PageRenderTime 83ms CodeModel.GetById 42ms RepoModel.GetById 0ms app.codeStats 1ms

/default/js/src/mura.js

http://github.com/blueriver/MuraCMS
JavaScript | 2468 lines | 1837 code | 443 blank | 188 comment | 608 complexity | 60676223c07b9ac4667579cf0777b51f MD5 | raw file
Possible License(s): GPL-3.0, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception, MIT, BSD-3-Clause, CPL-1.0, Apache-2.0, 0BSD, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. /* This file is part of Mura CMS.
  2. Mura CMS is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, Version 2 of the License.
  5. Mura CMS is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with Mura CMS. If not, see <http://www.gnu.org/licenses/>.
  11. Linking Mura CMS statically or dynamically with other modules constitutes the preparation of a derivative work based on
  12. Mura CMS. Thus, the terms and conditions of the GNU General Public License version 2 ("GPL") cover the entire combined work.
  13. However, as a special exception, the copyright holders of Mura CMS grant you permission to combine Mura CMS with programs
  14. or libraries that are released under the GNU Lesser General Public License version 2.1.
  15. In addition, as a special exception, the copyright holders of Mura CMS grant you permission to combine Mura CMS with
  16. independent software modules (plugins, themes and bundles), and to distribute these plugins, themes and bundles without
  17. Mura CMS under the license of your choice, provided that you follow these specific guidelines:
  18. Your custom code
  19. • Must not alter any default objects in the Mura CMS database and
  20. • May not alter the default display of the Mura CMS logo within Mura CMS and
  21. • Must not alter any files in the following directories.
  22. /admin/
  23. /tasks/
  24. /config/
  25. /requirements/mura/
  26. /Application.cfc
  27. /index.cfm
  28. /MuraProxy.cfc
  29. You may copy and distribute Mura CMS with a plug-in, theme or bundle that meets the above guidelines as a combined work
  30. under the terms of GPL for Mura CMS, provided that you include the source code of that other code when and as the GNU GPL
  31. requires distribution of source code.
  32. For clarity, if you create a modified version of Mura CMS, you are not obligated to grant this special exception for your
  33. modified version; it is your choice whether to do so, or to make such modified version available under the GNU General Public License
  34. version 2 without this exception. You may, if you choose, apply this exception to your own modified versions of Mura CMS. */
  35. ;(function (root, factory) {
  36. if (typeof define === 'function' && define.amd) {
  37. // AMD. Register as an anonymous module.
  38. define(['Mura'], factory);
  39. } else if (typeof module === 'object' && module.exports) {
  40. // Node. Does not work with strict CommonJS, but
  41. // only CommonJS-like environments that support module.exports,
  42. // like Node.
  43. root.Mura=factory(root);
  44. } else {
  45. // Browser globals (root is window)
  46. root.Mura=factory(root);
  47. }
  48. }(this, function (root) {
  49. function login(username,password,siteid){
  50. siteid=siteid || root.Mura.siteid;
  51. return new Promise(function(resolve,reject) {
  52. root.Mura.ajax({
  53. async:true,
  54. type:'post',
  55. url:root.Mura.apiEndpoint,
  56. data:{
  57. siteid:siteid,
  58. username:username,
  59. password:password,
  60. method:'login'
  61. },
  62. success:function(resp){
  63. resolve(resp.data);
  64. }
  65. });
  66. });
  67. }
  68. function logout(siteid){
  69. siteid=siteid || root.Mura.siteid;
  70. return new Promise(function(resolve,reject) {
  71. root.Mura.ajax({
  72. async:true,
  73. type:'post',
  74. url:root.Mura.apiEndpoint,
  75. data:{
  76. siteid:siteid,
  77. method:'logout'
  78. },
  79. success:function(resp){
  80. resolve(resp.data);
  81. }
  82. });
  83. });
  84. }
  85. function escapeHTML(str) {
  86. var div = document.createElement('div');
  87. div.appendChild(document.createTextNode(str));
  88. return div.innerHTML;
  89. };
  90. // UNSAFE with unsafe strings; only use on previously-escaped ones!
  91. function unescapeHTML(escapedStr) {
  92. var div = document.createElement('div');
  93. div.innerHTML = escapedStr;
  94. var child = div.childNodes[0];
  95. return child ? child.nodeValue : '';
  96. };
  97. function renderFilename(filename,params){
  98. var query = [];
  99. params = params || {};
  100. params.filename= params.filename || '';
  101. params.siteid= params.siteid || root.Mura.siteid;
  102. for (var key in params) {
  103. if(key != 'entityname' && key != 'filename' && key != 'siteid' && key != 'method'){
  104. query.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));
  105. }
  106. }
  107. return new Promise(function(resolve,reject) {
  108. root.Mura.ajax({
  109. async:true,
  110. type:'get',
  111. url:root.Mura.apiEndpoint + params.siteid + '/content/_path/' + filename + '?' + query.join('&'),
  112. success:function(resp){
  113. if(typeof resolve == 'function'){
  114. var item=new root.Mura.Entity();
  115. item.set(resp.data);
  116. resolve(item);
  117. }
  118. }
  119. });
  120. });
  121. }
  122. function getEntity(entityname,siteid){
  123. if(typeof entityname == 'string'){
  124. var properties={entityname:entityname};
  125. properties.siteid = siteid || root.Mura.siteid;
  126. } else {
  127. properties=entityname;
  128. properties.entityname=properties.entityname || 'content';
  129. properties.siteid=properties.siteid || root.Mura.siteid;
  130. }
  131. if(root.Mura.entities[properties.entityname]){
  132. return new root.Mura.entities[properties.entityname](properties);
  133. } else {
  134. return new root.Mura.Entity(properties);
  135. }
  136. }
  137. function getFeed(entityname){
  138. return new root.Mura.Feed(Mura.siteid,entityname);
  139. }
  140. function findQuery(params){
  141. params=params || {};
  142. params.entityname=params.entityname || 'content';
  143. params.siteid=params.siteid || Mura.siteid;
  144. params.method=params.method || 'findQuery';
  145. return new Promise(function(resolve,reject) {
  146. root.Mura.ajax({
  147. type:'get',
  148. url:root.Mura.apiEndpoint,
  149. data:params,
  150. success:function(resp){
  151. var collection=new root.Mura.EntityCollection(resp.data)
  152. if(typeof resolve == 'function'){
  153. resolve(collection);
  154. }
  155. }
  156. });
  157. });
  158. }
  159. function evalScripts(el) {
  160. if(typeof el=='string'){
  161. el=parseHTML(el);
  162. }
  163. var scripts = [];
  164. var ret = el.childNodes;
  165. for ( var i = 0; ret[i]; i++ ) {
  166. if ( scripts && nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
  167. scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
  168. } else if(ret[i].nodeType==1 || ret[i].nodeType==9 || ret[i].nodeType==11){
  169. evalScripts(ret[i]);
  170. }
  171. }
  172. for(script in scripts){
  173. evalScript(scripts[script]);
  174. }
  175. }
  176. function nodeName( el, name ) {
  177. return el.nodeName && el.nodeName.toUpperCase() === name.toUpperCase();
  178. }
  179. function evalScript(el) {
  180. var data = ( el.text || el.textContent || el.innerHTML || "" );
  181. var head = document.getElementsByTagName("head")[0] || document.documentElement,
  182. script = document.createElement("script");
  183. script.type = "text/javascript";
  184. //script.appendChild( document.createTextNode( data ) );
  185. script.text=data;
  186. head.insertBefore( script, head.firstChild );
  187. head.removeChild( script );
  188. if ( el.parentNode ) {
  189. el.parentNode.removeChild( el );
  190. }
  191. }
  192. function changeElementType(el, to) {
  193. var newEl = document.createElement(to);
  194. // Try to copy attributes across
  195. for (var i = 0, a = el.attributes, n = a.length; i < n; ++i)
  196. el.setAttribute(a[i].name, a[i].value);
  197. // Try to move children across
  198. while (el.hasChildNodes())
  199. newEl.appendChild(el.firstChild);
  200. // Replace the old element with the new one
  201. el.parentNode.replaceChild(newEl, el);
  202. // Return the new element, for good measure.
  203. return newEl;
  204. }
  205. function ready(fn) {
  206. if(document.readyState != 'loading'){
  207. //IE set the readyState to interative too early
  208. setTimeout(fn,1);
  209. } else {
  210. document.addEventListener('DOMContentLoaded',function(){
  211. fn();
  212. });
  213. }
  214. }
  215. function get(url,data){
  216. return new Promise(function(resolve, reject) {
  217. return ajax({
  218. type:'get',
  219. url:url,
  220. data:data,
  221. success:function(resp){
  222. resolve(resp);
  223. },
  224. error:function(resp){
  225. reject(resp);
  226. }
  227. }
  228. );
  229. });
  230. }
  231. function post(url,data){
  232. return new Promise(function(resolve, reject) {
  233. return ajax({
  234. type:'post',
  235. url:url,
  236. data:data,
  237. success:function(resp){
  238. resolve(resp);
  239. },
  240. error:function(resp){
  241. reject(resp);
  242. }
  243. }
  244. );
  245. });
  246. }
  247. function isXDomainRequest(url){
  248. function getHostName(url) {
  249. var match = url.match(/:\/\/([0-9]?\.)?(.[^/:]+)/i);
  250. if (match != null && match.length > 2 && typeof match[2] === 'string' && match[2].length > 0) {
  251. return match[2];
  252. } else {
  253. return null;
  254. }
  255. }
  256. function getDomain(url) {
  257. var hostName = getHostName(url);
  258. var domain = hostName;
  259. if (hostName != null) {
  260. var parts = hostName.split('.').reverse();
  261. if (parts != null && parts.length > 1) {
  262. domain = parts[1] + '.' + parts[0];
  263. if (hostName.toLowerCase().indexOf('.co.uk') != -1 && parts.length > 2) {
  264. domain = parts[2] + '.' + domain;
  265. }
  266. }
  267. }
  268. return domain;
  269. }
  270. var requestDomain=getDomain(url);
  271. return (requestDomain && requestDomain != location.host);
  272. }
  273. function ajax(params){
  274. //params=params || {};
  275. if(!('type' in params)){
  276. params.type='GET';
  277. }
  278. if(!('success' in params)){
  279. params.success=function(){};
  280. }
  281. if(!('error' in params)){
  282. params.error=function(){};
  283. }
  284. if(!('data' in params)){
  285. params.data={};
  286. }
  287. if(!(typeof FormData != 'undefined' && params.data instanceof FormData)){
  288. params.data=Mura.deepExtend({},params.data);
  289. for(var p in params.data){
  290. if(typeof params.data[p] == 'object'){
  291. params.data[p]=JSON.stringify(params.data[p]);
  292. }
  293. }
  294. }
  295. if(!('xhrFields' in params)){
  296. params.xhrFields={ withCredentials: true };
  297. }
  298. if(!('crossDomain' in params)){
  299. params.crossDomain=true;
  300. }
  301. if(!('async' in params)){
  302. params.async=true;
  303. }
  304. if(!('headers' in params)){
  305. params.headers={};
  306. }
  307. var request = new XMLHttpRequest();
  308. if(params.crossDomain){
  309. if (!("withCredentials" in request)
  310. && typeof XDomainRequest != "undefined" && isXDomainRequest(params.url)) {
  311. // Check if the XMLHttpRequest object has a "withCredentials" property.
  312. // "withCredentials" only exists on XMLHTTPRequest2 objects.
  313. // Otherwise, check if XDomainRequest.
  314. // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
  315. request =new XDomainRequest();
  316. }
  317. }
  318. request.onreadystatechange = function() {
  319. if(request.readyState == 4) {
  320. //IE9 doesn't appear to return the request status
  321. if(typeof request.status == 'undefined' || (request.status >= 200 && request.status < 400)) {
  322. try{
  323. var data = JSON.parse(request.responseText);
  324. } catch(e){
  325. var data = request.responseText;
  326. }
  327. params.success(data,request);
  328. } else {
  329. params.error(request);
  330. }
  331. }
  332. }
  333. if(params.type.toLowerCase()=='post'){
  334. request.open(params.type.toUpperCase(), params.url, params.async);
  335. for(var p in params.xhrFields){
  336. if(p in request){
  337. request[p]=params.xhrFields[p];
  338. }
  339. }
  340. for(var h in params.headers){
  341. request.setRequestHeader(p,params.headers[h]);
  342. }
  343. //if(params.data.constructor.name == 'FormData'){
  344. if(typeof FormData != 'undefined' && params.data instanceof FormData){
  345. request.send(params.data);
  346. } else {
  347. request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  348. var query = [];
  349. for (var key in params.data) {
  350. query.push($escape(key) + '=' + $escape(params.data[key]));
  351. }
  352. query=query.join('&');
  353. setTimeout(function () {
  354. request.send(query);
  355. }, 0);
  356. }
  357. } else {
  358. if(params.url.indexOf('?') == -1){
  359. params.url += '?';
  360. }
  361. var query = [];
  362. for (var key in params.data) {
  363. query.push($escape(key) + '=' + $escape(params.data[key]));
  364. }
  365. query=query.join('&');
  366. request.open(params.type.toUpperCase(), params.url + '&' + query, params.async);
  367. for(var p in params.xhrFields){
  368. if(p in request){
  369. request[p]=params.xhrFields[p];
  370. }
  371. }
  372. for(var h in params.headers){
  373. request.setRequestHeader(p,params.headers[h]);
  374. }
  375. setTimeout(function () {
  376. request.send();
  377. }, 0);
  378. }
  379. }
  380. function generateOauthToken(grant_type,client_id,client_secret){
  381. return new Promise(function(resolve,reject) {
  382. get(Mura.apiEndpoint.replace('/json/','/rest/') + 'oauth/token?grant_type=' + encodeURIComponent(grant_type) + '&client_id=' + encodeURIComponent(client_id) + '&client_secret=' + encodeURIComponent(client_secret)).then(function(resp){
  383. if(resp.data != 'undefined'){
  384. resolve(resp.data);
  385. } else {
  386. if(typeof reject=='function'){
  387. reject(resp);
  388. }
  389. }
  390. })
  391. });
  392. }
  393. function each(selector,fn){
  394. select(selector).each(fn);
  395. }
  396. function on(el,eventName,fn){
  397. if(eventName=='ready'){
  398. Mura.ready(fn);
  399. } else {
  400. if(typeof el.addEventListener == 'function'){
  401. el.addEventListener(
  402. eventName,
  403. function(event){
  404. fn.call(el,event);
  405. },
  406. true
  407. );
  408. }
  409. }
  410. }
  411. function trigger(el, eventName, eventDetail) {
  412. var eventClass = "";
  413. switch (eventName) {
  414. case "click":
  415. case "mousedown":
  416. case "mouseup":
  417. eventClass = "MouseEvents";
  418. break;
  419. case "focus":
  420. case "change":
  421. case "blur":
  422. case "select":
  423. eventClass = "HTMLEvents";
  424. break;
  425. default:
  426. eventClass = "Event";
  427. break;
  428. }
  429. var bubbles=eventName == "change" ? false : true;
  430. if(document.createEvent){
  431. var event = document.createEvent(eventClass);
  432. event.initEvent(eventName, bubbles, true);
  433. event.synthetic = true;
  434. el.dispatchEvent(event);
  435. } else {
  436. try{
  437. document.fireEvent("on" + eventName);
  438. } catch(e){
  439. console.warn("Event failed to fire due to legacy browser: on" + eventName);
  440. }
  441. }
  442. };
  443. function off(el,eventName,fn){
  444. el.removeEventListener(eventName,fn);
  445. }
  446. function parseSelection(selector){
  447. if(typeof selector == 'object' && Array.isArray(selector)){
  448. var selection=selector;
  449. } else if(typeof selector== 'string'){
  450. var selection=nodeListToArray(document.querySelectorAll(selector));
  451. } else {
  452. if((typeof StaticNodeList != 'undefined' && selector instanceof StaticNodeList) || selector instanceof NodeList || selector instanceof HTMLCollection){
  453. var selection=nodeListToArray(selector);
  454. } else {
  455. var selection=[selector];
  456. }
  457. }
  458. if(typeof selection.length == 'undefined'){
  459. selection=[];
  460. }
  461. return selection;
  462. }
  463. function isEmptyObject(obj){
  464. return (typeof obj != 'object' || Object.keys(obj).length == 0);
  465. }
  466. function filter(selector,fn){
  467. return select(parseSelection(selector)).filter(fn);
  468. }
  469. function nodeListToArray(nodeList){
  470. var arr = [];
  471. for(var i = nodeList.length; i--; arr.unshift(nodeList[i]));
  472. return arr;
  473. }
  474. function select(selector){
  475. return new root.Mura.DOMSelection(parseSelection(selector),selector);
  476. }
  477. function parseHTML(str) {
  478. var tmp = document.implementation.createHTMLDocument();
  479. tmp.body.innerHTML = str;
  480. return tmp.body.children;
  481. };
  482. function getData(el){
  483. var data = {};
  484. Array.prototype.forEach.call(el.attributes, function(attr) {
  485. if (/^data-/.test(attr.name)) {
  486. data[attr.name.substr(5)] = parseString(attr.value);
  487. }
  488. });
  489. return data;
  490. }
  491. function getProps(el){
  492. var data = {};
  493. Array.prototype.forEach.call(el.attributes, function(attr) {
  494. if (/^data-/.test(attr.name)) {
  495. data[attr.name.substr(5)] = parseString(attr.value);
  496. }
  497. });
  498. return data;
  499. }
  500. function isNumeric(val) {
  501. return Number(parseFloat(val)) == val;
  502. }
  503. function parseString(val){
  504. if(typeof val == 'string'){
  505. var lcaseVal=val.toLowerCase();
  506. if(lcaseVal=='false'){
  507. return false;
  508. } else if (lcaseVal=='true'){
  509. return true;
  510. } else {
  511. if(!(typeof val == 'string' && val.length==35) && isNumeric(val)){
  512. var numVal=parseFloat(val);
  513. if(numVal==0 || !isNaN(1/numVal)){
  514. return numVal;
  515. }
  516. }
  517. try {
  518. var jsonVal=JSON.parse(val);
  519. return jsonVal;
  520. } catch (e) {
  521. return val;
  522. }
  523. }
  524. } else {
  525. return val;
  526. }
  527. }
  528. function getAttributes(el){
  529. var data = {};
  530. Array.prototype.forEach.call(el.attributes, function(attr) {
  531. data[attr.name] = attr.value;
  532. });
  533. return data;
  534. }
  535. function formToObject(form) {
  536. var field, s = {};
  537. if (typeof form == 'object' && form.nodeName == "FORM") {
  538. var len = form.elements.length;
  539. for (i=0; i<len; i++) {
  540. field = form.elements[i];
  541. if (field.name && !field.disabled && field.type != 'file' && field.type != 'reset' && field.type != 'submit' && field.type != 'button') {
  542. if (field.type == 'select-multiple') {
  543. for (j=form.elements[i].options.length-1; j>=0; j--) {
  544. if(field.options[j].selected)
  545. s[s.name] = field.options[j].value;
  546. }
  547. } else if ((field.type != 'checkbox' && field.type != 'radio') || field.checked) {
  548. if(typeof s[field.name ] == 'undefined'){
  549. s[field.name ] =field.value;
  550. } else {
  551. s[field.name ] = s[field.name ] + ',' + field.value;
  552. }
  553. }
  554. }
  555. }
  556. }
  557. return s;
  558. }
  559. //http://youmightnotneedjquery.com/
  560. function extend(out) {
  561. out = out || {};
  562. for (var i = 1; i < arguments.length; i++) {
  563. if (!arguments[i])
  564. continue;
  565. for (var key in arguments[i]) {
  566. if (typeof arguments[i].hasOwnProperty != 'undefined' && arguments[i].hasOwnProperty(key))
  567. out[key] = arguments[i][key];
  568. }
  569. }
  570. return out;
  571. };
  572. function deepExtend(out) {
  573. out = out || {};
  574. for (var i = 1; i < arguments.length; i++) {
  575. var obj = arguments[i];
  576. if (!obj)
  577. continue;
  578. for (var key in obj) {
  579. if (typeof arguments[i].hasOwnProperty != 'undefined' && arguments[i].hasOwnProperty(key)) {
  580. if(Array.isArray(obj[key])){
  581. out[key]=obj[key].slice(0);
  582. } else if (typeof obj[key] === 'object') {
  583. out[key]=deepExtend({}, obj[key]);
  584. } else {
  585. out[key] = obj[key];
  586. }
  587. }
  588. }
  589. }
  590. return out;
  591. }
  592. function createCookie(name,value,days) {
  593. if (days) {
  594. var date = new Date();
  595. date.setTime(date.getTime()+(days*24*60*60*1000));
  596. var expires = "; expires="+date.toGMTString();
  597. }
  598. else var expires = "";
  599. document.cookie = name+"="+value+expires+"; path=/";
  600. }
  601. function readCookie(name) {
  602. var nameEQ = name + "=";
  603. var ca = document.cookie.split(';');
  604. for(var i=0;i < ca.length;i++) {
  605. var c = ca[i];
  606. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  607. if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
  608. }
  609. return "";
  610. }
  611. function eraseCookie(name) {
  612. createCookie(name,"",-1);
  613. }
  614. function $escape(value){
  615. if(typeof encodeURIComponent != 'undefined'){
  616. return encodeURIComponent(value)
  617. } else {
  618. return escape(value).replace(
  619. new RegExp( "\\+", "g" ),
  620. "%2B"
  621. ).replace(/[\x00-\x1F\x7F-\x9F]/g, "");
  622. }
  623. }
  624. function $unescape(value){
  625. return unescape(value);
  626. }
  627. //deprecated
  628. function addLoadEvent(func) {
  629. var oldonload = root.onload;
  630. if (typeof root.onload != 'function') {
  631. root.onload = func;
  632. } else {
  633. root.onload = function() {
  634. oldonload();
  635. func();
  636. }
  637. }
  638. }
  639. function noSpam(user,domain) {
  640. locationstring = "mailto:" + user + "@" + domain;
  641. root.location = locationstring;
  642. }
  643. function createUUID() {
  644. var s = [], itoh = '0123456789ABCDEF';
  645. // Make array of random hex digits. The UUID only has 32 digits in it, but we
  646. // allocate an extra items to make room for the '-'s we'll be inserting.
  647. for (var i = 0; i < 35; i++) s[i] = Math.floor(Math.random()*0x10);
  648. // Conform to RFC-4122, section 4.4
  649. s[14] = 4; // Set 4 high bits of time_high field to version
  650. s[19] = (s[19] & 0x3) | 0x8; // Specify 2 high bits of clock sequence
  651. // Convert to hex chars
  652. for (var i = 0; i < 36; i++) s[i] = itoh[s[i]];
  653. // Insert '-'s
  654. s[8] = s[13] = s[18] = '-';
  655. return s.join('');
  656. }
  657. function setHTMLEditor(el) {
  658. function initEditor(){
  659. var instance=root.CKEDITOR.instances[el.getAttribute('id')];
  660. var conf={height:200,width:'70%'};
  661. if(el.getAttribute('data-editorconfig')){
  662. extend(conf,el.getAttribute('data-editorconfig'));
  663. }
  664. if (instance) {
  665. instance.destroy();
  666. CKEDITOR.remove(instance);
  667. }
  668. root.CKEDITOR.replace( el.getAttribute('id'),getHTMLEditorConfig(conf),htmlEditorOnComplete);
  669. }
  670. function htmlEditorOnComplete( editorInstance ) {
  671. //var instance=jQuery(editorInstance).ckeditorGet();
  672. //instance.resetDirty();
  673. editorInstance.resetDirty();
  674. var totalIntances=root.CKEDITOR.instances;
  675. //CKFinder.setupCKEditor( instance, { basePath : context + '/requirements/ckfinder/', rememberLastFolder : false } ) ;
  676. }
  677. function getHTMLEditorConfig(customConfig) {
  678. var attrname='';
  679. var htmlEditorConfig={
  680. toolbar:'htmlEditor',
  681. customConfig : 'config.js.cfm'
  682. }
  683. if(typeof(customConfig)== 'object'){
  684. extend(htmlEditorConfig,customConfig);
  685. }
  686. return htmlEditorConfig;
  687. }
  688. loader().loadjs(
  689. root.Mura.requirementspath + '/ckeditor/ckeditor.js'
  690. ,
  691. function(){
  692. initEditor();
  693. }
  694. );
  695. }
  696. var pressed_keys='';
  697. var loginCheck=function(key){
  698. if(key==27){
  699. pressed_keys = key.toString();
  700. } else if(key == 76){
  701. pressed_keys = pressed_keys + "" + key.toString();
  702. }
  703. if (key !=27 && key !=76) {
  704. pressed_keys = "";
  705. }
  706. if (pressed_keys != "") {
  707. var aux = pressed_keys;
  708. var lu='';
  709. var ru='';
  710. if (aux.indexOf('2776') != -1 && location.search.indexOf("display=login") == -1) {
  711. if(typeof(root.Mura.loginURL) != "undefined"){
  712. lu=root.Mura.loginURL;
  713. } else if(typeof(root.Mura.loginurl) != "undefined"){
  714. lu=root.Mura.loginurl;
  715. } else{
  716. lu="?display=login";
  717. }
  718. if(typeof(root.Mura.returnURL) != "undefined"){
  719. ru=root.Mura.returnURL;
  720. } else if(typeof(root.Mura.returnurl) != "undefined"){
  721. ru=root.Mura.returnURL;
  722. } else{
  723. ru=location.href;
  724. }
  725. pressed_keys = "";
  726. lu = new String(lu);
  727. if(lu.indexOf('?') != -1){
  728. location.href=lu + "&returnUrl=" + encodeURIComponent(ru);
  729. } else {
  730. location.href=lu + "?returnUrl=" + encodeURIComponent(ru);
  731. }
  732. }
  733. }
  734. }
  735. function isInteger(s){
  736. var i;
  737. for (i = 0; i < s.length; i++){
  738. // Check that current character is number.
  739. var c = s.charAt(i);
  740. if (((c < "0") || (c > "9"))) return false;
  741. }
  742. // All characters are numbers.
  743. return true;
  744. }
  745. function createDate(str){
  746. var valueArray = str.split("/");
  747. var mon = valueArray[0];
  748. var dt = valueArray[1];
  749. var yr = valueArray[2];
  750. var date = new Date(yr, mon-1, dt);
  751. if(!isNaN(date.getMonth())){
  752. return date;
  753. } else {
  754. return new Date();
  755. }
  756. }
  757. function dateToString(date){
  758. var mon = date.getMonth()+1;
  759. var dt = date.getDate();
  760. var yr = date.getFullYear();
  761. if(mon < 10){ mon="0" + mon;}
  762. if(dt < 10){ dt="0" + dt;}
  763. return mon + "/" + dt + "/20" + new String(yr).substring(2,4);
  764. }
  765. function stripCharsInBag(s, bag){
  766. var i;
  767. var returnString = "";
  768. // Search through string's characters one by one.
  769. // If character is not in bag, append to returnString.
  770. for (i = 0; i < s.length; i++){
  771. var c = s.charAt(i);
  772. if (bag.indexOf(c) == -1) returnString += c;
  773. }
  774. return returnString;
  775. }
  776. function daysInFebruary(year){
  777. // February has 29 days in any year evenly divisible by four,
  778. // EXCEPT for centurial years which are not also divisible by 400.
  779. return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
  780. }
  781. function DaysArray(n) {
  782. for (var i = 1; i <= n; i++) {
  783. this[i] = 31
  784. if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
  785. if (i==2) {this[i] = 29}
  786. }
  787. return this
  788. }
  789. function isDate(dtStr,fldName){
  790. var daysInMonth = DaysArray(12);
  791. var dtArray= dtStr.split(root.Mura.dtCh);
  792. if (dtArray.length != 3){
  793. //alert("The date format for the "+fldName+" field should be : short")
  794. return false
  795. }
  796. var strMonth=dtArray[root.Mura.dtFormat[0]];
  797. var strDay=dtArray[root.Mura.dtFormat[1]];
  798. var strYear=dtArray[root.Mura.dtFormat[2]];
  799. /*
  800. if(strYear.length == 2){
  801. strYear="20" + strYear;
  802. }
  803. */
  804. strYr=strYear;
  805. if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
  806. if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
  807. for (var i = 1; i <= 3; i++) {
  808. if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
  809. }
  810. month=parseInt(strMonth)
  811. day=parseInt(strDay)
  812. year=parseInt(strYr)
  813. if (month<1 || month>12){
  814. //alert("Please enter a valid month in the "+fldName+" field")
  815. return false
  816. }
  817. if (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
  818. //alert("Please enter a valid day in the "+fldName+" field")
  819. return false
  820. }
  821. if (strYear.length != 4 || year==0 || year<root.Mura.minYear || year>root.Mura.maxYear){
  822. //alert("Please enter a valid 4 digit year between "+root.Mura.minYear+" and "+root.Mura.maxYear +" in the "+fldName+" field")
  823. return false
  824. }
  825. if (isInteger(stripCharsInBag(dtStr, root.Mura.dtCh))==false){
  826. //alert("Please enter a valid date in the "+fldName+" field")
  827. return false
  828. }
  829. return true;
  830. }
  831. function isEmail(cur){
  832. var string1=cur
  833. if (string1.indexOf("@") == -1 || string1.indexOf(".") == -1){
  834. return false;
  835. }else{
  836. return true;
  837. }
  838. }
  839. function initShadowBox(el){
  840. if(Mura(el).find('[data-rel^="shadowbox"],[rel^="shadowbox"]').length){
  841. loader().load(
  842. [
  843. Mura.assetpath +'/css/shadowbox.min.css',
  844. Mura.assetpath +'/js/external/shadowbox/shadowbox.js'
  845. ],
  846. function(){
  847. Mura('#shadowbox_overlay,#shadowbox_container').remove();
  848. if(root.Shadowbox){
  849. root.Shadowbox.init();
  850. }
  851. }
  852. );
  853. }
  854. }
  855. function validateForm(frm,customaction) {
  856. function getValidationFieldName(theField){
  857. if(theField.getAttribute('data-label')!=undefined){
  858. return theField.getAttribute('data-label');
  859. }else if(theField.getAttribute('label')!=undefined){
  860. return theField.getAttribute('label');
  861. }else{
  862. return theField.getAttribute('name');
  863. }
  864. }
  865. function getValidationIsRequired(theField){
  866. if(theField.getAttribute('data-required')!=undefined){
  867. return (theField.getAttribute('data-required').toLowerCase() =='true');
  868. }else if(theField.getAttribute('required')!=undefined){
  869. return (theField.getAttribute('required').toLowerCase() =='true');
  870. }else{
  871. return false;
  872. }
  873. }
  874. function getValidationMessage(theField, defaultMessage){
  875. if(theField.getAttribute('data-message') != undefined){
  876. return theField.getAttribute('data-message');
  877. } else if(theField.getAttribute('message') != undefined){
  878. return theField.getAttribute('message') ;
  879. } else {
  880. return getValidationFieldName(theField).toUpperCase() + defaultMessage;
  881. }
  882. }
  883. function getValidationType(theField){
  884. if(theField.getAttribute('data-validate')!=undefined){
  885. return theField.getAttribute('data-validate').toUpperCase();
  886. }else if(theField.getAttribute('validate')!=undefined){
  887. return theField.getAttribute('validate').toUpperCase();
  888. }else{
  889. return '';
  890. }
  891. }
  892. function hasValidationMatchField(theField){
  893. if(theField.getAttribute('data-matchfield')!=undefined && theField.getAttribute('data-matchfield') != ''){
  894. return true;
  895. }else if(theField.getAttribute('matchfield')!=undefined && theField.getAttribute('matchfield') != ''){
  896. return true;
  897. }else{
  898. return false;
  899. }
  900. }
  901. function getValidationMatchField(theField){
  902. if(theField.getAttribute('data-matchfield')!=undefined){
  903. return theField.getAttribute('data-matchfield');
  904. }else if(theField.getAttribute('matchfield')!=undefined){
  905. return theField.getAttribute('matchfield');
  906. }else{
  907. return '';
  908. }
  909. }
  910. function hasValidationRegex(theField){
  911. if(theField.value != undefined){
  912. if(theField.getAttribute('data-regex')!=undefined && theField.getAttribute('data-regex') != ''){
  913. return true;
  914. }else if(theField.getAttribute('regex')!=undefined && theField.getAttribute('regex') != ''){
  915. return true;
  916. }
  917. }else{
  918. return false;
  919. }
  920. }
  921. function getValidationRegex(theField){
  922. if(theField.getAttribute('data-regex')!=undefined){
  923. return theField.getAttribute('data-regex');
  924. }else if(theField.getAttribute('regex')!=undefined){
  925. return theField.getAttribute('regex');
  926. }else{
  927. return '';
  928. }
  929. }
  930. var theForm=frm;
  931. var errors="";
  932. var setFocus=0;
  933. var started=false;
  934. var startAt;
  935. var firstErrorNode;
  936. var validationType='';
  937. var validations={properties:{}};
  938. var frmInputs = theForm.getElementsByTagName("input");
  939. var rules=new Array();
  940. var data={};
  941. var $customaction=customaction;
  942. for (var f=0; f < frmInputs.length; f++) {
  943. var theField=frmInputs[f];
  944. validationType=getValidationType(theField).toUpperCase();
  945. rules=new Array();
  946. if(theField.style.display==""){
  947. if(getValidationIsRequired(theField))
  948. {
  949. rules.push({
  950. required: true,
  951. message: getValidationMessage(theField,' is required.')
  952. });
  953. }
  954. if(validationType != ''){
  955. if(validationType=='EMAIL' && theField.value != '')
  956. {
  957. rules.push({
  958. dataType: 'EMAIL',
  959. message: getValidationMessage(theField,' must be a valid email address.')
  960. });
  961. }
  962. else if(validationType=='NUMERIC' && theField.value != '')
  963. {
  964. rules.push({
  965. dataType: 'NUMERIC',
  966. message: getValidationMessage(theField,' must be numeric.')
  967. });
  968. }
  969. else if(validationType=='REGEX' && theField.value !='' && hasValidationRegex(theField))
  970. {
  971. rules.push({
  972. regex: getValidationRegex(theField),
  973. message: getValidationMessage(theField,' is not valid.')
  974. });
  975. }
  976. else if(validationType=='MATCH'
  977. && hasValidationMatchField(theField) && theField.value != theForm[getValidationMatchField(theField)].value)
  978. {
  979. rules.push({
  980. eq: theForm[getValidationMatchField(theField)].value,
  981. message: getValidationMessage(theField, ' must match' + getValidationMatchField(theField) + '.' )
  982. });
  983. }
  984. else if(validationType=='DATE' && theField.value != '')
  985. {
  986. rules.push({
  987. dataType: 'DATE',
  988. message: getValidationMessage(theField, ' must be a valid date [MM/DD/YYYY].' )
  989. });
  990. }
  991. }
  992. if(rules.length){
  993. validations.properties[theField.getAttribute('name')]=rules;
  994. data[theField.getAttribute('name')]=theField.value;
  995. }
  996. }
  997. }
  998. var frmTextareas = theForm.getElementsByTagName("textarea");
  999. for (f=0; f < frmTextareas.length; f++) {
  1000. theField=frmTextareas[f];
  1001. validationType=getValidationType(theField);
  1002. rules=new Array();
  1003. if(theField.style.display=="" && getValidationIsRequired(theField))
  1004. {
  1005. rules.push({
  1006. required: true,
  1007. message: getValidationMessage(theField, ' is required.' )
  1008. });
  1009. }
  1010. else if(validationType != ''){
  1011. if(validationType=='REGEX' && theField.value !='' && hasValidationRegex(theField))
  1012. {
  1013. rules.push({
  1014. regex: getValidationRegex(theField),
  1015. message: getValidationMessage(theField, ' is not valid.' )
  1016. });
  1017. }
  1018. }
  1019. if(rules.length){
  1020. validations.properties[theField.getAttribute('name')]=rules;
  1021. data[theField.getAttribute('name')]=theField.value;
  1022. }
  1023. }
  1024. var frmSelects = theForm.getElementsByTagName("select");
  1025. for (f=0; f < frmSelects.length; f++) {
  1026. theField=frmSelects[f];
  1027. validationType=getValidationType(theField);
  1028. rules=new Array();
  1029. if(theField.style.display=="" && getValidationIsRequired(theField))
  1030. {
  1031. rules.push({
  1032. required: true,
  1033. message: getValidationMessage(theField, ' is required.' )
  1034. });
  1035. }
  1036. if(rules.length){
  1037. validations.properties[theField.getAttribute('name')]=rules;
  1038. data[theField.getAttribute('name')]=theField.value;
  1039. }
  1040. }
  1041. try{
  1042. //alert(JSON.stringify(validations));
  1043. //console.log(data);
  1044. //console.log(validations);
  1045. ajax(
  1046. {
  1047. type: 'post',
  1048. url: root.Mura.apiEndpoint + '?method=validate',
  1049. data: {
  1050. data: encodeURIComponent(JSON.stringify(data)),
  1051. validations: encodeURIComponent(JSON.stringify(validations)),
  1052. version: 4
  1053. },
  1054. success: function(resp) {
  1055. data=resp.data;
  1056. if(Object.keys(data).length === 0){
  1057. if(typeof $customaction == 'function'){
  1058. $customaction(theForm);
  1059. return false;
  1060. } else {
  1061. document.createElement('form').submit.call(theForm);
  1062. }
  1063. } else {
  1064. var msg='';
  1065. for(var e in data){
  1066. msg=msg + data[e] + '\n';
  1067. }
  1068. alert(msg);
  1069. }
  1070. },
  1071. error: function(resp) {
  1072. alert(JSON.stringify(resp));
  1073. }
  1074. }
  1075. );
  1076. }
  1077. catch(err){
  1078. console.log(err);
  1079. }
  1080. return false;
  1081. }
  1082. function setLowerCaseKeys(obj) {
  1083. for(var key in obj){
  1084. if (key !== key.toLowerCase()) { // might already be in its lower case version
  1085. obj[key.toLowerCase()] = obj[key] // swap the value to a new lower case key
  1086. delete obj[key] // delete the old key
  1087. }
  1088. if(typeof obj[key.toLowerCase()] == 'object'){
  1089. setLowerCaseKeys(obj[key.toLowerCase()]);
  1090. }
  1091. }
  1092. return (obj);
  1093. }
  1094. function isScrolledIntoView(el) {
  1095. if(!root || root.innerHeight){
  1096. true;
  1097. }
  1098. try{
  1099. var elemTop = el.getBoundingClientRect().top;
  1100. var elemBottom = el.getBoundingClientRect().bottom;
  1101. } catch(e){
  1102. return true;
  1103. }
  1104. var isVisible = elemTop < root.innerHeight && elemBottom >= 0;
  1105. return isVisible;
  1106. }
  1107. function loader(){return root.Mura.ljs;}
  1108. var layoutmanagertoolbar='<div class="frontEndToolsModal mura"><span class="mura-edit-icon"></span></div>';
  1109. function processMarkup(scope){
  1110. if(!(scope instanceof root.Mura.DOMSelection)){
  1111. scope=select(scope);
  1112. }
  1113. var self=scope;
  1114. function find(selector){
  1115. return scope.find(selector);
  1116. }
  1117. var processors=[
  1118. function(){
  1119. find('.mura-object, .mura-async-object').each(function(){
  1120. processDisplayObject(this,true);
  1121. });
  1122. },
  1123. function(){
  1124. find(".htmlEditor").each(function(el){
  1125. setHTMLEditor(this);
  1126. });
  1127. },
  1128. function(){
  1129. if(find(".cffp_applied .cffp_mm .cffp_kp").length){
  1130. var fileref=document.createElement('script')
  1131. fileref.setAttribute("type","text/javascript")
  1132. fileref.setAttribute("src", root.Mura.requirementspath + '/cfformprotect/js/cffp.js')
  1133. document.getElementsByTagName("head")[0].appendChild(fileref)
  1134. }
  1135. },
  1136. function(){
  1137. if(find(".g-recaptcha" ).length){
  1138. var fileref=document.createElement('script')
  1139. fileref.setAttribute("type","text/javascript")
  1140. fileref.setAttribute("src", "https://www.google.com/recaptcha/api.js?onload=checkForReCaptcha&render=explicit")
  1141. document.getElementsByTagName("head")[0].appendChild(fileref)
  1142. }
  1143. if(find(".g-recaptcha-container" ).length){
  1144. loader().loadjs(
  1145. "https://www.google.com/recaptcha/api.js?onload=checkForReCaptcha&render=explicit",
  1146. function(){
  1147. find(".g-recaptcha-container" ).each(function(el){
  1148. var self=el;
  1149. var checkForReCaptcha=function()
  1150. {
  1151. if (typeof grecaptcha == 'object' && !self.innerHTML)
  1152. {
  1153. self.setAttribute(
  1154. 'data-widgetid',
  1155. grecaptcha.render(self.getAttribute('id'), {
  1156. 'sitekey' : self.getAttribute('data-sitekey'),
  1157. 'theme' : self.getAttribute('data-theme'),
  1158. 'type' : self.getAttribute('data-type')
  1159. })
  1160. );
  1161. }
  1162. else
  1163. {
  1164. root.setTimeout(function(){checkForReCaptcha();},10);
  1165. }
  1166. }
  1167. checkForReCaptcha();
  1168. });
  1169. }
  1170. );
  1171. }
  1172. },
  1173. function(){
  1174. if(typeof resizeEditableObject == 'function' ){
  1175. scope.closest('.editableObject').each(function(){
  1176. resizeEditableObject(this);
  1177. });
  1178. find(".editableObject").each(function(){
  1179. resizeEditableObject(this);
  1180. });
  1181. }
  1182. },
  1183. function(){
  1184. if(typeof openFrontEndToolsModal == 'function' ){
  1185. find(".frontEndToolsModal").on(
  1186. 'click',
  1187. function(event){
  1188. event.preventDefault();
  1189. openFrontEndToolsModal(this);
  1190. }
  1191. );
  1192. }
  1193. if(root.MuraInlineEditor && root.MuraInlineEditor.checkforImageCroppers){
  1194. find("img").each(function(){
  1195. root.MuraInlineEditor.checkforImageCroppers(this);
  1196. });
  1197. }
  1198. },
  1199. function(){
  1200. initShadowBox(scope.node);
  1201. },
  1202. function(){
  1203. if(typeof urlparams.Muraadminpreview != 'undefined'){
  1204. find("a").each(function() {
  1205. var h=this.getAttribute('href');
  1206. if(typeof h =='string' && h.indexOf('muraadminpreview')==-1){
  1207. h=h + (h.indexOf('?') != -1 ? "&muraadminpreview&mobileformat=" + root.Mura.mobileformat : "?muraadminpreview&muraadminpreview&mobileformat=" + root.Mura.mobileformat);
  1208. this.setAttribute('href',h);
  1209. }
  1210. });
  1211. }
  1212. }
  1213. ];
  1214. for(var h=0;h<processors.length;h++){
  1215. processors[h]();
  1216. }
  1217. }
  1218. function addEventHandler(eventName,fn){
  1219. if(typeof eventName == 'object'){
  1220. for(var h in eventName){
  1221. on(document,h,eventName[h]);
  1222. }
  1223. } else {
  1224. on(document,eventName,fn);
  1225. }
  1226. }
  1227. function submitForm(frm,obj){
  1228. frm=(frm.node) ? frm.node : frm;
  1229. if(obj){
  1230. obj=(obj.node) ? obj : Mura(obj);
  1231. } else {
  1232. obj=Mura(frm).closest('.mura-async-object');
  1233. }
  1234. if(!obj.length){
  1235. Mura(frm).trigger('formSubmit',formToObject(frm));
  1236. frm.submit();
  1237. }
  1238. if(typeof FormData != 'undefined' && frm.getAttribute('enctype')=='multipart/form-data'){
  1239. var data=new FormData(frm);
  1240. var checkdata=setLowerCaseKeys(formToObject(frm));
  1241. var keys=deepExtend(setLowerCaseKeys(obj.data()),urlparams,{siteid:root.Mura.siteid,contentid:root.Mura.contentid,contenthistid:root.Mura.contenthistid,nocache:1});
  1242. for(var k in keys){
  1243. if(!(k in checkdata)){
  1244. data.append(k,keys[k]);
  1245. }
  1246. }
  1247. if('objectparams' in checkdata){
  1248. data.append('objectparams2', encodeURIComponent(JSON.stringify(obj.data('objectparams'))));
  1249. }
  1250. if('nocache' in checkdata){
  1251. data.append('nocache',1);
  1252. }
  1253. /*
  1254. if(data.object=='container' && data.content){
  1255. delete data.content;
  1256. }
  1257. */
  1258. var postconfig={
  1259. url: root.Mura.apiEndpoint + '?method=processAsyncObject',
  1260. type: 'POST',
  1261. data: data,
  1262. success:function(resp){handleResponse(obj,resp);}
  1263. }
  1264. } else {
  1265. var data=deepExtend(setLowerCaseKeys(obj.data()),urlparams,setLowerCaseKeys(formToObject(frm)),{siteid:root.Mura.siteid,contentid:root.Mura.contentid,contenthistid:root.Mura.contenthistid,nocache:1});
  1266. if(data.object=='container' && data.content){
  1267. delete data.content;
  1268. }
  1269. if(!('g-recaptcha-response' in data)) {
  1270. var reCaptchaCheck=Mura(frm).find("#g-recaptcha-response");
  1271. if(reCaptchaCheck.length && typeof reCaptchaCheck.val() != 'undefined'){
  1272. data['g-recaptcha-response']=eCaptchaCheck.val();
  1273. }
  1274. }
  1275. if('objectparams' in data){
  1276. data['objectparams']= encodeURIComponent(JSON.stringify(data['objectparams']));
  1277. }
  1278. var postconfig={
  1279. url: root.Mura.apiEndpoint + '?method=processAsyncObject',
  1280. type: 'POST',
  1281. data: data,
  1282. success:function(resp){handleResponse(obj,resp);}
  1283. }
  1284. }
  1285. var self=obj.node;
  1286. self.prevInnerHTML=self.innerHTML;
  1287. self.prevData=obj.data();
  1288. self.innerHTML=root.Mura.preloaderMarkup;
  1289. Mura(frm).trigger('formSubmit',data);
  1290. ajax(postconfig);
  1291. }
  1292. function firstToUpperCase( str ) {
  1293. return str.substr(0, 1).toUpperCase() + str.substr(1);
  1294. }
  1295. function resetAsyncObject(el){
  1296. var self=Mura(el);
  1297. self.removeClass('mura-active');
  1298. self.removeAttr('data-perm');
  1299. self.removeAttr('draggable');
  1300. if(self.data('object')=='container'){
  1301. self.find('.mura-object:not([data-object="container"])').html('');
  1302. self.find('.frontEndToolsModal').remove();
  1303. self.find('.mura-object').each(function(){
  1304. var self=Mura(this);
  1305. self.removeClass('mura-active');
  1306. self.removeAttr('data-perm');
  1307. self.removeAttr('data-inited');
  1308. self.removeAttr('draggable');
  1309. });
  1310. self.find('.mura-object[data-object="container"]').each(function(){
  1311. var self=Mura(this);
  1312. var content=self.children('div.mura-object-content');
  1313. if(content.length){
  1314. self.data('content',content.html());
  1315. }
  1316. content.html('');
  1317. });
  1318. self.find('.mura-object-meta').html('');
  1319. var content=self.children('div.mura-object-content');
  1320. if(content.length){
  1321. self.data('content',content.html());
  1322. }
  1323. }
  1324. self.html('');
  1325. }
  1326. function processAsyncObject(el){
  1327. obj=Mura(el);
  1328. if(obj.data('async')===null){
  1329. obj.data('async',true);
  1330. }
  1331. return processDisplayObject(obj,false,true);
  1332. }
  1333. function wireUpObject(obj,response){
  1334. function validateFormAjax(frm) {
  1335. validateForm(frm,
  1336. function(frm){
  1337. submitForm(frm,obj);
  1338. }
  1339. );
  1340. return false;
  1341. }
  1342. obj=(obj.node) ? obj : Mura(obj);
  1343. var self=obj.node;
  1344. if(obj.data('class')){
  1345. var classes=obj.data('class');
  1346. if(typeof classes != 'array'){
  1347. var classes=classes.split(' ');
  1348. }
  1349. for(var c=0;c<classes.length;c++){
  1350. if(!obj.hasClass(classes[c])){
  1351. obj.addClass(classes[c]);
  1352. }
  1353. }
  1354. }
  1355. obj.data('inited',true);
  1356. if(obj.data('cssclass')){
  1357. var classes=obj.data('cssclass');
  1358. if(typeof classes != 'array'){
  1359. var classes=classes.split(' ');
  1360. }
  1361. for(var c in classes){
  1362. if(!obj.hasClass(classes[c])){
  1363. obj.addClass(classes[c]);
  1364. }
  1365. }
  1366. }
  1367. if(response){
  1368. if(typeof response == 'string'){
  1369. obj.html(trim(response));
  1370. } else if (typeof response.html =='string' && response.render!='client'){
  1371. obj.html(trim(response.html));
  1372. } else {
  1373. if(obj.data('object')=='container'){
  1374. var context=deepExtend(obj.data(),response);
  1375. context.targetEl=obj.node;
  1376. obj.prepend(Mura.templates.meta(context));
  1377. } else {
  1378. var context=deepExtend(obj.data(),response);
  1379. var template=obj.data('clienttemplate') || obj.data('object');
  1380. var properNameCheck=firstToUpperCase(template);
  1381. if(typeof Mura.DisplayObject[properNameCheck] != 'undefined'){
  1382. template=properNameCheck;
  1383. }
  1384. if(typeof context.async != 'undefined'){
  1385. obj.data('async',context.async);
  1386. }
  1387. if(typeof context.render != 'undefined'){
  1388. obj.data('render',context.render);
  1389. }
  1390. if(typeof context.rendertemplate != 'undefined'){
  1391. obj.data('rendertemplate',context.rendertemplate);
  1392. }
  1393. if(typeof Mura.DisplayObject[template] != 'undefined'){
  1394. context.html='';
  1395. obj.html(Mura.templates.content(context));
  1396. obj.prepend(Mura.templates.meta(context));
  1397. context.targetEl=obj.children('.mura-object-content').node;
  1398. Mura.displayObjectInstances[obj.data('instanceid')]=new Mura.DisplayObject[template]( context );
  1399. } else if(typeof Mura.templates[template] != 'undefined'){
  1400. context.html='';
  1401. obj.html(Mura.templates.content(context));
  1402. obj.prepend(Mura.templates.meta(context));
  1403. context.targetEl=obj.children('.mura-object-content').node;
  1404. Mura.templates[template](context);
  1405. } else {
  1406. console.log('Missing Client Template for:');
  1407. console.log(obj.data());
  1408. }
  1409. }
  1410. }
  1411. } else {
  1412. var context=obj.data();
  1413. if(obj.data('object')=='container'){
  1414. obj.prepend(Mura.templates.meta(context));
  1415. } else {
  1416. var template=obj.data('clienttemplate') || obj.data('object');
  1417. var properNameCheck=firstToUpperCase(template);
  1418. if(typeof Mura.DisplayObject[properNameCheck] != 'undefined'){
  1419. template=properNameCheck;
  1420. }
  1421. if(typeof Mura.DisplayObject[template] == 'function'){
  1422. context.html='';
  1423. obj.html(Mura.templates.content(context));
  1424. obj.prepend(Mura.templates.meta(context));
  1425. context.targetEl=obj.children('.mura-object-content').node;
  1426. Mura.displayObjectInstances[obj.data('instanceid')]=new Mura.DisplayObject[template]( context );
  1427. } else if(typeof Mura.templates[template] != 'undefined'){
  1428. context.html='';
  1429. obj.html(Mura.templates.content(context));
  1430. obj.prepend(Mura.templates.meta(context));
  1431. context.targetEl=obj.children('.mura-object-content').node;
  1432. Mura.templates[template](context);
  1433. } else {
  1434. console.log('Missing Client Template for:');
  1435. console.log(obj.data());
  1436. }
  1437. }
  1438. }
  1439. //obj.hide().show();
  1440. if(Mura.layoutmanager && Mura.editing){
  1441. if(obj.hasClass('mura-body-object')){
  1442. obj.children('.frontEndToolsModal').remove();
  1443. obj.prepend(layoutmanagertoolbar);
  1444. MuraInlineEditor.setAnchorSaveChecks(obj.node);
  1445. obj
  1446. .addClass('mura-active')
  1447. .hover(
  1448. function(e){
  1449. //e.stopPropagation();
  1450. Mura('.mura-active-target').removeClass('mura-active-target');
  1451. Mura(this).addClass('mura-active-target');
  1452. },
  1453. function(e){
  1454. //e.stopPropagation();
  1455. Mura(this).removeClass('mura-active-target');
  1456. }
  1457. );
  1458. } else {
  1459. if(Mura.type == 'Variation'){
  1460. var objectData=obj.data();
  1461. if(root.MuraInlineEditor && (root.MuraInlineEditor.objectHasConfigurator(obj) || (!root.Mura.layoutmanager && root.MuraInlineEditor.objectHasEditor(objectParams)) ) ){
  1462. obj.children('.frontEndToolsModal').remove();
  1463. obj.prepend(layoutmanagertoolbar);
  1464. MuraInlineEditor.setAnchorSaveChecks(obj.node);
  1465. obj
  1466. .addClass('mura-active')
  1467. .hover(
  1468. function(e){
  1469. //e.stopPropagation();
  1470. Mura('.mura-active-target').removeClass('mura-active-target');
  1471. Mura(this).addClass('mura-active-target');
  1472. },
  1473. function(e){
  1474. //e.stopPropagation();
  1475. Mura(this).removeClass('mura-active-target');
  1476. }
  1477. );
  1478. Mura.initDraggableObject(self);
  1479. }
  1480. } else {
  1481. var region=Mura(self).closest(".mura-region-local");
  1482. if(region && region.length ){
  1483. if(region.data('perm')){
  1484. var objectData=obj.data();
  1485. if(root.MuraInlineEditor && (root.MuraInlineEditor.objectHasConfigurator(obj) || (!root.Mura.layoutmanager && root.MuraInlineEditor.objectHasEditor(objectData)) ) ){
  1486. obj.children('.frontEndToolsModal').remove();
  1487. obj.prepend(layoutmanagertoolbar);
  1488. MuraInlineEditor.setAnchorSaveChecks(obj.node);
  1489. obj
  1490. .addClass('mura-active')
  1491. .hover(
  1492. function(e){
  1493. //e.stopPropagation();
  1494. Mura('.mura-active-target').removeClass('mura-active-target');
  1495. Mura(this).addClass('mura-active-target');
  1496. },
  1497. function(e){
  1498. //e.stopPropagation();
  1499. Mura(this).removeClass('mura-active-target');
  1500. }
  1501. );
  1502. Mura.initDraggableObject(self);
  1503. }
  1504. }
  1505. }
  1506. }
  1507. }
  1508. }
  1509. obj.hide().show();
  1510. processMarkup(obj.node);
  1511. obj.find('a[href="javascript:history.back();"]').each(function(){
  1512. Mura(this).off("click").on("click",function(e){
  1513. if(self.prevInnerHTML){
  1514. e.preventDefault();
  1515. wireUpObject(obj,self.prevInnerHTML);
  1516. if(self.prevData){
  1517. for(var p in self.prevData){
  1518. select('[name="' + p + '"]').val(self.prevData[p]);
  1519. }
  1520. }
  1521. self.prevInnerHTML=false;
  1522. self.prevData=false;
  1523. }
  1524. });
  1525. });
  1526. obj.find('FORM').each(function(){
  1527. var form=Mura(this);
  1528. var self=this;
  1529. if(form.data('async') || !(form.hasData('async') && !form.data('async')) && !(form.hasData('autowire') && !form.data('autowire')) && !form.attr('action') && !form.attr('onsubmit') && !form.attr('onSubmit')){
  1530. self.onsubmit=function(){return validateFormAjax(this);};
  1531. }
  1532. });
  1533. if(obj.data('nextnid')){
  1534. obj.find('.mura-next-n a').each(function(){
  1535. Mura(this).on('click',function(e){
  1536. e.preventDefault();
  1537. var a=this.getAttribute('href').split('?');
  1538. if(a.length==2){
  1539. root.location.hash=a[1];
  1540. }
  1541. });
  1542. })
  1543. }
  1544. obj.trigger('asyncObjectRendered');
  1545. }
  1546. function handleResponse(obj,resp){
  1547. obj=(obj.node) ? obj : Mura(obj);
  1548. if(typeof resp.data.redirect != 'undefined'){
  1549. if(resp.data.redirect && resp.data.redirect != location.href){
  1550. location.href=resp.data.redirect;
  1551. } else {
  1552. location.reload(true);
  1553. }
  1554. } else if(resp.data.apiEndpoint){
  1555. ajax({
  1556. type:"POST",
  1557. xhrFields:{ withCredentials: true },
  1558. crossDomain:true,
  1559. url:resp.data.apiEndpoint,
  1560. data:resp.data,
  1561. success:function(data){
  1562. if(typeof data=='string'){
  1563. wireUpObject(obj,data);
  1564. } else if (typeof data=='object' && '…

Large files files are truncated, but you can click here to view the full file