1/*jslint browser: true */ /*global jQuery: true */ 2 3/** 4 * jQuery Cookie plugin 5 * 6 * Copyright (c) 2010 Klaus Hartl (stilbuero.de) 7 * Dual licensed under the MIT and GPL licenses: 8 * http://www.opensource.org/licenses/mit-license.php 9 * http://www.gnu.org/licenses/gpl.html 10 * 11 */ 12 13// TODO JsDoc 14 15/** 16 * Create a cookie with the given key and value and other optional parameters. 17 * 18 * @example $.cookie('the_cookie', 'the_value'); 19 * @desc Set the value of a cookie. 20 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); 21 * @desc Create a cookie with all available options. 22 * @example $.cookie('the_cookie', 'the_value'); 23 * @desc Create a session cookie. 24 * @example $.cookie('the_cookie', null); 25 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain 26 * used when the cookie was set. 27 * 28 * @param String key The key of the cookie. 29 * @param String value The value of the cookie. 30 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. 31 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. 32 * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. 33 * If set to null or omitted, the cookie will be a session cookie and will not be retained 34 * when the the browser exits. 35 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). 36 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). 37 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will 38 * require a secure protocol (like HTTPS). 39 * @type undefined 40 * 41 * @name $.cookie 42 * @cat Plugins/Cookie 43 * @author Klaus Hartl/[email protected] 44 */ 45 46/** 47 * Get the value of a cookie with the given key. 48 * 49 * @example $.cookie('the_cookie'); 50 * @desc Get the value of a cookie. 51 * 52 * @param String key The key of the cookie. 53 * @return The value of the cookie. 54 * @type String 55 * 56 * @name $.cookie 57 * @cat Plugins/Cookie 58 * @author Klaus Hartl/[email protected] 59 */ 60jQuery.cookie = function (key, value, options) { 61 62 // key and value given, set cookie... 63 if (arguments.length > 1 && (value === null || typeof value !== "object")) { 64 options = jQuery.extend({}, options); 65 66 if (value === null) { 67 options.expires = -1; 68 } 69 70 if (typeof options.expires === 'number') { 71 var days = options.expires, t = options.expires = new Date(); 72 t.setDate(t.getDate() + days); 73 } 74 75 return (document.cookie = [ 76 encodeURIComponent(key), '=', 77 options.raw ? String(value) : encodeURIComponent(String(value)), 78 options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE 79 options.path ? '; path=' + options.path : '', 80 options.domain ? '; domain=' + options.domain : '', 81 options.secure ? '; secure' : '' 82 ].join('')); 83 } 84 85 // key and possibly options given, get cookie... 86 options = value || {}; 87 var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent; 88 return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null; 89}; 90; 91/*! 92 * jQuery Form Plugin 93 * version: 4.2.1 94 * Requires jQuery v1.7 or later 95 * Copyright 2017 Kevin Morris 96 * Copyright 2006 M. Alsup 97 * Project repository: https://github.com/jquery-form/form 98 * Dual licensed under the MIT and LGPLv3 licenses. 99 * https://github.com/jquery-form/form#license 100 */ 101!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=function(b,c){return void 0===c&&(c="undefined"!=typeof window?require("jquery"):require("jquery")(b)),a(c),c}:a(jQuery)}(function(a){"use strict";function b(b){var c=b.data;b.isDefaultPrevented()||(b.preventDefault(),a(b.target).closest("form").ajaxSubmit(c))}function c(b){var c=b.target,d=a(c);if(!d.is("[type=submit],[type=image]")){var e=d.closest("[type=submit]");if(0===e.length)return;c=e[0]}var f=c.form;if(f.clk=c,"image"===c.type)if(void 0!==b.offsetX)f.clk_x=b.offsetX,f.clk_y=b.offsetY;else if("function"==typeof a.fn.offset){var g=d.offset();f.clk_x=b.pageX-g.left,f.clk_y=b.pageY-g.top}else f.clk_x=b.pageX-c.offsetLeft,f.clk_y=b.pageY-c.offsetTop;setTimeout(function(){f.clk=f.clk_x=f.clk_y=null},100)}function d(){if(a.fn.ajaxSubmit.debug){var b="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(b):window.opera&&window.opera.postError&&window.opera.postError(b)}}var e={};e.fileapi=void 0!==a('<input type="file">').get(0).files,e.formdata=void 0!==window.FormData;var f=!!a.fn.prop;a.fn.attr2=function(){if(!f)return this.attr.apply(this,arguments);var a=this.prop.apply(this,arguments);return a&&a.jquery||"string"==typeof a?a:this.attr.apply(this,arguments)},a.fn.ajaxSubmit=function(b,c,g,h){function i(c){var d,e,f=a.param(c,b.traditional).split("&"),g=f.length,h=[];for(d=0;d<g;
101d++)f[d]=f[d].replace(/\+/g," "),e=f[d].split("="),h.push([decodeURIComponent(e[0]),decodeURIComponent(e[1])]);return h}function j(c){for(var d=new FormData,e=0;e<c.length;e++)d.append(c[e].name,c[e].value);if(b.extraData){var f=i(b.extraData);for(e=0;e<f.length;e++)f[e]&&d.append(f[e][0],f[e][1])}b.data=null;var g=a.extend(!0,{},a.ajaxSettings,b,{contentType:!1,processData:!1,cache:!1,type:l||"POST"});b.uploadProgress&&(g.xhr=function(){var c=a.ajaxSettings.xhr();return c.upload&&c.upload.addEventListener("progress",function(a){var c=0,d=a.loaded||a.position,e=a.total;a.lengthComputable&&(c=Math.ceil(d/e*100)),b.uploadProgress(a,d,e,c)},!1),c}),g.data=null;var h=g.beforeSend;return g.beforeSend=function(a,c){b.formData?c.data=b.formData:c.data=d,h&&h.call(this,a,c)},a.ajax(g)}function k(c){function e(a){var b=null;try{a.contentWindow&&(b=a.contentWindow.document)}catch(a){d("cannot get iframe.contentWindow document: "+a)}if(b)return b;try{b=a.contentDocument?a.contentDocument:a.document}catch(c){d("cannot get iframe.contentDocument: "+c),b=a.document}return b}function g(){function b(){try{var a=e(q).readyState;d("state = "+a),a&&"uninitialized"===a.toLowerCase()&&setTimeout(b,50)}catch(a){d("Server abort: ",a," (",a.name,")"),h(2),w&&clearTimeout(w),w=void 0}}var c=o.attr2("target"),f=o.attr2("action"),g=o.attr("enctype")||o.attr("encoding")||"multipart/form-data";x.setAttribute("target",n),l&&!/post/i.test(l)||x.setAttribute("method","POST"),f!==k.url&&x.setAttribute("action",k.url),k.skipEncodingOverride||l&&!/post/i.test(l)||o.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),k.timeout&&(w=setTimeout(function(){v=!0,h(1)},k.timeout));var i=[];try{if(k.extraData)for(var j in k.extraData)k.extraData.hasOwnProperty(j)&&(a.isPlainObject(k.extraData[j])&&k.extraData[j].hasOwnProperty("name")&&k.extraData[j].hasOwnProperty("value")?i.push(a('<input type="hidden" name="'+k.extraData[j].name+'">',z).val(k.extraData[j].value).appendTo(x)[0]):i.push(a('<input type="hidden" name="'+j+'">',z).val(k.extraData[j]).appendTo(x)[0]));k.iframeTarget||p.appendTo(A),q.attachEvent?q.attachEvent("onload",h):q.addEventListener("load",h,!1),setTimeout(b,15);try{x.submit()}catch(a){var m=document.createElement("form").submit;m.apply(x)}}finally{x.setAttribute("action",f),x.setAttribute("enctype",g),c?x.setAttribute("target",c):o.removeAttr("target"),a(i).remove()}}function h(b){if(!r.aborted&&!F){if(E=e(q),E||(d("cannot access response document"),b=2),1===b&&r)return r.abort("timeout"),void y.reject(r,"timeout");if(2===b&&r)return r.abort("server abort"),void y.reject(r,"error","server abort");if(E&&E.location.href!==k.iframeSrc||v){q.detachEvent?q.detachEvent("onload",h):q.removeEventListener("load",h,!1);var c,f="success";try{if(v)throw"timeout";var g="xml"===k.dataType||E.XMLDocument||a.isXMLDoc(E);if(d("isXml="+g),!g&&window.opera&&(null===E.body||!E.body.innerHTML)&&--G)return d("requeing onLoad callback, DOM not available"),void setTimeout(h,250);var i=E.body?E.body:E.documentElement;r.responseText=i?i.innerHTML:null,r.responseXML=E.XMLDocument?E.XMLDocument:E,g&&(k.dataType="xml"),r.getResponseHeader=function(a){return{"content-type":k.dataType}[a.toLowerCase()]},i&&(r.status=Number(i.getAttribute("status"))||r.status,r.statusText=i.getAttribute("statusText")||r.statusText);var j=(k.dataType||"").toLowerCase(),l=/(json|script|text)/.test(j);if(l||k.textarea){var n=E.getElementsByTagName("textarea")[0];if(n)r.responseText=n.value,r.status=Number(n.getAttribute("status"))||r.status,r.statusText=n.getAttribute("statusText")||r.statusText;else if(l){var o=E.getElementsByTagName("pre")[0],s=E.getElementsByTagName("body")[0];o?r.responseText=o.textContent?o.textContent:o.innerText:s&&(r.responseText=s.textContent?s.textContent:s.innerText)}}else"xml"===j&&!r.responseXML&&r.responseText&&(r.responseXML=H(r.responseText));try{D=J(r,j,k)}catch(a){f="parsererror",r.error=c=a||f}}catch(a){d("error caught: ",a),f="error",r.error=c=a||f}r.aborted&&(d("upload aborted"),f=null),r.status&&(f=r.status>=200&&r.status<300||304===r.status?"success":"error"),"success"===f?(k.success&&k.success.call(k.
101context,D,"success",r),y.resolve(r.responseText,"success",r),m&&a.event.trigger("ajaxSuccess",[r,k])):f&&(void 0===c&&(c=r.statusText),k.error&&k.error.call(k.context,r,f,c),y.reject(r,"error",c),m&&a.event.trigger("ajaxError",[r,k,c])),m&&a.event.trigger("ajaxComplete",[r,k]),m&&!--a.active&&a.event.trigger("ajaxStop"),k.complete&&k.complete.call(k.context,r,f),F=!0,k.timeout&&clearTimeout(w),setTimeout(function(){k.iframeTarget?p.attr("src",k.iframeSrc):p.remove(),r.responseXML=null},100)}}}var i,j,k,m,n,p,q,r,t,u,v,w,x=o[0],y=a.Deferred();if(y.abort=function(a){r.abort(a)},c)for(j=0;j<s.length;j++)i=a(s[j]),f?i.prop("disabled",!1):i.removeAttr("disabled");k=a.extend(!0,{},a.ajaxSettings,b),k.context=k.context||k,n="jqFormIO"+(new Date).getTime();var z=x.ownerDocument,A=o.closest("body");if(k.iframeTarget?(p=a(k.iframeTarget,z),u=p.attr2("name"),u?n=u:p.attr2("name",n)):(p=a('<iframe name="'+n+'" src="'+k.iframeSrc+'" />',z),p.css({position:"absolute",top:"-1000px",left:"-1000px"})),q=p[0],r={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(b){var c="timeout"===b?"timeout":"aborted";d("aborting upload... "+c),this.aborted=1;try{q.contentWindow.document.execCommand&&q.contentWindow.document.execCommand("Stop")}catch(a){}p.attr("src",k.iframeSrc),r.error=c,k.error&&k.error.call(k.context,r,c,b),m&&a.event.trigger("ajaxError",[r,k,c]),k.complete&&k.complete.call(k.context,r,c)}},m=k.global,m&&0==a.active++&&a.event.trigger("ajaxStart"),m&&a.event.trigger("ajaxSend",[r,k]),k.beforeSend&&k.beforeSend.call(k.context,r,k)===!1)return k.global&&a.active--,y.reject(),y;if(r.aborted)return y.reject(),y;(t=x.clk)&&(u=t.name)&&!t.disabled&&(k.extraData=k.extraData||{},k.extraData[u]=t.value,"image"===t.type&&(k.extraData[u+".x"]=x.clk_x,k.extraData[u+".y"]=x.clk_y));var B=a("meta[name=csrf-token]").attr("content"),C=a("meta[name=csrf-param]").attr("content");C&&B&&(k.extraData=k.extraData||{},k.extraData[C]=B),k.forceSync?g():setTimeout(g,10);var D,E,F,G=50,H=a.parseXML||function(a,b){return window.ActiveXObject?(b=new ActiveXObject("Microsoft.XMLDOM"),b.async="false",b.loadXML(a)):b=(new DOMParser).parseFromString(a,"text/xml"),b&&b.documentElement&&"parsererror"!==b.documentElement.nodeName?b:null},I=a.parseJSON||function(a){return window.eval("("+a+")")},J=function(b,c,d){var e=b.getResponseHeader("content-type")||"",f=("xml"===c||!c)&&e.indexOf("xml")>=0,g=f?b.responseXML:b.responseText;return f&&"parsererror"===g.documentElement.nodeName&&a.error&&a.error("parsererror"),d&&d.dataFilter&&(g=d.dataFilter(g,c)),"string"==typeof g&&(("json"===c||!c)&&e.indexOf("json")>=0?g=I(g):("script"===c||!c)&&e.indexOf("javascript")>=0&&a.globalEval(g)),g};return y}if(!this.length)return d("ajaxSubmit: skipping submit process - no element selected"),this;var l,m,n,o=this;"function"==typeof b?b={success:b}:"string"==typeof b||b===!1&&arguments.length>0?(b={url:b,data:c,dataType:g},"function"==typeof h&&(b.success=h)):void 0===b&&(b={}),l=b.method||b.type||this.attr2("method"),m=b.url||this.attr2("action"),n="string"==typeof m?a.trim(m):"",n=n||window.location.href||"",n&&(n=(n.match(/^([^#]+)/)||[])[1]),b=a.extend(!0,{url:n,success:a.ajaxSettings.success,type:l||a.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},b);var p={};if(this.trigger("form-pre-serialize",[this,b,p]),p.veto)return d("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(b.beforeSerialize&&b.beforeSerialize(this,b)===!1)return d("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var q=b.traditional;void 0===q&&(q=a.ajaxSettings.traditional);var r,s=[],t=this.formToArray(b.semantic,s,b.filtering);if(b.data){var u=a.isFunction(b.data)?b.data(t):b.data;b.extraData=u,r=a.param(u,q)}if(b.beforeSubmit&&b.beforeSubmit(t,this,b)===!1)return d("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[t,this,b,p]),p.veto)return d("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var v=a.param(t,q);r&&(v=v?v+"&"+r:r),"GET"===b.type.toUpperCase()?(b.url+=(b.url.indexOf("?")>=0?"&":"?")+v,b.data=null):b.data=v;var w=[];if(b.resetForm&&w.push(function(){o.resetForm()}),b.clearForm&&w.push(function(){o.clearForm(b.includeHidden)}),!b.dataType&&b.target){var x=b.success||function(){};w.push(function(c,d,e){var f=arguments,g=b.replaceTarget?"replaceWith":"html";a(b.target)[g](c).each(function(){x.apply(this,f)})})}
101else b.success&&(a.isArray(b.success)?a.merge(w,b.success):w.push(b.success));if(b.success=function(a,c,d){for(var e=b.context||this,f=0,g=w.length;f<g;f++)w[f].apply(e,[a,c,d||o,o])},b.error){var y=b.error;b.error=function(a,c,d){var e=b.context||this;y.apply(e,[a,c,d,o])}}if(b.complete){var z=b.complete;b.complete=function(a,c){var d=b.context||this;z.apply(d,[a,c,o])}}var A=a("input[type=file]:enabled",this).filter(function(){return""!==a(this).val()}),B=A.length>0,C="multipart/form-data",D=o.attr("enctype")===C||o.attr("encoding")===C,E=e.fileapi&&e.formdata;d("fileAPI :"+E);var F,G=(B||D)&&!E;b.iframe!==!1&&(b.iframe||G)?b.closeKeepAlive?a.get(b.closeKeepAlive,function(){F=k(t)}):F=k(t):F=(B||D)&&E?j(t):a.ajax(b),o.removeData("jqxhr").data("jqxhr",F);for(var H=0;H<s.length;H++)s[H]=null;return this.trigger("form-submit-notify",[this,b]),this},a.fn.ajaxForm=function(e,f,g,h){if(("string"==typeof e||e===!1&&arguments.length>0)&&(e={url:e,data:f,dataType:g},"function"==typeof h&&(e.success=h)),e=e||{},e.delegation=e.delegation&&a.isFunction(a.fn.on),!e.delegation&&0===this.length){var i={s:this.selector,c:this.context};return!a.isReady&&i.s?(d("DOM not ready, queuing ajaxForm"),a(function(){a(i.s,i.c).ajaxForm(e)}),this):(d("terminating; zero elements found by selector"+(a.isReady?"":" (DOM not ready)")),this)}return e.delegation?(a(document).off("submit.form-plugin",this.selector,b).off("click.form-plugin",this.selector,c).on("submit.form-plugin",this.selector,e,b).on("click.form-plugin",this.selector,e,c),this):this.ajaxFormUnbind().on("submit.form-plugin",e,b).on("click.form-plugin",e,c)},a.fn.ajaxFormUnbind=function(){return this.off("submit.form-plugin click.form-plugin")},a.fn.formToArray=function(b,c,d){var f=[];if(0===this.length)return f;var g,h=this[0],i=this.attr("id"),j=b||void 0===h.elements?h.getElementsByTagName("*"):h.elements;if(j&&(j=a.makeArray(j)),i&&(b||/(Edge|Trident)\//.test(navigator.userAgent))&&(g=a(':input[form="'+i+'"]').get(),g.length&&(j=(j||[]).concat(g))),!j||!j.length)return f;a.isFunction(d)&&(j=a.map(j,d));var k,l,m,n,o,p,q;for(k=0,p=j.length;k<p;k++)if(o=j[k],(m=o.name)&&!o.disabled)if(b&&h.clk&&"image"===o.type)h.clk===o&&(f.push({name:m,value:a(o).val(),type:o.type}),f.push({name:m+".x",value:h.clk_x},{name:m+".y",value:h.clk_y}));else if((n=a.fieldValue(o,!0))&&n.constructor===Array)for(c&&c.push(o),l=0,q=n.length;l<q;l++)f.push({name:m,value:n[l]});else if(e.fileapi&&"file"===o.type){c&&c.push(o);var r=o.files;if(r.length)for(l=0;l<r.length;l++)f.push({name:m,value:r[l],type:o.type});else f.push({name:m,value:"",type:o.type})}else null!==n&&void 0!==n&&(c&&c.push(o),f.push({name:m,value:n,type:o.type,required:o.required}));if(!b&&h.clk){var s=a(h.clk),t=s[0];m=t.name,m&&!t.disabled&&"image"===t.type&&(f.push({name:m,value:s.val()}),f.push({name:m+".x",value:h.clk_x},{name:m+".y",value:h.clk_y}))}return f},a.fn.formSerialize=function(b){return a.param(this.formToArray(b))},a.fn.fieldSerialize=function(b){var c=[];return this.each(function(){var d=this.name;if(d){var e=a.fieldValue(this,b);if(e&&e.constructor===Array)for(var f=0,g=e.length;f<g;f++)c.push({name:d,value:e[f]});else null!==e&&void 0!==e&&c.push({name:this.name,value:e})}}),a.param(c)},a.fn.fieldValue=function(b){for(var c=[],d=0,e=this.length;d<e;d++){var f=this[d],g=a.fieldValue(f,b);null===g||void 0===g||g.constructor===Array&&!g.length||(g.constructor===Array?a.merge
101(c,g):c.push(g))}return c},a.fieldValue=function(b,c){var d=b.name,e=b.type,f=b.tagName.toLowerCase();if(void 0===c&&(c=!0),c&&(!d||b.disabled||"reset"===e||"button"===e||("checkbox"===e||"radio"===e)&&!b.checked||("submit"===e||"image"===e)&&b.form&&b.form.clk!==b||"select"===f&&b.selectedIndex===-1))return null;if("select"===f){var g=b.selectedIndex;if(g<0)return null;for(var h=[],i=b.options,j="select-one"===e,k=j?g+1:i.length,l=j?g:0;l<k;l++){var m=i[l];if(m.selected&&!m.disabled){var n=m.value;if(n||(n=m.attributes&&m.attributes.value&&!m.attributes.value.specified?m.text:m.value),j)return n;h.push(n)}}return h}return a(b).val().replace(/\r?\n/g,"\r\n")},a.fn.clearForm=function(b){return this.each(function(){a("input,select,textarea",this).clearFields(b)})},a.fn.clearFields=a.fn.clearInputs=function(b){var c=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;return this.each(function(){var d=this.type,e=this.tagName.toLowerCase();c.test(d)||"textarea"===e?this.value="":"checkbox"===d||"radio"===d?this.checked=!1:"select"===e?this.selectedIndex=-1:"file"===d?/MSIE/.test(navigator.userAgent)?a(this).replaceWith(a(this).clone(!0)):a(this).val(""):b&&(b===!0&&/hidden/.test(d)||"string"==typeof b&&a(this).is(b))&&(this.value="")})},a.fn.resetForm=function(){return this.each(function(){var b=a(this),c=this.tagName.toLowerCase();switch(c){case"input":this.checked=this.defaultChecked;case"textarea":return this.value=this.defaultValue,!0;case"option":case"optgroup":var d=b.parents("select");return d.length&&d[0].multiple?"option"===c?this.selected=this.defaultSelected:b.find("option").resetForm():d.resetForm(),!0;case"select":return b.find("option").each(function(a){if(this.selected=this.defaultSelected,this.defaultSelected&&!b[0].multiple)return b[0].selectedIndex=a,!1}),!0;case"label":var e=a(b.attr("for")),f=b.find("input,select,textarea");return e[0]&&f.unshift(e[0]),f.resetForm(),!0;case"form":return("function"==typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset(),!0;default:return b.find("form,input,label,select,textarea").resetForm(),!0}})},a.fn.enable=function(a){return void 0===a&&(a=!0),this.each(function(){this.disabled=!a})},a.fn.selected=function(b){return void 0===b&&(b=!0),this.each(function(){var c=this.type;if("checkbox"===c||"radio"===c)this.checked=b;else if("option"===this.tagName.toLowerCase()){var d=a(this).parent("select");b&&d[0]&&"select-one"===d[0].type&&d.find("option").selected(!1),this.selected=b}})},a.fn.ajaxSubmit.debug=!1}); 102; 103(function ($) { 104 105 $.fn.customScrollbar = function (options, args) { 106 107 var defaultOptions = { 108 skin: undefined, 109 hScroll: true, 110 vScroll: true, 111 updateOnWindowResize: false, 112 animationSpeed: 300, 113 onCustomScroll: undefined, 114 swipeSpeed: 1, 115 wheelSpeed: 40, 116 fixedThumbWidth: undefined, 117 fixedThumbHeight: undefined, 118 preventDefaultScroll: false 119 } 120 121 var Scrollable = function (element, options) { 122 this.$element = $(element); 123 this.options = options; 124 this.addScrollableClass(); 125 this.addSkinClass(); 126 this.addScrollBarComponents(); 127 if (this.options.vScroll) 128 this.vScrollbar = new Scrollbar(this, new VSizing()); 129 if (this.options.hScroll) 130 this.hScrollbar = new Scrollbar(this, new HSizing()); 131 this.$element.data("scrollable", this); 132 this.initKeyboardScrolling(); 133 this.bindEvents(); 134 } 135 136 Scrollable.prototype = { 137 138 addScrollableClass: function () { 139 if (!this.$element.hasClass("scrollable")) { 140 this.scrollableAdded = true; 141 this.$element.addClass("scrollable"); 142 } 143 }, 144 145 removeScrollableClass: function () { 146 if (this.scrollableAdded) 147 this.$element.removeClass("scrollable"); 148 }, 149 150 addSkinClass: function () { 151 if (typeof(this.options.skin) == "string" && !this.$element.hasClass(this.options.skin)) { 152 this.skinClassAdded = true; 153 this.$element.addClass(this.options.skin); 154 } 155 }, 156 157 removeSkinClass: function () { 158 if (this.skinClassAdded) 159 this.$element.removeClass(this.options.skin); 160 }, 161 162 addScrollBarComponents: function () { 163 this.assignViewPort(); 164 if (this.$viewPort.length == 0) { 165 this.$element.wrapInner("<div class=\"viewport\" />"); 166 this.assignViewPort(); 167 this.viewPortAdded = true; 168 } 169 this.assignOverview(); 170 if (this.$overview.length == 0) { 171 this.$viewPort.wrapInner("<div class=\"overview\" />"); 172 this.assignOverview(); 173 this.overviewAdded = true; 174 } 175 this.addScrollBar("vertical", "prepend"); 176 this.addScrollBar("horizontal", "append"); 177 }, 178 179 removeScrollbarComponents: function () { 180 this.removeScrollbar("vertical"); 181 this.removeScrollbar("horizontal"); 182 if (this.overviewAdded) 183 this.$element.unwrap(); 184 if (this.viewPortAdded) 185 this.$element.unwrap(); 186 }, 187 188 removeScrollbar: function (orientation) { 189 if (this[orientation + "ScrollbarAdded"]) 190 this.$element.find(".scroll-bar." + orientation).remove(); 191 }, 192 193 assignViewPort: function () { 194 this.$viewPort = this.$element.find(".viewport"); 195 }, 196 197 assignOverview: function () { 198 this.$overview = this.$viewPort.find(".overview"); 199 }, 200 201 addScrollBar: function (orientation, fun) { 202 if (this.$element.find(".scroll-bar." + orientation).length == 0) { 203 this.$element[fun]("<div class='scroll-bar " + orientation + "'><div class='thumb'></div></div>") 204 this[orientation + "ScrollbarAdded"] = true; 205 } 206 }, 207 208 resize: function (keepPosition) { 209 if (this.vScrollbar) 210 this.vScrollbar.resize(keepPosition); 211 if (this.hScrollbar) 212 this.hScrollbar.resize(keepPosition); 213 }, 214 215 scrollTo: function (element) { 216 if (this.vScrollbar) 217 this.vScrollbar.scrollToElement(element); 218 if (this.hScrollbar) 219 this.hScrollbar.scrollToElement(element); 220 }, 221 222 scrollToXY: function (x, y) { 223 this.scrollToX(x); 224 this.scrollToY(y); 225 }, 226 227 scrollToX: function (x) { 228 if (this.hScrollbar) 229 this.hScrollbar.scrollOverviewTo(x, true); 230 }, 231 232 scrollToY: function (y) { 233 if (this.vScrollbar) 234 this.vScrollbar.scrollOverviewTo(y, true); 235 }, 236 237 scrollByX: function (x) { 238 if (this.hScrollbar) 239 this.scrollToX(this.hScrollbar.overviewPosition() + x); 240 }, 241 242 scrollByY: function (y) { 243 if (this.vScrollbar) 244 this.scrollToY(this.vScrollbar.overviewPosition() + y); 245 }, 246 247 remove: function () { 248 this.removeScrollableClass(); 249 this.removeSkinClass(); 250 this.removeScrollbarComponents(); 251 this.$element.data("scrollable", null); 252 this.removeKeyboardScrolling(); 253 if (this.vScrollbar) 254 this.vScrollbar.remove(); 255 if (this.hScrollbar) 256 this.hScrollbar.remove(); 257 }, 258 259 setAnimationSpeed: function (speed) { 260 this.options.animationSpeed = speed; 261 }, 262 263 isInside: function (element, wrappingElement) { 264 var $element = $(element); 265 var $wrappingElement = $(wrappingElement); 266 var elementOffset = $element.offset(); 267 var wrappingElementOffset = $wrappingElement.offset(); 268 return (elementOffset.top >= wrappingElementOffset.top) && (elementOffset.left >= wrappingElementOffset.left) && 269 (elementOffset.top + $element.height() <= wrappingElementOffset.top + $wrappingElement.height()) && 270 (elementOffset.left + $element.width() <= wrappingElementOffset.left + $wrappingElement.width()) 271 }, 272 273 initKeyboardScrolling: function () { 274 var _this = this; 275
276 this.elementKeydown = function (event) { 277 if (document.activeElement === _this.$element[0]) { 278 if (_this.vScrollbar) 279 _this.vScrollbar.keyScroll(event); 280 if (_this.hScrollbar) 281 _this.hScrollbar.keyScroll(event); 282 } 283 } 284 285 this.$element 286 .attr('tabindex', '-1') 287 .keydown(this.elementKeydown); 288 }, 289 290 removeKeyboardScrolling: function () { 291 this.$element 292 .removeAttr('tabindex') 293 .unbind("keydown", this.elementKeydown); 294 }, 295 296 bindEvents: function () { 297 if (this.options.onCustomScroll) 298 this.$element.on("customScroll", this.options.onCustomScroll); 299 } 300 301 } 302 303 var Scrollbar = function (scrollable, sizing) { 304 this.scrollable = scrollable; 305 this.sizing = sizing 306 this.$scrollBar = this.sizing.scrollBar(this.scrollable.$element); 307 this.$thumb = this.$scrollBar.find(".thumb"); 308 this.setScrollPosition(0, 0); 309 this.resize(); 310 this.initMouseMoveScrolling(); 311 this.initMouseWheelScrolling(); 312 this.initTouchScrolling(); 313 this.initMouseClickScrolling(); 314 this.initWindowResize(); 315 } 316 317 Scrollbar.prototype = { 318 319 resize: function (keepPosition) { 320 this.overviewSize = this.sizing.size(this.scrollable.$overview); 321 this.calculateViewPortSize(); 322 this.sizing.size(this.scrollable.$viewPort, this.viewPortSize); 323 this.ratio = this.viewPortSize / this.overviewSize; 324 this.sizing.size(this.$scrollBar, this.viewPortSize); 325 this.thumbSize = this.calculateThumbSize(); 326 this.sizing.size(this.$thumb, this.thumbSize); 327 this.maxThumbPosition = this.calculateMaxThumbPosition(); 328 this.maxOverviewPosition = this.calculateMaxOverviewPosition(); 329 this.enabled = (this.overviewSize > this.viewPortSize); 330 if (this.scrollPercent === undefined) 331 this.scrollPercent = 0.0; 332 if (this.enabled) 333 this.rescroll(keepPosition); 334 else 335 this.setScrollPosition(0, 0); 336 this.$scrollBar.toggle(this.enabled); 337 }, 338 339 calculateViewPortSize: function () { 340 var elementSize = this.sizing.size(this.scrollable.$element); 341 if (elementSize > 0 && !this.maxSizeUsed) { 342 this.viewPortSize = elementSize; 343 this.maxSizeUsed = false; 344 } 345 else { 346 var maxSize = this.sizing.maxSize(this.scrollable.$element); 347 this.viewPortSize = Math.min(maxSize, this.overviewSize); 348 this.maxSizeUsed = true; 349 } 350 }, 351 352 calculateThumbSize: function () { 353 var fixedSize = this.sizing.fixedThumbSize(this.scrollable.options) 354 var size; 355 if (fixedSize) 356 size = fixedSize; 357 else 358 size = this.ratio * this.viewPortSize 359 return Math.max(size, this.sizing.minSize(this.$thumb)); 360 }, 361 362 initMouseMoveScrolling: function () { 363 var _this = this; 364 this.$thumb.mousedown(function (event) { 365 if (_this.enabled) 366 _this.startMouseMoveScrolling(event); 367 }); 368 this.documentMouseup = function (event) { 369 _this.stopMouseMoveScrolling(event); 370 }; 371 $(document).mouseup(this.documentMouseup); 372 this.documentMousemove = function (event) { 373 _this.mouseMoveScroll(event); 374 }; 375 $(document).mousemove(this.documentMousemove); 376 this.$thumb.click(function (event) { 377 event.stopPropagation(); 378 }); 379 }, 380 381 removeMouseMoveScrolling: function () { 382 this.$thumb.unbind(); 383 $(document).unbind("mouseup", this.documentMouseup); 384 $(document).unbind("mousemove", this.documentMousemove); 385 }, 386 387 initMouseWheelScrolling: function () { 388 var _this = this; 389 this.scrollable.$element.mousewheel(function (event, delta, deltaX, deltaY) { 390 if (_this.enabled) { 391 var scrolled = _this.mouseWheelScroll(deltaX, deltaY); 392 _this.stopEventConditionally(event, scrolled); 393 } 394 }); 395 }, 396 397 removeMouseWheelScrolling: function () { 398 this.scrollable.$element.unbind("mousewheel"); 399 }, 400 401 initTouchScrolling: function () { 402 if (document.addEventListener) { 403 var _this = this; 404 this.elementTouchstart = function (event) { 405 if (_this.enabled) 406 _this.startTouchScrolling(event); 407 } 408 this.scrollable.$element[0].addEventListener("touchstart", this.elementTouchstart); 409 this.documentTouchmove = function (event) { 410 _this.touchScroll(event); 411 } 412 this.scrollable.$element[0].addEventListener("touchmove", this.documentTouchmove); 413 this.elementTouchend = function (event) { 414 _this.stopTouchScrolling(event); 415 } 416 this.scrollable.$element[0].addEventListener("touchend", this.elementTouchend); 417 } 418 }, 419 420 removeTouchScrolling: function () { 421 if (document.addEventListener) { 422 this.scrollable.$element[0].removeEventListener("touchstart", this.elementTouchstart); 423 document.removeEventListener("touchmove", this.documentTouchmove); 424 this.scrollable.$element[0].removeEventListener("touchend", this.elementTouchend); 425 } 426 }, 427 428 initMouseClickScrolling: function () { 429 var _this = this; 430 this.scrollBarClick = function (event) { 431 _this.mouseClickScroll(event); 432 }; 433 this.$scrollBar.click(this.scrollBarClick); 434 }, 435 436 removeMouseClickScrolling: function () { 437 this.$scrollBar.unbind("click", this.scrollBarClick); 438 }, 439 440 initWindowResize: function () { 441 if (this.scrollable.options.updateOnWindowResize) { 442 var _this = this; 443 this.windowResize = function () { 444 _this.resize(); 445 }; 446 $(window).resize(this.windowResize); 447 } 448 }, 449 450 removeWindowResize: function () { 451 $(window).unbind("resize", this.windowResize); 452 }, 453 454 isKeyScrolling: function (key) { 455 return this.keyScrollDelta(key) != null; 456 }, 457 458 keyScrollDelta: function (key) { 459 for (var scrollingKey in this.sizing.scrollingKeys) 460 if (scrollingKey == key) 461 return this.sizing.scrollingKeys[key](this.viewPortSize); 462 return null; 463 }, 464 465 startMouseMoveScrolling: function (event) { 466 this.mouseMoveScrolling = true; 467 $("body").addClass("not-selectable"); 468 this.setUnselectable($("body"), "on"); 469 this.setScrollEvent(event); 470 event.preventDefault(); 471 }, 472 473 stopMouseMoveScrolling: function (event) { 474 this.mouseMoveScrolling = false;
475 $("body").removeClass("not-selectable"); 476 this.setUnselectable($("body"), null); 477 }, 478 479 setUnselectable: function (element, value) { 480 if (element.attr("unselectable") != value) { 481 element.attr("unselectable", value); 482 element.find(':not(input)').attr('unselectable', value); 483 } 484 }, 485 486 mouseMoveScroll: function (event) { 487 if (this.mouseMoveScrolling) { 488 var delta = this.sizing.mouseDelta(this.scrollEvent, event); 489 this.scrollThumbBy(delta); 490 this.setScrollEvent(event); 491 } 492 }, 493 494 startTouchScrolling: function (event) { 495 if (event.touches && event.touches.length == 1) { 496 this.setScrollEvent(event.touches[0]); 497 this.touchScrolling = true; 498 event.stopPropagation(); 499 } 500 }, 501 502 touchScroll: function (event) { 503 if (this.touchScrolling && event.touches && event.touches.length == 1) { 504 var delta = -this.sizing.mouseDelta(this.scrollEvent, event.touches[0]) * this.scrollable.options.swipeSpeed; 505 var scrolled = this.scrollOverviewBy(delta); 506 if (scrolled) 507 this.setScrollEvent(event.touches[0]); 508 this.stopEventConditionally(event, scrolled); 509 } 510 }, 511 512 stopTouchScrolling: function (event) { 513 this.touchScrolling = false; 514 event.stopPropagation(); 515 }, 516 517 mouseWheelScroll: function (deltaX, deltaY) { 518 var delta = -this.sizing.wheelDelta(deltaX, deltaY) * this.scrollable.options.wheelSpeed; 519 if (delta != 0) 520 return this.scrollOverviewBy(delta); 521 }, 522 523 mouseClickScroll: function (event) { 524 var delta = this.viewPortSize - 20; 525 if (event["page" + this.sizing.scrollAxis()] < this.$thumb.offset()[this.sizing.offsetComponent()]) 526 // mouse click over thumb 527 delta = -delta; 528 this.scrollOverviewBy(delta); 529 }, 530 531 keyScroll: function (event) { 532 var keyDown = event.which; 533 if (this.enabled && this.isKeyScrolling(keyDown)) { 534 var scrolled = this.scrollOverviewBy(this.keyScrollDelta(keyDown)); 535 this.stopEventConditionally(event, scrolled); 536 } 537 }, 538 539 scrollThumbBy: function (delta) { 540 var thumbPosition = this.thumbPosition(); 541 thumbPosition += delta; 542 thumbPosition = this.positionOrMax(thumbPosition, this.maxThumbPosition); 543 var oldScrollPercent = this.scrollPercent; 544 this.scrollPercent = thumbPosition / this.maxThumbPosition; 545 if (oldScrollPercent != this.scrollPercent) { 546 var overviewPosition = (thumbPosition * this.maxOverviewPosition) / this.maxThumbPosition; 547 this.setScrollPosition(overviewPosition, thumbPosition); 548 this.triggerCustomScroll(oldScrollPercent); 549 return true 550 } 551 else 552 return false; 553 }, 554 555 thumbPosition: function () { 556 return this.$thumb.position()[this.sizing.offsetComponent()]; 557 }, 558 559 scrollOverviewBy: function (delta) { 560 var overviewPosition = this.overviewPosition() + delta; 561 return this.scrollOverviewTo(overviewPosition, false); 562 }, 563 564 overviewPosition: function () { 565 return -this.scrollable.$overview.position()[this.sizing.offsetComponent()]; 566 }, 567 568 scrollOverviewTo: function (overviewPosition, animate) { 569 overviewPosition = this.positionOrMax(overviewPosition, this.maxOverviewPosition); 570 var oldScrollPercent = this.scrollPercent; 571 this.scrollPercent = overviewPosition / this.maxOverviewPosition; 572 if (oldScrollPercent != this.scrollPercent) { 573 var thumbPosition = this.scrollPercent * this.maxThumbPosition; 574 if (animate) 575 this.setScrollPositionWithAnimation(overviewPosition, thumbPosition); 576 else 577 this.setScrollPosition(overviewPosition, thumbPosition); 578 this.triggerCustomScroll(oldScrollPercent); 579 return true; 580 } 581 else 582 return false; 583 }, 584 585 positionOrMax: function (p, max) { 586 if (p < 0) 587 return 0; 588 else if (p > max) 589 return max; 590 else 591 return p; 592 }, 593 594 triggerCustomScroll: function (oldScrollPercent) { 595 this.scrollable.$element.trigger("customScroll", { 596 scrollAxis: this.sizing.scrollAxis(), 597 direction: this.sizing.scrollDirection(oldScrollPercent, this.scrollPercent), 598 scrollPercent: this.scrollPercent * 100 599 } 600 ); 601 }, 602 603 rescroll: function (keepPosition) { 604 if (keepPosition) { 605 var overviewPosition = this.positionOrMax(this.overviewPosition(), this.maxOverviewPosition); 606 this.scrollPercent = overviewPosition / this.maxOverviewPosition; 607 var thumbPosition = this.scrollPercent * this.maxThumbPosition; 608 this.setScrollPosition(overviewPosition, thumbPosition); 609 } 610 else { 611 var thumbPosition = this.scrollPercent * this.maxThumbPosition; 612 var overviewPosition = this.scrollPercent * this.maxOverviewPosition; 613 this.setScrollPosition(overviewPosition, thumbPosition); 614 } 615 }, 616 617 setScrollPosition: function (overviewPosition, thumbPosition) { 618 this.$thumb.css(this.sizing.offsetComponent(), thumbPosition + "px"); 619 this.scrollable.$overview.css(this.sizing.offsetComponent(), -overviewPosition + "px"); 620 }, 621 622 setScrollPositionWithAnimation: function (overviewPosition, thumbPosition) { 623 var thumbAnimationOpts = {}; 624 var overviewAnimationOpts = {}; 625 thumbAnimationOpts[this.sizing.offsetComponent()] = thumbPosition + "px"; 626 this.$thumb.animate(thumbAnimationOpts, this.scrollable.options.animationSpeed); 627 overviewAnimationOpts[this.sizing.offsetComponent()] = -overviewPosition + "px"; 628 this.scrollable.$overview.animate(overviewAnimationOpts, this.scrollable.options.animationSpeed); 629 }, 630 631 calculateMaxThumbPosition: function () { 632 return Math.max(0, this.sizing.size(this.$scrollBar) - this.thumbSize); 633 }, 634 635 calculateMaxOverviewPosition: function () { 636 return Math.max(0, this.sizing.size(this.scrollable.$overview) - this.sizing.size(this.scrollable.$viewPort)); 637 }, 638 639 setScrollEvent: function (event) { 640 var attr = "page" + this.sizing.scrollAxis(); 641 if (!this.scrollEvent || this.scrollEvent[attr] != event[attr]) 642 this.scrollEvent = {pageX: event.pageX, pageY: event.pageY}; 643 }, 644 645 scrollToElement: function (element) { 646 var $element = $(element); 647 if (this.sizing.isInside($element, this.scrollable.$overview) && !this.sizing.isInside($element, this.scrollable.$viewPort)) { 648 var elementOffset = $element.offset(); 649 var overviewOffset = this.scrollable.$overview.offset(); 650 var viewPortOffset = this.scrollable.$viewPort.offset(); 651 this.scrollOverviewTo(elementOffset[this.sizing.offsetComponent()] - overviewOffset[this.sizing.offsetComponent()], true); 652 } 653 }, 654 655 remove: function () { 656 this.removeMouseMoveScrolling(); 657 this.removeMouseWheelScrolling(); 658 this.removeTouchScrolling(); 659 this.removeMouseClickScrolling(); 660 this.removeWindowResize(); 661 }, 662 663 stopEventConditionally: function (event, condition) { 664 if (condition || this.scrollable.options.preventDefaultScroll) { 665 event.preventDefault(); 666 event.stopPropagation(); 667 } 668 } 669 670 } 671 672 var HSizing = function () { 673 } 674 675 HSizing.prototype = { 676 size: function ($el, arg) { 677 if (arg) 678 return $el.width(arg); 679 else 680 return $el.width(); 681 }, 682 683 minSize: function ($el) { 684 return parseInt($el.css("min-width")) || 0; 685 }, 686 687 maxSize: function ($el) { 688 return parseInt($el.css("max-width")) || 0; 689 }, 690 691 fixedThumbSize: function (options) { 692 return options.fixedThumbWidth; 693 }, 694 695 scrollBar: function ($el) { 696 return $el.find(".scroll-bar.horizontal"); 697 }, 698 699 mouseDelta: function (event1, event2) { 700 return event2.pageX - event1.pageX; 701 }, 702 703 offsetComponent: function () { 704 return "left"; 705 }, 706 707 wheelDelta: function (deltaX, deltaY) { 708 return deltaX; 709 }, 710 711 scrollAxis: function () { 712 return "X"; 713 }, 714 715 scrollDirection: function (oldPercent, newPercent) { 716 return oldPercent < newPercent ? "right" : "left"; 717 }, 718 719 scrollingKeys: { 720 37: function (viewPortSize) { 721 return -10; //arrow left 722 }, 723 39: function (viewPortSize) { 724 return 10; //arrow right 725 } 726 }, 727 728 isInside: function (element, wrappingElement) { 729 var $element = $(element); 730 var $wrappingElement = $(wrappingElement); 731 var elementOffset = $element.offset(); 732 var wrappingElementOffset = $wrappingElement.offset(); 733 return (elementOffset.left >= wrappingElementOffset.left) && 734 (elementOffset.left + $element.width() <= wrappingElementOffset.left + $wrappingElement.width()); 735 } 736 737 } 738 739 var VSizing = function () { 740 } 741 742 VSizing.prototype = { 743 744 size: function ($el, arg) { 745 if (arg) 746 return $el.height(arg); 747 else 748 return $el.height(); 749 }, 750 751 minSize: function ($el) { 752 return parseInt($el.css("min-height")) || 0; 753 }, 754 755 maxSize: function ($el) { 756 return parseInt($el.css("max-height")) || 0; 757 }, 758 759 fixedThumbSize: function (options) { 760 return options.fixedThumbHeight; 761 }, 762 763 scrollBar: function ($el) { 764 return $el.find(".scroll-bar.vertical"); 765 }, 766 767 mouseDelta: function (event1, event2) { 768 return event2.pageY - event1.pageY; 769 }, 770 771 offsetComponent: function () { 772 return "top"; 773 }, 774 775 wheelDelta: function (deltaX, deltaY) { 776 return deltaY; 777 }, 778 779 scrollAxis: function () { 780 return "Y"; 781 }, 782 783 scrollDirection: function (oldPercent, newPercent) { 784 return oldPercent < newPercent ? "down" : "up"; 785 }, 786 787 scrollingKeys: { 788 38: function (viewPortSize) { 789 return -10; //arrow up 790 }, 791 40: function (viewPortSize) { 792 return 10; //arrow down 793 }, 794 33: function (viewPortSize) { 795 return -(viewPortSize - 20); //page up 796 }, 797 34: function (viewPortSize) { 798 return viewPortSize - 20; //page down 799 } 800 }, 801 802 isInside: function (element, wrappingElement) { 803 var $element = $(element); 804 var $wrappingElement = $(wrappingElement); 805 var elementOffset = $element.offset(); 806 var wrappingElementOffset = $wrappingElement.offset(); 807 return (elementOffset.top >= wrappingElementOffset.top) && 808 (elementOffset.top + $element.height() <= wrappingElementOffset.top + $wrappingElement.height()); 809 } 810 811 } 812 813 return this.each(function () { 814 if (options == undefined) 815 options = defaultOptions; 816 if (typeof(options) == "string") { 817 var scrollable = $(this).data("scrollable"); 818 if (scrollable) 819 scrollable[options](args); 820 } 821 else if (typeof(options) == "object") { 822 options = $.extend(defaultOptions, options); 823 new Scrollable($(this), options); 824 } 825 else 826 throw "Invalid type of options"; 827 }); 828 829 } 830 ; 831 832}) 833 (jQuery); 834 835(function ($) { 836 837 var types = ['DOMMouseScroll', 'mousewheel']; 838 839 if ($.event.fixHooks) { 840 for (var i = types.length; i;) { 841 $.event.fixHooks[ types[--i] ] = $.event.mouseHooks; 842 } 843 } 844 845 $.event.special.mousewheel = { 846 setup: function () { 847 if (this.addEventListener) { 848 for (var i = types.length; i;) { 849 this.addEventListener(types[--i], handler, false); 850 } 851 } else { 852 this.onmousewheel = handler; 853 } 854 }, 855 856 teardown: function () { 857 if (this.removeEventListener) { 858 for (var i = types.length; i;) { 859 this.removeEventListener(types[--i], handler, false); 860 } 861 } else { 862 this.onmousewheel = null; 863 } 864 } 865 }; 866 867 $.fn.extend({ 868 mousewheel: function (fn) { 869 return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel"); 870 }, 871 872 unmousewheel: function (fn) { 873 return this.unbind("mousewheel", fn); 874 } 875 }); 876 877 878 function handler(event) { 879 var orgEvent = event || window.event, args = [].slice.call(arguments, 1), delta = 0, returnValue = true, deltaX = 0, deltaY = 0; 880 event = $.event.fix(orgEvent); 881 event.type = "mousewheel"; 882 883 // Old school scrollwheel delta 884 if (orgEvent.wheelDelta) { 885 delta = orgEvent.wheelDelta / 120; 886 } 887 if (orgEvent.detail) { 888 delta = -orgEvent.detail / 3; 889 } 890 891 // New school multidimensional scroll (touchpads) deltas 892 deltaY = delta; 893 894 // Gecko 895 if (orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS) { 896 deltaY = 0; 897 deltaX = delta; 898 } 899 900 // Webkit 901 if (orgEvent.wheelDeltaY !== undefined) { 902 deltaY = orgEvent.wheelDeltaY / 120; 903 } 904 if (orgEvent.wheelDeltaX !== undefined) { 905 deltaX = orgEvent.wheelDeltaX / 120; 906 } 907 908 // Add event and delta to the front of the arguments 909 args.unshift(event, delta, deltaX, deltaY); 910 911 return ($.event.dispatch || $.event.handle).apply(this, args); 912 } 913 914})(jQuery); 915; 916/** 917 * @file 918 * JQuery Custom Scrollbar initialisation. 919 */ 920 921(function ($) { 922 Drupal.behaviors.jQueryCustomScrollbar = { 923 attach: function (context, settings) { 924 $(settings.jqueryCustomScrollbar.elements).each(function() { 925 // Apply css skins. 926 $(this).addClass(settings.jqueryCustomScrollbar.skin); 927 // Apply scrollbars. 928 $(this).customScrollbar(); 929 }); 930 } 931 }; 932}(jQuery)); 933; 934(function ($) { 935 936/** 937 * Provides Ajax page updating via jQuery $.ajax (Asynchronous JavaScript and XML). 938 * 939 * Ajax is a method of making a request via JavaScript while viewing an HTML 940 * page. The request returns an array of commands encoded in JSON, which is 941 * then executed to make any changes that are necessary to the page. 942 * 943 * Drupal uses this file to enhance form elements with #ajax['path'] and 944 * #ajax['wrapper'] properties. If set, this file will automatically be included 945 * to provide Ajax capabilities. 946 */ 947 948Drupal.ajax = Drupal.ajax || {}; 949 950Drupal.settings.urlIsAjaxTrusted = Drupal.settings.urlIsAjaxTrusted || {}; 951 952/** 953 * Attaches the Ajax behavior to each Ajax form element. 954 */ 955Drupal.behaviors.AJAX = { 956 attach: function (context, settings) { 957 // Load all Ajax behaviors specified in the settings. 958 for (var base in settings.ajax) { 959 if (!$('#' + base + '.ajax-processed').length) { 960 var element_settings = settings.ajax[base]; 961 962 if (typeof element_settings.selector == 'undefined') { 963 element_settings.selector = '#' + base; 964 } 965 $(element_settings.selector).each(function () { 966 element_settings.element = this; 967 Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); 968 }); 969 970 $('#' + base).addClass('ajax-processed'); 971 } 972 } 973 974 // Bind Ajax behaviors to all items showing the class.
975 $('.use-ajax:not(.ajax-processed)').addClass('ajax-processed').each(function () { 976 var element_settings = {}; 977 // Clicked links look better with the throbber than the progress bar. 978 element_settings.progress = { 'type': 'throbber' }; 979 980 // For anchor tags, these will go to the target of the anchor rather 981 // than the usual location. 982 if ($(this).attr('href')) { 983 element_settings.url = $(this).attr('href'); 984 element_settings.event = 'click'; 985 } 986 var base = $(this).attr('id'); 987 Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); 988 }); 989 990 // This class means to submit the form to the action using Ajax. 991 $('.use-ajax-submit:not(.ajax-processed)').addClass('ajax-processed').each(function () { 992 var element_settings = {}; 993 994 // Ajax submits specified in this manner automatically submit to the 995 // normal form action. 996 element_settings.url = $(this.form).attr('action'); 997 // Form submit button clicks need to tell the form what was clicked so 998 // it gets passed in the POST request. 999 element_settings.setClick = true; 1000 // Form buttons use the 'click' event rather than mousedown. 1001 element_settings.event = 'click'; 1002 // Clicked form buttons look better with the throbber than the progress bar. 1003 element_settings.progress = { 'type': 'throbber' }; 1004 1005 var base = $(this).attr('id'); 1006 Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); 1007 }); 1008 } 1009}; 1010 1011/** 1012 * Ajax object. 1013 * 1014 * All Ajax objects on a page are accessible through the global Drupal.ajax 1015 * object and are keyed by the submit button's ID. You can access them from 1016 * your module's JavaScript file to override properties or functions. 1017 * 1018 * For example, if your Ajax enabled button has the ID 'edit-submit', you can 1019 * redefine the function that is called to insert the new content like this 1020 * (inside a Drupal.behaviors attach block): 1021 * @code 1022 * Drupal.behaviors.myCustomAJAXStuff = { 1023 * attach: function (context, settings) { 1024 * Drupal.ajax['edit-submit'].commands.insert = function (ajax, response, status) { 1025 * new_content = $(response.data); 1026 * $('#my-wrapper').append(new_content); 1027 * alert('New content was appended to #my-wrapper'); 1028 * } 1029 * } 1030 * }; 1031 * @endcode 1032 */ 1033Drupal.ajax = function (base, element, element_settings) { 1034 var defaults = { 1035 url: 'system/ajax', 1036 event: 'mousedown', 1037 keypress: true, 1038 selector: '#' + base, 1039 effect: 'none', 1040 speed: 'none', 1041 method: 'replaceWith', 1042 progress: { 1043 type: 'throbber', 1044 message: Drupal.t('Please wait...') 1045 }, 1046 submit: { 1047 'js': true 1048 } 1049 }; 1050 1051 $.extend(this, defaults, element_settings); 1052 1053 this.element = element; 1054 this.element_settings = element_settings; 1055 1056 // Replacing 'nojs' with 'ajax' in the URL allows for an easy method to let 1057 // the server detect when it needs to degrade gracefully. 1058 // There are five scenarios to check for: 1059 // 1. /nojs/ 1060 // 2. /nojs$ - The end of a URL string. 1061 // 3. /nojs? - Followed by a query (with clean URLs enabled). 1062 // E.g.: path/nojs?destination=foobar 1063 // 4. /nojs& - Followed by a query (without clean URLs enabled). 1064 // E.g.: ?q=path/nojs&destination=foobar 1065 // 5. /nojs# - Followed by a fragment. 1066 // E.g.: path/nojs#myfragment 1067 this.url = element_settings.url.replace(/\/nojs(\/|$|\?|&|#)/g, '/ajax$1'); 1068 // If the 'nojs' version of the URL is trusted, also trust the 'ajax' version. 1069 if (Drupal.settings.urlIsAjaxTrusted[element_settings.url]) { 1070 Drupal.settings.urlIsAjaxTrusted[this.url] = true; 1071 } 1072 1073 this.wrapper = '#' + element_settings.wrapper; 1074 1075 // If there isn't a form, jQuery.ajax() will be used instead, allowing us to 1076 // bind Ajax to links as well. 1077 if (this.element.form) { 1078 this.form = $(this.element.form); 1079 } 1080 1081 // Set the options for the ajaxSubmit function. 1082 // The 'this' variable will not persist inside of the options object. 1083 var ajax = this; 1084 ajax.options = { 1085 url: Drupal.sanitizeAjaxUrl(ajax.url), 1086 data: ajax.submit, 1087 beforeSerialize: function (element_settings, options) { 1088 return ajax.beforeSerialize(element_settings, options); 1089 }, 1090 beforeSubmit: function (form_values, element_settings, options) { 1091 ajax.ajaxing = true; 1092 return ajax.beforeSubmit(form_values, element_settings, options); 1093 }, 1094 beforeSend: function (xmlhttprequest, options) { 1095 ajax.ajaxing = true; 1096 return ajax.beforeSend(xmlhttprequest, options); 1097 }, 1098 success: function (response, status, xmlhttprequest) { 1099 // Sanity check for browser support (object expected). 1100 // When using iFrame uploads, responses must be returned as a string. 1101 if (typeof response == 'string') { 1102 response = $.parseJSON(response); 1103 } 1104 1105 // Prior to invoking the response's commands, verify that they can be 1106 // trusted by checking for a response header. See 1107 // ajax_set_verification_header() for details. 1108 // - Empty responses are harmless so can bypass verification. This avoids 1109 // an alert message for server-generated no-op responses that skip Ajax 1110 // rendering. 1111 // - Ajax objects with trusted URLs (e.g., ones defined server-side via 1112 // #ajax) can bypass header verification. This is especially useful for 1113 // Ajax with multipart forms. Because IFRAME transport is used, the 1114 // response headers cannot be accessed for verification. 1115 if (response !== null && !Drupal.settings.urlIsAjaxTrusted[ajax.url]) { 1116 if (xmlhttprequest.getResponseHeader('X-Drupal-Ajax-Token') !== '1') { 1117 var customMessage = Drupal.t("The response failed verification so will not be processed."); 1118 return ajax.error(xmlhttprequest, ajax.url, customMessage); 1119 } 1120 } 1121 1122 return ajax.success(response, status); 1123 }, 1124 complete: function (xmlhttprequest, status) { 1125 ajax.ajaxing = false;
1126 if (status == 'error' || status == 'parsererror') { 1127 return ajax.error(xmlhttprequest, ajax.url); 1128 } 1129 }, 1130 dataType: 'json', 1131 jsonp: false, 1132 type: 'POST' 1133 }; 1134 1135 // For multipart forms (e.g., file uploads), jQuery Form targets the form 1136 // submission to an iframe instead of using an XHR object. The initial "src" 1137 // of the iframe, prior to the form submission, is set to options.iframeSrc. 1138 // "about:blank" is the semantically correct, standards-compliant, way to 1139 // initialize a blank iframe; however, some old IE versions (possibly only 6) 1140 // incorrectly report a mixed content warning when iframes with an 1141 // "about:blank" src are added to a parent document with an https:// origin. 1142 // jQuery Form works around this by defaulting to "javascript:false" instead, 1143 // but that breaks on Chrome 83, so here we force the semantically correct 1144 // behavior for all browsers except old IE. 1145 // @see https://www.drupal.org/project/drupal/issues/3143016 1146 // @see https://github.com/jquery-form/form/blob/df9cb101b9c9c085c8d75ad980c7ff1cf62063a1/jquery.form.js#L68 1147 // @see https://bugs.chromium.org/p/chromium/issues/detail?id=1084874 1148 // @see https://html.spec.whatwg.org/multipage/browsers.html#creating-browsing-contexts 1149 // @see https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy 1150 if (navigator.userAgent.indexOf("MSIE") === -1) { 1151 ajax.options.iframeSrc = 'about:blank'; 1152 } 1153 1154 // Bind the ajaxSubmit function to the element event. 1155 $(ajax.element).bind(element_settings.event, function (event) { 1156 if (!Drupal.settings.urlIsAjaxTrusted[ajax.url] && !Drupal.urlIsLocal(ajax.url)) { 1157 throw new Error(Drupal.t('The callback URL is not local and not trusted: !url', {'!url': ajax.url})); 1158 } 1159 return ajax.eventResponse(this, event); 1160 }); 1161 1162 // If necessary, enable keyboard submission so that Ajax behaviors 1163 // can be triggered through keyboard input as well as e.g. a mousedown 1164 // action. 1165 if (element_settings.keypress) { 1166 $(ajax.element).keypress(function (event) { 1167 return ajax.keypressResponse(this, event); 1168 }); 1169 } 1170 1171 // If necessary, prevent the browser default action of an additional event. 1172 // For example, prevent the browser default action of a click, even if the 1173 // AJAX behavior binds to mousedown. 1174 if (element_settings.prevent) { 1175 $(ajax.element).bind(element_settings.prevent, false); 1176 } 1177}; 1178 1179/** 1180 * Handle a key press. 1181 * 1182 * The Ajax object will, if instructed, bind to a key press response. This 1183 * will test to see if the key press is valid to trigger this event and 1184 * if it is, trigger it for us and prevent other keypresses from triggering. 1185 * In this case we're handling RETURN and SPACEBAR keypresses (event codes 13 1186 * and 32. RETURN is often used to submit a form when in a textfield, and 1187 * SPACE is often used to activate an element without submitting. 1188 */ 1189Drupal.ajax.prototype.keypressResponse = function (element, event) { 1190 // Create a synonym for this to reduce code confusion. 1191 var ajax = this; 1192 1193 // Detect enter key and space bar and allow the standard response for them, 1194 // except for form elements of type 'text' and 'textarea', where the 1195 // spacebar activation causes inappropriate activation if #ajax['keypress'] is 1196 // TRUE. On a text-type widget a space should always be a space. 1197 if (event.which == 13 || (event.which == 32 && element.type != 'text' && element.type != 'textarea')) { 1198 $(ajax.element_settings.element).trigger(ajax.element_settings.event); 1199 return false; 1200 } 1201}; 1202 1203/** 1204 * Handle an event that triggers an Ajax response. 1205 * 1206 * When an event that triggers an Ajax response happens, this method will 1207 * perform the actual Ajax call. It is bound to the event using 1208 * bind() in the constructor, and it uses the options specified on the 1209 * ajax object. 1210 */ 1211Drupal.ajax.prototype.eventResponse = function (element, event) { 1212 // Create a synonym for this to reduce code confusion. 1213 var ajax = this; 1214 1215 // Do not perform another ajax command if one is already in progress. 1216 if (ajax.ajaxing) { 1217 return false; 1218 } 1219 1220 try { 1221 if (ajax.form) { 1222 // If setClick is set, we must set this to ensure that the button's 1223 // value is passed. 1224 if (ajax.setClick) { 1225 // Mark the clicked button. 'form.clk' is a special variable for 1226 // ajaxSubmit that tells the system which element got clicked to 1227 // trigger the submit. Without it there would be no 'op' or
1228 // equivalent. 1229 element.form.clk = element; 1230 } 1231 1232 ajax.form.ajaxSubmit(ajax.options); 1233 } 1234 else { 1235 ajax.beforeSerialize(ajax.element, ajax.options); 1236 $.ajax(ajax.options); 1237 } 1238 } 1239 catch (e) { 1240 // Unset the ajax.ajaxing flag here because it won't be unset during 1241 // the complete response. 1242 ajax.ajaxing = false; 1243 alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message); 1244 } 1245 1246 // For radio/checkbox, allow the default event. On IE, this means letting 1247 // it actually check the box. 1248 if (typeof element.type != 'undefined' && (element.type == 'checkbox' || element.type == 'radio')) { 1249 return true; 1250 } 1251 else { 1252 return false; 1253 } 1254 1255}; 1256 1257/** 1258 * Handler for the form serialization. 1259 * 1260 * Runs before the beforeSend() handler (see below), and unlike that one, runs 1261 * before field data is collected. 1262 */ 1263Drupal.ajax.prototype.beforeSerialize = function (element, options) { 1264 // Allow detaching behaviors to update field values before collecting them. 1265 // This is only needed when field values are added to the POST data, so only 1266 // when there is a form such that this.form.ajaxSubmit() is used instead of 1267 // $.ajax(). When there is no form and $.ajax() is used, beforeSerialize() 1268 // isn't called, but don't rely on that: explicitly check this.form. 1269 if (this.form) { 1270 var settings = this.settings || Drupal.settings; 1271 Drupal.detachBehaviors(this.form, settings, 'serialize'); 1272 } 1273 1274 // Prevent duplicate HTML ids in the returned markup. 1275 // @see drupal_html_id() 1276 options.data['ajax_html_ids[]'] = []; 1277 $('[id]').each(function () { 1278 options.data['ajax_html_ids[]'].push(this.id); 1279 }); 1280 1281 // Allow Drupal to return new JavaScript and CSS files to load without 1282 // returning the ones already loaded. 1283 // @see ajax_base_page_theme() 1284 // @see drupal_get_css() 1285 // @see drupal_get_js() 1286 options.data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme; 1287 options.data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token; 1288 for (var key in Drupal.settings.ajaxPageState.css) { 1289 options.data['ajax_page_state[css][' + key + ']'] = 1; 1290 } 1291 for (var key in Drupal.settings.ajaxPageState.js) { 1292 options.data['ajax_page_state[js][' + key + ']'] = 1; 1293 } 1294}; 1295 1296/** 1297 * Modify form values prior to form submission. 1298 */ 1299Drupal.ajax.prototype.beforeSubmit = function (form_values, element, options) { 1300 // This function is left empty to make it simple to override for modules 1301 // that wish to add functionality here. 1302}; 1303 1304/** 1305 * Prepare the Ajax request before it is sent. 1306 */ 1307Drupal.ajax.prototype.beforeSend = function (xmlhttprequest, options) { 1308 // For forms without file inputs, the jQuery Form plugin serializes the form 1309 // values, and then calls jQuery's $.ajax() function, which invokes this 1310 // handler. In this circumstance, options.extraData is never used. For forms 1311 // with file inputs, the jQuery Form plugin uses the browser's normal form 1312 // submission mechanism, but captures the response in a hidden IFRAME. In this 1313 // circumstance, it calls this handler first, and then appends hidden fields 1314 // to the form to submit the values in options.extraData. There is no simple 1315 // way to know which submission mechanism will be used, so we add to extraData 1316 // regardless, and allow it to be ignored in the former case. 1317 if (this.form) { 1318 options.extraData = options.extraData || {}; 1319 1320 // Let the server know when the IFRAME submission mechanism is used. The 1321 // server can use this information to wrap the JSON response in a TEXTAREA, 1322 // as per http://jquery.malsup.com/form/#file-upload. 1323 options.extraData.ajax_iframe_upload = '1'; 1324 1325 // The triggering element is about to be disabled (see below), but if it 1326 // contains a value (e.g., a checkbox, textfield, select, etc.), ensure that 1327 // value is included in the submission. As per above, submissions that use 1328 // $.ajax() are already serialized prior to the element being disabled, so 1329 // this is only needed for IFRAME submissions. 1330 var v = $.fieldValue(this.element); 1331 if (v !== null) { 1332 options.extraData[this.element.name] = Drupal.checkPlain(v); 1333 } 1334 } 1335 1336 // Disable the element that received the change to prevent user interface 1337 // interaction while the Ajax request is in progress. ajax.ajaxing prevents 1338 // the element from triggering a new request, but does not prevent the user 1339 // from changing its value. 1340 $(this.element).addClass('progress-disabled').attr('disabled', true); 1341 1342 // Insert progressbar or throbber. 1343 if (this.progress.type == 'bar') { 1344 var progressBar = new Drupal.progressBar('ajax-progress-' + this.element.i
1344d, eval(this.progress.update_callback), this.progress.method, eval(this.progress.error_callback)); 1345 if (this.progress.message) { 1346 progressBar.setProgress(-1, this.progress.message); 1347 } 1348 if (this.progress.url) { 1349 progressBar.startMonitoring(this.progress.url, this.progress.interval || 1500); 1350 } 1351 this.progress.element = $(progressBar.element).addClass('ajax-progress ajax-progress-bar'); 1352 this.progress.object = progressBar; 1353 $(this.element).after(this.progress.element); 1354 } 1355 else if (this.progress.type == 'throbber') { 1356 this.progress.element = $('<div class="ajax-progress ajax-progress-throbber"><div class="throbber"> </div></div>'); 1357 if (this.progress.message) { 1358 $('.throbber', this.progress.element).after('<div class="message">' + this.progress.message + '</div>'); 1359 } 1360 $(this.element).after(this.progress.element); 1361 } 1362}; 1363 1364/** 1365 * Handler for the form redirection completion. 1366 */ 1367Drupal.ajax.prototype.success = function (response, status) { 1368 // Remove the progress element. 1369 if (this.progress.element) { 1370 $(this.progress.element).remove(); 1371 } 1372 if (this.progress.object) { 1373 this.progress.object.stopMonitoring(); 1374 } 1375 $(this.element).removeClass('progress-disabled').removeAttr('disabled'); 1376 1377 Drupal.freezeHeight(); 1378 1379 for (var i in response) { 1380 if (response.hasOwnProperty(i) && response[i]['command'] && this.commands[response[i]['command']]) { 1381 this.commands[response[i]['command']](this, response[i], status); 1382 } 1383 } 1384 1385 // Reattach behaviors, if they were detached in beforeSerialize(). The 1386 // attachBehaviors() called on the new content from processing the response 1387 // commands is not sufficient, because behaviors from the entire form need 1388 // to be reattached. 1389 if (this.form) { 1390 var settings = this.settings || Drupal.settings; 1391 Drupal.attachBehaviors(this.form, settings); 1392 } 1393 1394 Drupal.unfreezeHeight(); 1395 1396 // Remove any response-specific settings so they don't get used on the next 1397 // call by mistake. 1398 this.settings = null; 1399}; 1400 1401/** 1402 * Build an effect object which tells us how to apply the effect when adding new HTML. 1403 */ 1404Drupal.ajax.prototype.getEffect = function (response) { 1405 var type = response.effect || this.effect; 1406 var speed = response.speed || this.speed; 1407 1408 var effect = {}; 1409 if (type == 'none') { 1410 effect.showEffect = 'show'; 1411 effect.hideEffect = 'hide'; 1412 effect.showSpeed = ''; 1413 } 1414 else if (type == 'fade') { 1415 effect.showEffect = 'fadeIn'; 1416 effect.hideEffect = 'fadeOut'; 1417 effect.showSpeed = speed; 1418 } 1419 else { 1420 effect.showEffect = type + 'Toggle'; 1421 effect.hideEffect = type + 'Toggle'; 1422 effect.showSpeed = speed; 1423 } 1424 1425 return effect; 1426}; 1427 1428/** 1429 * Handler for the form redirection error. 1430 */ 1431Drupal.ajax.prototype.error = function (xmlhttprequest, uri, customMessage) { 1432 Drupal.displayAjaxError(Drupal.ajaxError(xmlhttprequest, uri, customMessage)); 1433 // Remove the progress element. 1434 if (this.progress.element) { 1435 $(this.progress.element).remove(); 1436 } 1437 if (this.progress.object) { 1438 this.progress.object.stopMonitoring(); 1439 } 1440 // Undo hide. 1441 $(this.wrapper).show(); 1442 // Re-enable the element. 1443 $(this.element).removeClass('progress-disabled').removeAttr('disabled'); 1444 // Reattach behaviors, if they were detached in beforeSerialize(). 1445 if (this.form) { 1446 var settings = this.settings || Drupal.settings; 1447 Drupal.attachBehaviors(this.form, settings); 1448 } 1449}; 1450 1451/** 1452 * Provide a series of commands that the server can request the client perform. 1453 */ 1454Drupal.ajax.prototype.commands = { 1455 /** 1456 * Command to insert new content into the DOM. 1457 */ 1458 insert: function (ajax, response, status) { 1459 // Get information from the response. If it is not there, default to 1460 // our presets. 1461 var wrapper = response.selector ? $(response.selector) : $(ajax.wrapper); 1462 var method = response.method || ajax.method; 1463 var effect = ajax.getEffect(response); 1464 1465 // We don't know what response.data contains: it might be a string of text 1466 // without HTML, so don't rely on jQuery correctly iterpreting 1467 // $(response.data) as new HTML rather than a CSS selector. Also, if 1468 // response.data contains top-level text nodes, they get lost with either 1469 // $(response.data) or $('<div></div>').replaceWith(response.data). 1470 var new_content_wrapped = $('<div></div>').html(response.data); 1471 var new_content = new_content_wrapped.contents(); 1472 1473 // For legacy reasons, the effects processing code assumes that new_content 1474 // consists of a single top-level element. Also, it has not been 1475 // sufficiently tested whether attachBehaviors() can be successfully called 1476 // with a context object that includes top-level text nodes. However, to 1477 // give developers full control of the HTML appearing in the page, and to 1478 // enable Ajax content to be inserted in places where DIV elements are not 1479 // allowed (e.g., within TABLE, TR, and SPAN parents), we check if the new 1480 // content satisfies the requirement of a single top-level element, and 1481 // only use the container DIV created above when it doesn't. For more 1482 // information, please see http://drupal.org/node/736066. 1483 if (new_content.length != 1 || new_content.get(0).nodeType != 1) { 1484 new_content = new_content_wrapped; 1485 } 1486 1487 // If removing content from the wrapper, detach behaviors first. 1488 switch (method) { 1489 case 'html': 1490 case 'replaceWith': 1491 case 'replaceAll': 1492 case 'empty': 1493 case 'remove': 1494 var settings = response.settings || ajax.settings || Drupal.settings; 1495 Drupal.detachBehaviors(wrapper, settings); 1496 } 1497 1498 // Add the new content to the page. 1499 wrapper[method](new_content); 1500 1501 // Immediately hide the new content if we're using any effects. 1502 if (effect.showEffect != 'show') { 1503 new_content.hide(); 1504 } 1505 1506 // Determine which effect to use and what content will receive the 1507 // effect, then show the new content. 1508 if ($('.ajax-new-content', new_content).length > 0) { 1509 $('.ajax-new-content', new_content).hide(); 1510 new_content.show(); 1511 $('.ajax-new-content', new_content)[effect.showEffect](effect.showSpeed); 1512 } 1513 else if (effect.showEffect != 'show') { 1514 new_content[effect.showEffect](effect.showSpeed); 1515 } 1516 1517 // Attach all JavaScript behaviors to the new content, if it was successfully 1518 // added to the page, this if statement allows #ajax['wrapper'] to be 1519 // optional. 1520 if (new_content.parents('html').length > 0) { 1521 // Apply any settings from the returned JSON if available. 1522 var settings = response.settings || ajax.settings || Drupal.settings; 1523 Drupal.attachBehaviors(new_content, settings); 1524 } 1525 }, 1526 1527 /** 1528 * Command to remove a chunk from the page. 1529 */ 1530 remove: function (ajax, response, status) { 1531 var settings = response.settings || ajax.settings || Drupal.settings; 1532 Drupal.detachBehaviors($(response.selector), settings); 1533 $(response.selector).remove(); 1534 }, 1535 1536 /** 1537 * Command to mark a chunk changed. 1538 */ 1539 changed: function (ajax, response, status) { 1540 if (!$(response.selector).hasClass('ajax-changed')) { 1541 $(response.selector).addClass('ajax-changed'); 1542 if (response.asterisk) { 1543 $(response.selector).find(response.asterisk).append(' <span class="ajax-changed">*</span> '); 1544 } 1545 } 1546 }, 1547 1548 /** 1549 * Command to provide an alert. 1550 */ 1551 alert: function (ajax, response, status) { 1552 alert(response.text, response.title); 1553 }, 1554 1555 /** 1556 * Command to provide the jQuery css() function. 1557 */ 1558 css: function (ajax, response, status) { 1559 $(response.selector).css(response.argument); 1560 }, 1561 1562 /** 1563 * Command to set the settings that will be used for other commands in this response. 1564 */ 1565 settings: function (ajax, response, status) { 1566 if (response.merge) { 1567 $.extend(true, Drupal.settings, response.settings); 1568 } 1569 else { 1570 ajax.settings = response.settings; 1571 } 1572 }, 1573 1574 /** 1575 * Command to attach data using jQuery's data API. 1576 */ 1577 data: function (ajax, response, status) { 1578 $(response.selector).data(response.name, response.value); 1579 }, 1580 1581 /** 1582 * Command to apply a jQuery method. 1583 */ 1584 invoke: function (ajax, response, status) { 1585 var $element = $(response.selector); 1586 $element[response.method].apply($element, response.arguments); 1587 }, 1588 1589 /** 1590 * Command to restripe a table. 1591 */ 1592 restripe: function (ajax, response, status) { 1593 // :even and :odd are reversed because jQuery counts from 0 and 1594 // we count from 1, so we're out of sync. 1595 // Match immediate children of the parent element to allow nesting. 1596 $('> tbody > tr:visible, > tr:visible', $(response.selector)) 1597 .removeClass('odd even') 1598 .filter(':even').addClass('odd').end() 1599 .filter(':odd').addClass('even'); 1600 }, 1601 1602 /** 1603 * Command to add css. 1604 * 1605 * Uses the proprietary addImport method if available as browsers which 1606 * support that method ignore @import statements in dynamically added 1607 * stylesheets. 1608 */ 1609 add_css: function (ajax, response, status) { 1610 // Add the styles in the normal way. 1611 $('head').prepend(response.data); 1612 // Add imports in the styles using the addImport method if available. 1613 var match, importMatch = /^@import url\("(.*)"\);$/igm; 1614 if (document.styleSheets[0].addImport && importMatch.test(response.data)) { 1615 importMatch.lastIndex = 0; 1616 while (match = importMatch.exec(response.data)) { 1617 document.styleSheets[0].addImport(match[1]); 1618 } 1619 } 1620 }, 1621 1622 /** 1623 * Command to update a form's build ID. 1624 */ 1625 updateBuildId: function(ajax, response, status) { 1626 $('input[name="form_build_id"][value="' + response['old'] + '"]').val(response['new']); 1627 } 1628}; 1629 1630})(jQuery); 1631; 1632(function (D) { 1633 var beforeSerialize = D.ajax.prototype.beforeSerialize;
1634 D.ajax.prototype.beforeSerialize = function (element, options) { 1635 beforeSerialize.call(this, element, options); 1636 options.data['ajax_page_state[jquery_version]'] = D.settings.ajaxPageState.jquery_version; 1637 } 1638})(Drupal); 1639;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.