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: 2.69 (06-APR-2011) 94 * @requires jQuery v1.3.2 or later 95 * 96 * Examples and documentation at: http://malsup.com/jquery/form/ 97 * Dual licensed under the MIT and GPL licenses: 98 * http://www.opensource.org/licenses/mit-license.php 99 * http://www.gnu.org/licenses/gpl.html 100 */ 101(function(a){function b(){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)}}a.fn.ajaxSubmit=function(c){function r(){function t(){if(!j.aborted){var c=i.contentWindow?i.contentWindow.document:i.contentDocument?i.contentDocument:i.document;if(!c||c.location.href==e.iframeSrc)if(!m)return;i.detachEvent?i.detachEvent("onload",t):i.removeEventListener("load",t,!1);var d=!0;try{if(m)throw"timeout";var f=e.dataType=="xml"||c.XMLDocument||a.isXMLDoc(c);b("isXml="+f);if(!f&&window.opera&&(c.body==null||c.body.innerHTML=="")&&--s){b("requeing onLoad callback, DOM not available"),setTimeout(t,250);return}j.responseText=c.body?c.body.innerHTML:c.documentElement?c.documentElement.innerHTML:null,j.responseXML=c.XMLDocument?c.XMLDocument:c,j.getResponseHeader=function(a){var b={"content-type":e.dataType};return b[a]};var g=/(json|script)/.test(e.dataType);if(g||e.textarea){var l=c.getElementsByTagName("textarea")[0];if(l)j.responseText=l.value;else if(g){var n=c.getElementsByTagName("pre")[0],o=c.getElementsByTagName("body")[0];n?j.responseText=n.textContent:o&&(j.responseText=o.innerHTML)}}else e.dataType=="xml"&&!j.responseXML&&j.responseText!=null&&(j.responseXML=u(j.responseText));q=w(j,e.dataType,e)}catch(p){b("error caught:",p),d=!1,j.error=p,e.error&&e.error.call(e.context,j,"error",p),k&&a.event.trigger("ajaxError",[j,e,p])}j.aborted&&(b("upload aborted"),d=!1),d&&(e.success&&e.success.call(e.context,q,"success",j),k&&a.event.trigger("ajaxSuccess",[j,e])),k&&a.event.trigger("ajaxComplete",[j,e]),k&&!--a.active&&a.event.trigger("ajaxStop"),e.complete&&e.complete.call(e.context,j,d?"success":"error"),setTimeout(function(){h.removeData("form-plugin-onload"),h.remove(),j.responseXML=null},100)}}function p(){var b=l.attr("target"),c=l.attr("action");d.setAttribute("target",f),d.getAttribute("method")!="POST"&&d.setAttribute("method","POST"),d.getAttribute("action")!=e.url&&d.setAttribute("action",e.url),e.skipEncodingOverride||l.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),e.timeout&&setTimeout(function(){m=!0,t()}
101,e.timeout);var g=[];try{if(e.extraData)for(var j in e.extraData)g.push(a('<input type="hidden" name="'+j+'" value="'+e.extraData[j]+'" />').appendTo(d)[0]);h.appendTo("body"),i.attachEvent?i.attachEvent("onload",t):i.addEventListener("load",t,!1),d.submit()}finally{d.setAttribute("action",c),b?d.setAttribute("target",b):l.removeAttr("target"),a(g).remove()}}var d=l[0];if(a(":input[name=submit],:input[id=submit]",d).length)alert('Error: Form elements must not have name or id of "submit".');else{var e=a.extend(!0,{},a.ajaxSettings,c);e.context=e.context||e;var f="jqFormIO"+(new Date).getTime(),g="_"+f,h=a('<iframe id="'+f+'" name="'+f+'" src="'+e.iframeSrc+'" />'),i=h[0];h.css({position:"absolute",top:"-1000px",left:"-1000px"});var j={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(){b("aborting upload...");var c="aborted";this.aborted=1,h.attr("src",e.iframeSrc),j.error=c,e.error&&e.error.call(e.context,j,"error",c),k&&a.event.trigger("ajaxError",[j,e,c]),e.complete&&e.complete.call(e.context,j,"error")}},k=e.global;k&&!(a.active++)&&a.event.trigger("ajaxStart"),k&&a.event.trigger("ajaxSend",[j,e]);if(e.beforeSend&&e.beforeSend.call(e.context,j,e)===!1){e.global&&a.active--;return}if(j.aborted)return;var m=0,n=d.clk;if(n){var o=n.name;o&&!n.disabled&&(e.extraData=e.extraData||{},e.extraData[o]=n.value,n.type=="image"&&(e.extraData[o+".x"]=d.clk_x,e.extraData[o+".y"]=d.clk_y))}e.forceSync?p():setTimeout(p,10);var q,r,s=50,u=a.parseXML||function(a,b){window.ActiveXObject?(b=new ActiveXObject("Microsoft.XMLDOM"),b.async="false",b.loadXML(a)):b=(new DOMParser).parseFromString(a,"text/xml");return b&&b.documentElement&&b.documentElement.nodeName!="parsererror"?b:null},v=a.parseJSON||function(a){return window.eval("("+a+")")},w=function(b,c,d){var e=b.getResponseHeader("content-type")||"",f=c==="xml"||!c&&e.indexOf("xml")>=0,g=f?b.responseXML:b.responseText;f&&g.documentElement.nodeName==="parsererror"&&a.error&&a.error("parsererror"),d&&d.dataFilter&&(g=d.dataFilter(g,c)),typeof g=="string"&&(c==="json"||!c&&e.indexOf("json")>=0?g=v(g):(c==="script"||!c&&e.indexOf("javascript")>=0)&&a.globalEval(g));return g}}}if(!this.length){b("ajaxSubmit: skipping submit process - no element selected");return this}typeof c=="function"&&(c={success:c});var d=this.attr("action"),e=typeof d=="string"?a.trim(d):"";e&&(e=(e.match(/^([^#]+)/)||[])[1]),e=e||window.location.href||"",c=a.extend(!0,{url:e,success:a.ajaxSettings.success,type:this[0].getAttribute("method")||"GET",iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},c);var f={};this.trigger("form-pre-serialize",[this,c,f]);if(f.veto){b("ajaxSubmit: submit vetoed via form-pre-serialize trigger");return this}if(c.beforeSerialize&&c.beforeSerialize(this,c)===!1){b("ajaxSubmit: submit aborted via beforeSerialize callback");return this}var g,h,i=this.formToArray(c.semantic);if(c.data){c.extraData=c.data;for(g in c.data)if(c.data[g]instanceof Array)for(var j in c.data[g])i.push({name:g,value:c.data[g][j]});else h=c.data[g],h=a.isFunction(h)?h():h,i.push({name:g,value:h})}if(c.beforeSubmit&&c.beforeSubmit(i,this,c)===!1){b("ajaxSubmit: submit aborted via beforeSubmit callback");return this}this.trigger("form-submit-validate",[i,this,c,f]);if(f.veto){b("ajaxSubmit: submit vetoed via form-submit-validate trigger");return this}var k=a.param(i);c.type.toUpperCase()=="GET"?(c.url+=(c.url.indexOf("?")>=0?"&":"?")+k,c.data=null):c.data=k;var l=this,m=[];c.resetForm&&m.push(function(){l.resetForm()}),c.clearForm&&m.push(function(){l.clearForm()});if(!c.dataType&&c.target){var n=c.success||function(){};m.push(function(b){var d=c.replaceTarget?"replaceWith":"html";a(c.target)[d](b).each(n,arguments)})}else c.success&&m.push(c.success);c.success=function(a,b,d){var e=c.context||c;for(var f=0,g=m.length;f<g;f++)m[f].apply(e,[a,b,d||l,l])};var o=a("input:file",this).length>0,p="multipart/form-data",q=l.attr("enctype")==p||l.attr("encoding")==p;c.iframe!==!1&&(o||c.iframe||q)?c.closeKeepAlive?a.get(c.closeKeepAlive,r):r():a.ajax(c),this.trigger("form-submit-notify",[this,c]);return this},a.fn.ajaxForm=function(c){if(this.length===0){var d={s:this.selector,c:this.context};if(!a.isReady&&d.s){b("DOM not ready, queuing ajaxForm"),a(function(){a(d.s,d.c).ajaxForm(c)});return this}b("terminating; zero elements found by selector"+(a.isReady?"":" (DOM not ready)"));return this}return this.ajaxFormUnbind().bind("submit.form-plugin",function(b){b.isDefaultPrevented()||(b.preventDefault(),a(this).ajaxSubmit(c))}).bind("click.form-plugin",function(b){var c=b.target,d=a(c);if(!d.is(":submit,input:image")){var e=d.closest(":submit");
101if(e.length==0)return;c=e[0]}var f=this;f.clk=c;if(c.type=="image")if(b.offsetX!=undefined)f.clk_x=b.offsetX,f.clk_y=b.offsetY;else if(typeof a.fn.offset=="function"){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)})},a.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")},a.fn.formToArray=function(b){var c=[];if(this.length===0)return c;var d=this[0],e=b?d.getElementsByTagName("*"):d.elements;if(!e)return c;var f,g,h,i,j,k,l;for(f=0,k=e.length;f<k;f++){j=e[f],h=j.name;if(!h)continue;if(b&&d.clk&&j.type=="image"){!j.disabled&&d.clk==j&&(c.push({name:h,value:a(j).val()}),c.push({name:h+".x",value:d.clk_x},{name:h+".y",value:d.clk_y}));continue}i=a.fieldValue(j,!0);if(i&&i.constructor==Array)for(g=0,l=i.length;g<l;g++)c.push({name:h,value:i[g]});else i!==null&&typeof i!="undefined"&&c.push({name:h,value:i})}if(!b&&d.clk){var m=a(d.clk),n=m[0];h=n.name,h&&!n.disabled&&n.type=="image"&&(c.push({name:h,value:m.val()}),c.push({name:h+".x",value:d.clk_x},{name:h+".y",value:d.clk_y}))}return c},a.fn.formSerialize=function(b){return a.param(this.formToArray(b))},a.fn.fieldSerialize=function(b){var c=[];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 e!==null&&typeof e!="undefined"&&c.push({name:this.name,value:e})}});return 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);if(g===null||typeof g=="undefined"||g.constructor==Array&&!g.length)continue;
101g.constructor==Array?a.merge(c,g):c.push(g)}return c},a.fieldValue=function(b,c){var d=b.name,e=b.type,f=b.tagName.toLowerCase();c===undefined&&(c=!0);if(c&&(!d||b.disabled||e=="reset"||e=="button"||(e=="checkbox"||e=="radio")&&!b.checked||(e=="submit"||e=="image")&&b.form&&b.form.clk!=b||f=="select"&&b.selectedIndex==-1))return null;if(f=="select"){var g=b.selectedIndex;if(g<0)return null;var h=[],i=b.options,j=e=="select-one",k=j?g+1:i.length;for(var l=j?g:0;l<k;l++){var m=i[l];if(m.selected){var n=m.value;n||(n=m.attributes&&m.attributes.value&&!m.attributes.value.specified?m.text:m.value);if(j)return n;h.push(n)}}return h}return a(b).val()},a.fn.clearForm=function(){return this.each(function(){a("input,select,textarea",this).clearFields()})},a.fn.clearFields=a.fn.clearInputs=function(){return this.each(function(){var a=this.type,b=this.tagName.toLowerCase();a=="text"||a=="password"||b=="textarea"?this.value="":a=="checkbox"||a=="radio"?this.checked=!1:b=="select"&&(this.selectedIndex=-1)})},a.fn.resetForm=function(){return this.each(function(){(typeof this.reset=="function"||typeof this.reset=="object"&&!this.reset.nodeType)&&this.reset()})},a.fn.enable=function(a){a===undefined&&(a=!0);return this.each(function(){this.disabled=!a})},a.fn.selected=function(b){b===undefined&&(b=!0);return this.each(function(){var c=this.type;if(c=="checkbox"||c=="radio")this.checked=b;else if(this.tagName.toLowerCase()=="option"){var d=a(this).parent("select");b&&d[0]&&d[0].type=="select-one"&&d.find("option").selected(!1),this.selected=b}})}})(jQuery); 102(function ($) { 103 104/** 105 * Provides Ajax page updating via jQuery $.ajax (Asynchronous JavaScript and XML). 106 * 107 * Ajax is a method of making a request via JavaScript while viewing an HTML 108 * page. The request returns an array of commands encoded in JSON, which is 109 * then executed to make any changes that are necessary to the page. 110 * 111 * Drupal uses this file to enhance form elements with #ajax['path'] and 112 * #ajax['wrapper'] properties. If set, this file will automatically be included 113 * to provide Ajax capabilities. 114 */ 115 116Drupal.ajax = Drupal.ajax || {}; 117 118Drupal.settings.urlIsAjaxTrusted = Drupal.settings.urlIsAjaxTrusted || {}; 119 120/** 121 * Attaches the Ajax behavior to each Ajax form element. 122 */ 123Drupal.behaviors.AJAX = { 124 attach: function (context, settings) { 125 // Load all Ajax behaviors specified in the settings. 126 for (var base in settings.ajax) { 127 if (!$('#' + base + '.ajax-processed').length) { 128 var element_settings = settings.ajax[base]; 129 130 if (typeof element_settings.selector == 'undefined') { 131 element_settings.selector = '#' + base; 132 } 133 $(element_settings.selector).each(function () { 134 element_settings.element = this; 135 Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); 136 }); 137 138 $('#' + base).addClass('ajax-processed'); 139 } 140 } 141 142 // Bind Ajax behaviors to all items showing the class. 143 $('.use-ajax:not(.ajax-processed)').addClass('ajax-processed').each(function () { 144 var element_settings = {}; 145 // Clicked links look better with the throbber than the progress bar. 146 element_settings.progress = { 'type': 'throbber' }; 147 148 // For anchor tags, these will go to the target of the anchor rather 149 // than the usual location. 150 if ($(this).attr('href')) { 151 element_settings.url = $(this).attr('href'); 152 element_settings.event = 'click'; 153 } 154 var base = $(this).attr('id'); 155 Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); 156 }); 157 158 // This class means to submit the form to the action using Ajax. 159 $('.use-ajax-submit:not(.ajax-processed)').addClass('ajax-processed').each(function () { 160 var element_settings = {}; 161 162 // Ajax submits specified in this manner automatically submit to the 163 // normal form action. 164 element_settings.url = $(this.form).attr('action'); 165 // Form submit button clicks need to tell the form what was clicked so 166 // it gets passed in the POST request. 167 element_settings.setClick = true; 168 // Form buttons use the 'click' event rather than mousedown. 169 element_settings.event = 'click'; 170 // Clicked form buttons look better with the throbber than the progress bar. 171 element_settings.progress = { 'type': 'throbber' }; 172 173 var base = $(this).attr('id'); 174 Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); 175 }); 176 } 177}; 178 179/** 180 * Ajax object. 181 * 182 * All Ajax objects on a page are accessible through the global Drupal.ajax 183 * object and are keyed by the submit button's ID. You can access them from 184 * your module's JavaScript file to override properties or functions. 185 * 186 * For example, if your Ajax enabled button has the ID 'edit-submit', you can 187 * redefine the function that is called to insert the new content like this 188 * (inside a Drupal.behaviors attach block): 189 * @code 190 * Drupal.behaviors.myCustomAJAXStuff = { 191 * attach: function (context, settings) { 192 * Drupal.ajax['edit-submit'].commands.insert = function (ajax, response, status) { 193 * new_content = $(response.data); 194 * $('#my-wrapper').append(new_content); 195 * alert('New content was appended to #my-wrapper'); 196 * } 197 * } 198 * }; 199 * @endcode 200 */ 201Drupal.ajax = function (base, element, element_settings) { 202 var defaults = { 203 url: 'system/ajax', 204 event: 'mousedown', 205 keypress: true, 206 selector: '#' + base, 207 effect: 'none', 208 speed: 'none', 209 method: 'replaceWith', 210 progress: { 211 type: 'throbber', 212 message: Drupal.t('Please wait...') 213 }, 214 submit: { 215 'js': true 216 } 217 }; 218 219 $.extend(this, defaults, element_settings); 220 221 this.element = element; 222 this.element_settings = element_settings; 223 224 // Replacing 'nojs' with 'ajax' in the URL allows for an easy method to let 225 // the server detect when it needs to degrade gracefully. 226 // There are five scenarios to check for: 227 // 1. /nojs/ 228 // 2. /nojs$ - The end of a URL string. 229 // 3. /nojs? - Followed by a query (with clean URLs enabled). 230 // E.g.: path/nojs?destination=foobar 231 // 4. /nojs& - Followed by a query (without clean URLs enabled). 232 // E.g.: ?q=path/nojs&destination=foobar 233 // 5. /nojs# - Followed by a fragment. 234 // E.g.: path/nojs#myfragment 235 this.url = element_settings.url.replace(/\/nojs(\/|$|\?|&|#)/g, '/ajax$1'); 236 // If the 'nojs' version of the URL is trusted, also trust the 'ajax' version. 237 if (Drupal.settings.urlIsAjaxTrusted[element_settings.url]) { 238 Drupal.settings.urlIsAjaxTrusted[this.url] = true; 239 } 240 241 this.wrapper = '#' + element_settings.wrapper; 242 243 // If there isn't a form, jQuery.ajax() will be used instead, allowing us to 244 // bind Ajax to links as well. 245 if (this.element.form) { 246 this.form = $(this.element.form); 247 } 248 249 // Set the options for the ajaxSubmit function. 250 // The 'this' variable will not persist inside of the options object. 251 var ajax = this; 252 ajax.options = { 253 url: ajax.url, 254 data: ajax.submit, 255 beforeSerialize: function (element_settings, options) { 256 return ajax.beforeSerialize(element_settings, options); 257 }, 258 beforeSubmit: function (form_values, element_settings, options) { 259 ajax.ajaxing = true; 260 return ajax.beforeSubmit(form_values, element_settings, options); 261 }, 262 beforeSend: function (xmlhttprequest, options) { 263 ajax.ajaxing = true; 264 return ajax.beforeSend(xmlhttprequest, options); 265 }, 266 success: function (response, status, xmlhttprequest) { 267 // Sanity check for browser support (object expected). 268 // When using iFrame uploads, responses must be returned as a string. 269 if (typeof response == 'string') { 270 response = $.parseJSON(response); 271 } 272 273 // Prior to invoking the response's commands, verify that they can be 274 // trusted by checking for a response header. See 275 // ajax_set_verification_header() for details. 276 // - Empty responses are harmless so can bypass verification. This avoids 277 // an alert message for server-generated no-op responses that skip Ajax 278 // rendering. 279 // - Ajax objects with trusted URLs (e.g., ones defined server-side via 280 // #ajax) can bypass header verification. This is especially useful for 281 // Ajax with multipart forms. Because IFRAME transport is used, the 282 // response headers cannot be accessed for verification. 283 if (response !== null && !Drupal.settings.urlIsAjaxTrusted[ajax.url]) { 284 if (xmlhttprequest.getResponseHeader('X-Drupal-Ajax-Token') !== '1') { 285 var customMessage = Drupal.t("The response failed verification so will not be processed."); 286 return ajax.error(xmlhttprequest, ajax.url, customMessage); 287 } 288 } 289 290 return ajax.success(response, status); 291 }, 292 complete: function (xmlhttprequest, status) { 293 ajax.ajaxing = false;
294 if (status == 'error' || status == 'parsererror') { 295 return ajax.error(xmlhttprequest, ajax.url); 296 } 297 }, 298 dataType: 'json', 299 type: 'POST' 300 }; 301 302 // Bind the ajaxSubmit function to the element event. 303 $(ajax.element).bind(element_settings.event, function (event) { 304 if (!Drupal.settings.urlIsAjaxTrusted[ajax.url] && !Drupal.urlIsLocal(ajax.url)) { 305 throw new Error(Drupal.t('The callback URL is not local and not trusted: !url', {'!url': ajax.url})); 306 } 307 return ajax.eventResponse(this, event); 308 }); 309 310 // If necessary, enable keyboard submission so that Ajax behaviors 311 // can be triggered through keyboard input as well as e.g. a mousedown 312 // action. 313 if (element_settings.keypress) { 314 $(ajax.element).keypress(function (event) { 315 return ajax.keypressResponse(this, event); 316 }); 317 } 318 319 // If necessary, prevent the browser default action of an additional event. 320 // For example, prevent the browser default action of a click, even if the 321 // AJAX behavior binds to mousedown. 322 if (element_settings.prevent) { 323 $(ajax.element).bind(element_settings.prevent, false); 324 } 325}; 326 327/** 328 * Handle a key press. 329 * 330 * The Ajax object will, if instructed, bind to a key press response. This 331 * will test to see if the key press is valid to trigger this event and 332 * if it is, trigger it for us and prevent other keypresses from triggering. 333 * In this case we're handling RETURN and SPACEBAR keypresses (event codes 13 334 * and 32. RETURN is often used to submit a form when in a textfield, and 335 * SPACE is often used to activate an element without submitting. 336 */ 337Drupal.ajax.prototype.keypressResponse = function (element, event) { 338 // Create a synonym for this to reduce code confusion. 339 var ajax = this; 340 341 // Detect enter key and space bar and allow the standard response for them, 342 // except for form elements of type 'text' and 'textarea', where the 343 // spacebar activation causes inappropriate activation if #ajax['keypress'] is 344 // TRUE. On a text-type widget a space should always be a space. 345 if (event.which == 13 || (event.which == 32 && element.type != 'text' && element.type != 'textarea')) { 346 $(ajax.element_settings.element).trigger(ajax.element_settings.event); 347 return false; 348 } 349}; 350 351/** 352 * Handle an event that triggers an Ajax response. 353 * 354 * When an event that triggers an Ajax response happens, this method will 355 * perform the actual Ajax call. It is bound to the event using 356 * bind() in the constructor, and it uses the options specified on the 357 * ajax object. 358 */ 359Drupal.ajax.prototype.eventResponse = function (element, event) { 360 // Create a synonym for this to reduce code confusion. 361 var ajax = this; 362 363 // Do not perform another ajax command if one is already in progress. 364 if (ajax.ajaxing) { 365 return false; 366 } 367 368 try { 369 if (ajax.form) { 370 // If setClick is set, we must set this to ensure that the button's 371 // value is passed. 372 if (ajax.setClick) { 373 // Mark the clicked button. 'form.clk' is a special variable for 374 // ajaxSubmit that tells the system which element got clicked to 375 // trigger the submit. Without it there would be no 'op' or 376 // equivalent. 377 element.form.clk = element; 378 } 379 380 ajax.form.ajaxSubmit(ajax.options); 381 } 382 else { 383 ajax.beforeSerialize(ajax.element, ajax.options); 384 $.ajax(ajax.options); 385 } 386 } 387 catch (e) { 388 // Unset the ajax.ajaxing flag here because it won't be unset during 389 // the complete response. 390 ajax.ajaxing = false; 391 alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message); 392 } 393 394 // For radio/checkbox, allow the default event. On IE, this means letting 395 // it actually check the box. 396 if (typeof element.type != 'undefined' && (element.type == 'checkbox' || element.type == 'radio')) { 397 return true; 398 } 399 else { 400 return false; 401 } 402 403}; 404 405/** 406 * Handler for the form serialization. 407 * 408 * Runs before the beforeSend() handler (see below), and unlike that one, runs 409 * before field data is collected. 410 */ 411Drupal.ajax.prototype.beforeSerialize = function (element, options) { 412 // Allow detaching behaviors to update field values before collecting them. 413 // This is only needed when field values are added to the POST data, so only 414 // when there is a form such that this.form.ajaxSubmit() is used instead of 415 // $.ajax(). When there is no form and $.ajax() is used, beforeSerialize() 416 // isn't called, but don't rely on that: explicitly check this.form. 417 if (this.form) { 418 var settings = this.settings || Drupal.settings; 419 Drupal.detachBehaviors(this.form, settings, 'serialize'); 420 } 421 422 // Prevent duplicate HTML ids in the returned markup. 423 // @see drupal_html_id() 424 options.data['ajax_html_ids[]'] = []; 425 $('[id]').each(function () { 426 options.data['ajax_html_ids[]'].push(this.id); 427 }); 428 429 // Allow Drupal to return new JavaScript and CSS files to load without 430 // returning the ones already loaded. 431 // @see ajax_base_page_theme() 432 // @see drupal_get_css() 433 // @see drupal_get_js() 434 options.data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme; 435 options.data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token; 436 for (var key in Drupal.settings.ajaxPageState.css) { 437 options.data['ajax_page_state[css][' + key + ']'] = 1; 438 } 439 for (var key in Drupal.settings.ajaxPageState.js) { 440 options.data['ajax_page_state[js][' + key + ']'] = 1; 441 } 442}; 443 444/** 445 * Modify form values prior to form submission. 446 */ 447Drupal.ajax.prototype.beforeSubmit = function (form_values, element, options) { 448 // This function is left empty to make it simple to override for modules 449 // that wish to add functionality here. 450}; 451 452/** 453 * Prepare the Ajax request before it is sent. 454 */ 455Drupal.ajax.prototype.beforeSend = function (xmlhttprequest, options) { 456 // For forms without file inputs, the jQuery Form plugin serializes the form 457 // values, and then calls jQuery's $.ajax() function, which invokes this 458 // handler. In this circumstance, options.extraData is never used. For forms 459 // with file inputs, the jQuery Form plugin uses the browser's normal form 460 // submission mechanism, but captures the response in a hidden IFRAME. In this 461 // circumstance, it calls this handler first, and then appends hidden fields 462 // to the form to submit the values in options.extraData. There is no simple 463 // way to know which submission mechanism will be used, so we add to extraData 464 // regardless, and allow it to be ignored in the former case. 465 if (this.form) { 466 options.extraData = options.extraData || {}; 467 468 // Let the server know when the IFRAME submission mechanism is used. The 469 // server can use this information to wrap the JSON response in a TEXTAREA, 470 // as per http://jquery.malsup.com/form/#file-upload. 471 options.extraData.ajax_iframe_upload = '1'; 472 473 // The triggering element is about to be disabled (see below), but if it 474 // contains a value (e.g., a checkbox, textfield, select, etc.), ensure that 475 // value is included in the submission. As per above, submissions that use 476 // $.ajax() are already serialized prior to the element being disabled, so 477 // this is only needed for IFRAME submissions. 478 var v = $.fieldValue(this.element); 479 if (v !== null) { 480 options.extraData[this.element.name] = Drupal.checkPlain(v); 481 } 482 } 483 484 // Disable the element that received the change to prevent user interface 485 // interaction while the Ajax request is in progress. ajax.ajaxing prevents 486 // the element from triggering a new request, but does not prevent the user 487 // from changing its value. 488 $(this.element).addClass('progress-disabled').attr('disabled', true); 489 490 // Insert progressbar or throbber. 491 if (this.progress.type == 'bar') { 492 var progressBar = new Drupal.progressBar('ajax-progress-' + this.element.i
492d, eval(this.progress.update_callback), this.progress.method, eval(this.progress.error_callback)); 493 if (this.progress.message) { 494 progressBar.setProgress(-1, this.progress.message); 495 } 496 if (this.progress.url) { 497 progressBar.startMonitoring(this.progress.url, this.progress.interval || 1500); 498 } 499 this.progress.element = $(progressBar.element).addClass('ajax-progress ajax-progress-bar'); 500 this.progress.object = progressBar; 501 $(this.element).after(this.progress.element); 502 } 503 else if (this.progress.type == 'throbber') { 504 this.progress.element = $('<div class="ajax-progress ajax-progress-throbber"><div class="throbber"> </div></div>'); 505 if (this.progress.message) { 506 $('.throbber', this.progress.element).after('<div class="message">' + this.progress.message + '</div>'); 507 } 508 $(this.element).after(this.progress.element); 509 } 510}; 511 512/** 513 * Handler for the form redirection completion. 514 */ 515Drupal.ajax.prototype.success = function (response, status) { 516 // Remove the progress element. 517 if (this.progress.element) { 518 $(this.progress.element).remove(); 519 } 520 if (this.progress.object) { 521 this.progress.object.stopMonitoring(); 522 } 523 $(this.element).removeClass('progress-disabled').removeAttr('disabled'); 524 525 Drupal.freezeHeight(); 526 527 for (var i in response) { 528 if (response.hasOwnProperty(i) && response[i]['command'] && this.commands[response[i]['command']]) { 529 this.commands[response[i]['command']](this, response[i], status); 530 } 531 } 532 533 // Reattach behaviors, if they were detached in beforeSerialize(). The 534 // attachBehaviors() called on the new content from processing the response 535 // commands is not sufficient, because behaviors from the entire form need 536 // to be reattached. 537 if (this.form) { 538 var settings = this.settings || Drupal.settings; 539 Drupal.attachBehaviors(this.form, settings); 540 } 541 542 Drupal.unfreezeHeight(); 543 544 // Remove any response-specific settings so they don't get used on the next 545 // call by mistake. 546 this.settings = null; 547}; 548 549/** 550 * Build an effect object which tells us how to apply the effect when adding new HTML. 551 */ 552Drupal.ajax.prototype.getEffect = function (response) { 553 var type = response.effect || this.effect; 554 var speed = response.speed || this.speed; 555 556 var effect = {}; 557 if (type == 'none') { 558 effect.showEffect = 'show'; 559 effect.hideEffect = 'hide'; 560 effect.showSpeed = ''; 561 } 562 else if (type == 'fade') { 563 effect.showEffect = 'fadeIn'; 564 effect.hideEffect = 'fadeOut'; 565 effect.showSpeed = speed; 566 } 567 else { 568 effect.showEffect = type + 'Toggle'; 569 effect.hideEffect = type + 'Toggle'; 570 effect.showSpeed = speed; 571 } 572 573 return effect; 574}; 575 576/** 577 * Handler for the form redirection error. 578 */ 579Drupal.ajax.prototype.error = function (xmlhttprequest, uri, customMessage) { 580 alert(Drupal.ajaxError(xmlhttprequest, uri, customMessage)); 581 // Remove the progress element. 582 if (this.progress.element) { 583 $(this.progress.element).remove(); 584 } 585 if (this.progress.object) { 586 this.progress.object.stopMonitoring(); 587 } 588 // Undo hide. 589 $(this.wrapper).show(); 590 // Re-enable the element. 591 $(this.element).removeClass('progress-disabled').removeAttr('disabled'); 592 // Reattach behaviors, if they were detached in beforeSerialize(). 593 if (this.form) { 594 var settings = this.settings || Drupal.settings; 595 Drupal.attachBehaviors(this.form, settings); 596 } 597}; 598 599/** 600 * Provide a series of commands that the server can request the client perform. 601 */ 602Drupal.ajax.prototype.commands = { 603 /** 604 * Command to insert new content into the DOM. 605 */ 606 insert: function (ajax, response, status) { 607 // Get information from the response. If it is not there, default to 608 // our presets. 609 var wrapper = response.selector ? $(response.selector) : $(ajax.wrapper); 610 var method = response.method || ajax.method; 611 var effect = ajax.getEffect(response); 612 613 // We don't know what response.data contains: it might be a string of text 614 // without HTML, so don't rely on jQuery correctly iterpreting 615 // $(response.data) as new HTML rather than a CSS selector. Also, if 616 // response.data contains top-level text nodes, they get lost with either 617 // $(response.data) or $('<div></div>').replaceWith(response.data). 618 var new_content_wrapped = $('<div></div>').html(response.data); 619 var new_content = new_content_wrapped.contents(); 620 621 // For legacy reasons, the effects processing code assumes that new_content 622 // consists of a single top-level element. Also, it has not been 623 // sufficiently tested whether attachBehaviors() can be successfully called 624 // with a context object that includes top-level text nodes. However, to 625 // give developers full control of the HTML appearing in the page, and to 626 // enable Ajax content to be inserted in places where DIV elements are not 627 // allowed (e.g., within TABLE, TR, and SPAN parents), we check if the new 628 // content satisfies the requirement of a single top-level element, and 629 // only use the container DIV created above when it doesn't. For more 630 // information, please see http://drupal.org/node/736066. 631 if (new_content.length != 1 || new_content.get(0).nodeType != 1) { 632 new_content = new_content_wrapped; 633 } 634 635 // If removing content from the wrapper, detach behaviors first. 636 switch (method) { 637 case 'html': 638 case 'replaceWith': 639 case 'replaceAll': 640 case 'empty': 641 case 'remove': 642 var settings = response.settings || ajax.settings || Drupal.settings; 643 Drupal.detachBehaviors(wrapper, settings); 644 } 645 646 // Add the new content to the page. 647 wrapper[method](new_content); 648 649 // Immediately hide the new content if we're using any effects. 650 if (effect.showEffect != 'show') { 651 new_content.hide(); 652 } 653 654 // Determine which effect to use and what content will receive the 655 // effect, then show the new content. 656 if ($('.ajax-new-content', new_content).length > 0) { 657 $('.ajax-new-content', new_content).hide(); 658 new_content.show(); 659 $('.ajax-new-content', new_content)[effect.showEffect](effect.showSpeed); 660 } 661 else if (effect.showEffect != 'show') { 662 new_content[effect.showEffect](effect.showSpeed); 663 } 664 665 // Attach all JavaScript behaviors to the new content, if it was successfully 666 // added to the page, this if statement allows #ajax['wrapper'] to be 667 // optional. 668 if (new_content.parents('html').length > 0) { 669 // Apply any settings from the returned JSON if available. 670 var settings = response.settings || ajax.settings || Drupal.settings; 671 Drupal.attachBehaviors(new_content, settings); 672 } 673 }, 674 675 /** 676 * Command to remove a chunk from the page. 677 */ 678 remove: function (ajax, response, status) { 679 var settings = response.settings || ajax.settings || Drupal.settings; 680 Drupal.detachBehaviors($(response.selector), settings); 681 $(response.selector).remove(); 682 }, 683 684 /** 685 * Command to mark a chunk changed. 686 */ 687 changed: function (ajax, response, status) { 688 if (!$(response.selector).hasClass('ajax-changed')) { 689 $(response.selector).addClass('ajax-changed'); 690 if (response.asterisk) { 691 $(response.selector).find(response.asterisk).append(' <span class="ajax-changed">*</span> '); 692 } 693 } 694 }, 695 696 /** 697 * Command to provide an alert. 698 */ 699 alert: function (ajax, response, status) { 700 alert(response.text, response.title); 701 }, 702 703 /** 704 * Command to provide the jQuery css() function. 705 */ 706 css: function (ajax, response, status) { 707 $(response.selector).css(response.argument); 708 }, 709 710 /** 711 * Command to set the settings that will be used for other commands in this response. 712 */ 713 settings: function (ajax, response, status) { 714 if (response.merge) { 715 $.extend(true, Drupal.settings, response.settings); 716 } 717 else { 718 ajax.settings = response.settings; 719 } 720 }, 721 722 /** 723 * Command to attach data using jQuery's data API. 724 */ 725 data: function (ajax, response, status) { 726 $(response.selector).data(response.name, response.value); 727 }, 728 729 /** 730 * Command to apply a jQuery method. 731 */ 732 invoke: function (ajax, response, status) { 733 var $element = $(response.selector); 734 $element[response.method].apply($element, response.arguments); 735 }, 736 737 /** 738 * Command to restripe a table. 739 */ 740 restripe: function (ajax, response, status) { 741 // :even and :odd are reversed because jQuery counts from 0 and 742 // we count from 1, so we're out of sync. 743 // Match immediate children of the parent element to allow nesting. 744 $('> tbody > tr:visible, > tr:visible', $(response.selector)) 745 .removeClass('odd even') 746 .filter(':even').addClass('odd').end() 747 .filter(':odd').addClass('even'); 748 }, 749 750 /** 751 * Command to add css. 752 * 753 * Uses the proprietary addImport method if available as browsers which 754 * support that method ignore @import statements in dynamically added 755 * stylesheets. 756 */ 757 add_css: function (ajax, response, status) { 758 // Add the styles in the normal way. 759 $('head').prepend(response.data); 760 // Add imports in the styles using the addImport method if available. 761 var match, importMatch = /^@import url\("(.*)"\);$/igm; 762 if (document.styleSheets[0].addImport && importMatch.test(response.data)) { 763 importMatch.lastIndex = 0; 764 while (match = importMatch.exec(response.data)) { 765 document.styleSheets[0].addImport(match[1]); 766 } 767 } 768 }, 769 770 /** 771 * Command to update a form's build ID. 772 */ 773 updateBuildId: function(ajax, response, status) { 774 $('input[name="form_build_id"][value="' + response['old'] + '"]').val(response['new']); 775 } 776}; 777 778})(jQuery); 779; 780(function (D) { 781 var beforeSerialize = D.ajax.prototype.beforeSerialize;
782 D.ajax.prototype.beforeSerialize = function (element, options) { 783 beforeSerialize.call(this, element, options); 784 options.data['ajax_page_state[jquery_version]'] = D.settings.ajaxPageState.jquery_version; 785 } 786})(Drupal); 787;
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.