# HG changeset patch # User Thierry Florac # Date 1530277786 -7200 # Node ID 48092a18c2c0cb025aa158d2ec319be3a4f8f4f1 # Parent e293b7ceaadd60f006caab5abd02c7f254bae6f4 Merge PyAMS_skin==0.1.17 diff -r e293b7ceaadd -r 48092a18c2c0 src/ztfy/myams/resources/js/myams.js --- a/src/ztfy/myams/resources/js/myams.js Mon Jun 04 12:33:03 2018 +0200 +++ b/src/ztfy/myams/resources/js/myams.js Fri Jun 29 15:09:46 2018 +0200 @@ -37,6 +37,16 @@ return (this.substr(slen-dlen) === str); }; + String.prototype.unserialize = function(str) { + var str = decodeURIComponent(this); + var chunks = str.split('&'), + obj = {}; + for (var c = 0; c < chunks.length; c++) { + var split = chunks[c].split('=', 2); + obj[split[0]] = split[1]; + } + return obj; + }; /** * Array prototype extensions @@ -822,7 +832,7 @@ if (response.contentType === 'json') { ams.ajax.handleJSON(response.data); } else { - var title = event.statusText || event.type; + var title = error || event.statusText || event.type; var message = response.responseText; ams.skin.messageBox('error', { title: ams.i18n.ERROR_OCCURED, @@ -970,6 +980,19 @@ }, /** + * Post data to given URL and handle result as JSON + */ + getJSON: function() { + return function(options) { + var url = options.url; + delete options.url; + ams.ajax.post(url, options, function(result, status, request) { + ams.ajax.handleJSON(result); + }); + } + }, + + /** * Post data to given URL */ post: function(url, data, options, callback) { @@ -2624,7 +2647,10 @@ } else { target.empty(); } - }); + }) + .fail(function() { + target.empty(); + }); break; case 'json-rpc': target.html('
'); @@ -2702,6 +2728,15 @@ $('.datepicker, .timepicker, .datetimepicker', this).datetimepicker('destroy'); }, + /** Clear search form target when query is empty */ + clearSearchTarget: function() { + var input = $(this); + if (!input.val()) { + var form = $(input).parents('form').first(); + $(form.data('ams-form-submit-target')).empty(); + } + }, + /** Set SEO status */ setSEOStatus: function() { var input = $(this); @@ -3001,6 +3036,22 @@ enabled: { /** + * SVG containers + */ + svg: function(element) { + var svgs = $('.svg-container', element); + if (svgs.length > 0) { + svgs.each(function() { + var container = $(this); + var svg = $('svg', container); + svg.get(0).setAttribute('viewBox', '0 0 ' + Math.round(svg.attr('width')) + ' ' + Math.round(svg.attr('height'))); + svg.attr('width', '100%') + .attr('height', 'auto'); + }) + } + }, + + /** * Label hints */ hint: function(element) { @@ -5259,6 +5310,33 @@ } }, + switchCellContent: function(element) { + var source = $(this); + var switcher = $('i.switch', source); + var td = source.parents('td'); + var innerdiv = $(source.data('ams-switch-target') || '.inner-table-form', td); + var datatype = source.parents('tr'); + if (switcher.hasClass('fa-plus-square-o')) { + var container = datatype.parents('table'); + innerdiv.html('

'); + MyAMS.ajax.post(container.data('ams-location') + '/' + source.data('ams-switch-handler'), + {object_name: datatype.data('ams-element-name')}, + function(result) { + innerdiv.html(result); + if (result) { + MyAMS.initContent(innerdiv); + switcher.removeClass('fa-plus-square-o') + .addClass('fa-minus-square-o'); + } + }); + } else { + MyAMS.skin.cleanContainer(innerdiv); + innerdiv.empty(); + switcher.removeClass('fa-minus-square-o') + .addClass('fa-plus-square-o'); + } + }, + /** * Initialize desktop and mobile widgets */ @@ -5921,13 +5999,25 @@ } e.preventDefault(); e.stopPropagation(); - var hrefGetter = ams.getFunctionByName(href); + + var url, + target, + params; + if (href.indexOf('?') >= 0) { + url = href.split('?'); + target = url[0]; + params = url[1].unserialize(); + } else { + target = href; + params = undefined; + } + var hrefGetter = ams.getFunctionByName(target); if (typeof(hrefGetter) === 'function') { - href = hrefGetter.call(link); + href = hrefGetter.call(link, params); } if (typeof(href) === 'function') { // Javascript function call - href.call(link); + href.call(link, params); } else { // Standard AJAX or browser URL call // Convert %23 chars to # @@ -6027,9 +6117,12 @@ if (data.amsClickKeepDefault !== true) { event.preventDefault(); } - var callback = ams.getFunctionByName(data.amsClickHandler); - if (callback !== undefined) { - callback.call(source, event, data.amsClickHandlerOptions); + var clickHandlers = data.amsClickHandler.split(/\s+/); + for (var index=0; index < clickHandlers.length; index++) { + var callback = ams.getFunctionByName(clickHandlers[index]); + if (callback !== undefined) { + callback.call(source, event, data.amsClickHandlerOptions); + } } } }); @@ -6054,9 +6147,12 @@ if (data.amsChangeKeepDefault !== true) { event.preventDefault(); } - var callback = ams.getFunctionByName(data.amsChangeHandler); - if (callback !== undefined) { - callback.call(source, event, data.amsChangeHandlerOptions); + var changeHandlers = data.amsChangeHandler.split(/\s+/); + for (var index=0; index < changeHandlers.length; index++) { + var callback = ams.getFunctionByName(changeHandlers[index]); + if (callback !== undefined) { + callback.call(source, event, data.amsChangeHandlerOptions); + } } } }); @@ -6169,7 +6265,7 @@ link = $('a[href]', link); } var data = link.data(); - if (data.amsUrl) { + if (data && data.amsUrl) { if (data.amsTabLoaded) { return; } diff -r e293b7ceaadd -r 48092a18c2c0 src/ztfy/myams/resources/js/myams.min.js --- a/src/ztfy/myams/resources/js/myams.min.js Mon Jun 04 12:33:03 2018 +0200 +++ b/src/ztfy/myams/resources/js/myams.min.js Fri Jun 29 15:09:46 2018 +0200 @@ -1,1 +1,1 @@ -"use strict";!function(e,a){var t=a.console;String.prototype.startsWith=function(e){var a=this.length,t=e.length;return!(a0},void 0===e.scrollbarWidth&&(e.scrollbarWidth=function(){var a=e('
').appendTo("body"),t=a.children(),n=t.innerWidth()-t.height(99).innerWidth();return a.remove(),n}),e.fn.extend({exists:function(){return e(this).length>0},objectOrParentWithClass:function(e){return this.hasClass(e)?this:this.parents("."+e)},listattr:function(a){var t=[];return this.each(function(){t.push(e(this).attr(a))}),t},style:function(e,a,t){if(void 0!==this.get(0)){var n=this.get(0).style;return void 0!==e?void 0!==a?(t=void 0!==t?t:"",n.setProperty(e,a,t),this):n.getPropertyValue(e):n}},removeClassPrefix:function(a){return this.each(function(t,n){var s=n.className.split(" ").map(function(e){return e.startsWith(a)?"":e});n.className=e.trim(s.join(" "))}),this},contextMenu:function(a){function t(t,n,s){var i=e(window)[n](),r=e(a.menuSelector)[n](),o=t;return t+r>i&&r',openedSign:''},a),n=e(this);n.find("LI").each(function(){var a=e(this);if(a.find("UL").size()>0){a.find("A:first").append(""+t.closedSign+"");var n=a.find("A:first");"#"===n.attr("href")&&n.click(function(){return!1})}}),n.find("LI.active").each(function(){var a=e(this).parents("UL"),n=a.parent("LI");a.slideDown(t.speed),n.find("b:first").html(t.openedSign),n.addClass("open")}),n.find("LI A").on("click",function(){var a=e(this);if(!a.hasClass("active")){var s=a.attr("href").replace(/^#/,""),i=a.parent().find("UL");if(t.accordion){var r=a.parent().parents("UL"),o=n.find("UL:visible");o.each(function(a){var n=!0;if(r.each(function(e){if(r[e]===o[a])return n=!1,!1}),n&&i!==o[a]){var l=e(o[a]);!s&&l.hasClass("active")||l.slideUp(t.speed,function(){e(this).parent("LI").removeClass("open").find("B:first").delay(t.speed).html(t.closedSign)})}})}var l=a.parent().find("UL:first");s||!l.is(":visible")||l.hasClass("active")?l.slideDown(t.speed,function(){a.parent("LI").addClass("open").find("B:first").delay(t.speed).html(t.openedSign)}):l.slideUp(t.speed,function(){a.parent("LI").removeClass("open").find("B:first").delay(t.speed).html(t.closedSign)})}})}}),e.UTF8={encode:function(e){e=e.replace(/\r\n/g,"\n");for(var a="",t=0;t127&&n<2048?(a+=String.fromCharCode(n>>6|192),a+=String.fromCharCode(63&n|128)):(a+=String.fromCharCode(n>>12|224),a+=String.fromCharCode(n>>6&63|128),a+=String.fromCharCode(63&n|128))}return a},decode:function(e){for(var a="",t=0,n=0,s=0,i=0;t191&&n<224?(s=e.charCodeAt(t+1),a+=String.fromCharCode((31&n)<<6|63&s),t+=2):(s=e.charCodeAt(t+1),i=e.charCodeAt(t+2),a+=String.fromCharCode((15&n)<<12|(63&s)<<6|63&i),t+=3);return a}},void 0===a.MyAMS&&(a.MyAMS={devmode:!0,devext:"",lang:"en",throttleDelay:350,menuSpeed:235,navbarHeight:49,ajaxNav:!0,enableWidgets:!0,enableMobile:!1,enableFastclick:!1,warnOnFormChange:!1,ismobile:/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())});var n=a.MyAMS,s=n;n.baseURL=function(){var a=e('script[src*="/myams.js"], script[src*="/myams.min.js"]').attr("src");return s.devmode=a.indexOf(".min.js")<0,s.devext=s.devmode?"":".min",a.substring(0,a.lastIndexOf("/")+1)}(),n.log=function(){t&&t.debug&&t.debug(this,arguments)},n.getQueryVar=function(e,a){if(e.indexOf("?")<0)return!1;e.endsWith("&")||(e+="&");var t=new RegExp(".*?[&\\?]"+a+"=(.*?)&.*"),n=e.replace(t,"$1");return n!==e&&n},n.rgb2hex=function(a){return"#"+e.map(a.match(/\b(\d+)\b/g),function(e){return("0"+parseInt(e).toString(16)).slice(-2)}).join("")},n.generateId=function(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+e()+e()},n.generateUUID=function(){var e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var t=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===a?t:3&t|8).toString(16)})},n.getObject=function(e,a){if(e){if("string"!=typeof e)return e;var t=e.split(".");a=void 0===a||null===a?window:a;for(var n=0;n").attr("data-ams-id",t).text('@import "'+s.getSource(a)+'";'),n)var l=setInterval(function(){try{o[0].sheet.cssRules;n.call(window,!0,i),clearInterval(l)}catch(e){}},10);o.appendTo(r)}else n&&n.call(window,!1,i)},n.event={stop:function(e){e||(e=window.event),e&&"string"!=typeof e&&(e.stopPropagation?(e.stopPropagation(),e.preventDefault()):(e.cancelBubble=!0,e.returnValue=!1))}},n.browser={getInternetExplorerVersion:function(){var e=-1;if("Microsoft Internet Explorer"===navigator.appName){var a=navigator.userAgent;null!==new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})").exec(a)&&(e=parseFloat(RegExp.$1))}return e},checkVersion:function(){var e="You're not using Windows Internet Explorer.",t=this.getInternetExplorerVersion();t>-1&&(e=t>=8?"You're using a recent copy of Windows Internet Explorer.":"You should upgrade your copy of Windows Internet Explorer."),a.alert&&a.alert(e)},isIE8orlower:function(){var e="0",a=this.getInternetExplorerVersion();return a>-1&&(e=a>=9?0:1),e},copyToClipboard:function(i){function r(i){var r=!1;if(window.clipboardData&&window.clipboardData.setData)r=clipboardData.setData("Text",i);else if(document.queryCommandSupported&&document.queryCommandSupported("copy")){var o=e("