'targets' => [ 'mobile', 'desktop' ],
],
'jquery.async' => [
- 'scripts' => 'resources/lib/jquery/jquery.async.js',
+ 'scripts' => 'resources/lib/jquery.async.js',
],
'jquery.byteLength' => [
'scripts' => 'resources/src/jquery/jquery.byteLength.js',
'dependencies' => 'mediawiki.jqueryMsg',
],
'jquery.cookie' => [
- 'scripts' => 'resources/lib/jquery/jquery.cookie.js',
+ 'scripts' => 'resources/lib/jquery.cookie.js',
'targets' => [ 'desktop', 'mobile' ],
],
'jquery.form' => [
- 'scripts' => 'resources/lib/jquery/jquery.form.js',
+ 'scripts' => 'resources/lib/jquery.form.js',
],
'jquery.fullscreen' => [
- 'scripts' => 'resources/lib/jquery/jquery.fullscreen.js',
+ 'scripts' => 'resources/lib/jquery.fullscreen.js',
],
'jquery.getAttrs' => [
'targets' => [ 'desktop', 'mobile' ],
'targets' => [ 'desktop', 'mobile' ],
],
'jquery.hoverIntent' => [
- 'scripts' => 'resources/lib/jquery/jquery.hoverIntent.js',
+ 'scripts' => 'resources/lib/jquery.hoverIntent.js',
],
'jquery.i18n' => [
'scripts' => [
'targets' => [ 'desktop', 'mobile' ],
],
'jquery.mockjax' => [
- 'scripts' => 'resources/lib/jquery/jquery.mockjax.js',
+ 'scripts' => 'resources/lib/jquery.mockjax.js',
],
'jquery.mw-jump' => [
'scripts' => 'resources/src/jquery/jquery.mw-jump.js',
],
'jquery.jStorage' => [
'deprecated' => 'Please use "mediawiki.storage" instead.',
- 'scripts' => 'resources/lib/jquery/jquery.jStorage.js',
+ 'scripts' => 'resources/lib/jquery.jStorage.js',
],
'jquery.suggestions' => [
'targets' => [ 'desktop', 'mobile' ],
'targets' => [ 'mobile', 'desktop' ],
],
'jquery.throttle-debounce' => [
- 'scripts' => 'resources/lib/jquery/jquery.ba-throttle-debounce.js',
+ 'scripts' => 'resources/lib/jquery.ba-throttle-debounce.js',
'targets' => [ 'desktop', 'mobile' ],
],
'jquery.xmldom' => [
- 'scripts' => 'resources/lib/jquery/jquery.xmldom.js',
+ 'scripts' => 'resources/lib/jquery.xmldom.js',
],
/* jQuery Tipsy */
--- /dev/null
+/*
+ * jQuery Asynchronous Plugin 1.0
+ *
+ * Copyright (c) 2008 Vincent Robert (genezys.net)
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ *
+ */
+(function($){
+
+// opts.delay : (default 10) delay between async call in ms
+// opts.bulk : (default 500) delay during which the loop can continue synchronously without yielding the CPU
+// opts.test : (default true) function to test in the while test part
+// opts.loop : (default empty) function to call in the while loop part
+// opts.end : (default empty) function to call at the end of the while loop
+$.whileAsync = function(opts) {
+ var delay = Math.abs(opts.delay) || 10,
+ bulk = isNaN(opts.bulk) ? 500 : Math.abs(opts.bulk),
+ test = opts.test || function(){ return true; },
+ loop = opts.loop || function(){},
+ end = opts.end || function(){};
+
+ (function(){
+
+ var t = false,
+ begin = new Date();
+
+ while( t = test() ) {
+ loop();
+ if( bulk === 0 || (new Date() - begin) > bulk ) {
+ break;
+ }
+ }
+ if( t ) {
+ setTimeout(arguments.callee, delay);
+ }
+ else {
+ end();
+ }
+
+ })();
+};
+
+// opts.delay : (default 10) delay between async call in ms
+// opts.bulk : (default 500) delay during which the loop can continue synchronously without yielding the CPU
+// opts.loop : (default empty) function to call in the each loop part, signature: function(index, value) this = value
+// opts.end : (default empty) function to call at the end of the each loop
+$.eachAsync = function(array, opts) {
+ var i = 0,
+ l = array.length,
+ loop = opts.loop || function(){};
+
+ $.whileAsync(
+ $.extend(opts, {
+ test: function() { return i < l; },
+ loop: function() {
+ var val = array[i];
+ return loop.call(val, i++, val);
+ }
+ })
+ );
+};
+
+$.fn.eachAsync = function(opts) {
+ $.eachAsync(this, opts);
+ return this;
+}
+
+})(jQuery);
\ No newline at end of file
--- /dev/null
+/*!
+ * jQuery throttle / debounce - v1.1 - 3/7/2010
+ * http://benalman.com/projects/jquery-throttle-debounce-plugin/
+ *
+ * Copyright (c) 2010 "Cowboy" Ben Alman
+ * Dual licensed under the MIT and GPL licenses.
+ * http://benalman.com/about/license/
+ */
+
+// Script: jQuery throttle / debounce: Sometimes, less is more!
+//
+// *Version: 1.1, Last updated: 3/7/2010*
+//
+// Project Home - http://benalman.com/projects/jquery-throttle-debounce-plugin/
+// GitHub - http://github.com/cowboy/jquery-throttle-debounce/
+// Source - http://github.com/cowboy/jquery-throttle-debounce/raw/master/jquery.ba-throttle-debounce.js
+// (Minified) - http://github.com/cowboy/jquery-throttle-debounce/raw/master/jquery.ba-throttle-debounce.min.js (0.7kb)
+//
+// About: License
+//
+// Copyright (c) 2010 "Cowboy" Ben Alman,
+// Dual licensed under the MIT and GPL licenses.
+// http://benalman.com/about/license/
+//
+// About: Examples
+//
+// These working examples, complete with fully commented code, illustrate a few
+// ways in which this plugin can be used.
+//
+// Throttle - http://benalman.com/code/projects/jquery-throttle-debounce/examples/throttle/
+// Debounce - http://benalman.com/code/projects/jquery-throttle-debounce/examples/debounce/
+//
+// About: Support and Testing
+//
+// Information about what version or versions of jQuery this plugin has been
+// tested with, what browsers it has been tested in, and where the unit tests
+// reside (so you can test it yourself).
+//
+// jQuery Versions - none, 1.3.2, 1.4.2
+// Browsers Tested - Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome 4-5, Opera 9.6-10.1.
+// Unit Tests - http://benalman.com/code/projects/jquery-throttle-debounce/unit/
+//
+// About: Release History
+//
+// 1.1 - (3/7/2010) Fixed a bug in <jQuery.throttle> where trailing callbacks
+// executed later than they should. Reworked a fair amount of internal
+// logic as well.
+// 1.0 - (3/6/2010) Initial release as a stand-alone project. Migrated over
+// from jquery-misc repo v0.4 to jquery-throttle repo v1.0, added the
+// no_trailing throttle parameter and debounce functionality.
+//
+// Topic: Note for non-jQuery users
+//
+// jQuery isn't actually required for this plugin, because nothing internal
+// uses any jQuery methods or properties. jQuery is just used as a namespace
+// under which these methods can exist.
+//
+// Since jQuery isn't actually required for this plugin, if jQuery doesn't exist
+// when this plugin is loaded, the method described below will be created in
+// the `Cowboy` namespace. Usage will be exactly the same, but instead of
+// $.method() or jQuery.method(), you'll need to use Cowboy.method().
+
+(function(window,undefined){
+ '$:nomunge'; // Used by YUI compressor.
+
+ // Since jQuery really isn't required for this plugin, use `jQuery` as the
+ // namespace only if it already exists, otherwise use the `Cowboy` namespace,
+ // creating it if necessary.
+ var $ = window.jQuery || window.Cowboy || ( window.Cowboy = {} ),
+
+ // Internal method reference.
+ jq_throttle;
+
+ // Method: jQuery.throttle
+ //
+ // Throttle execution of a function. Especially useful for rate limiting
+ // execution of handlers on events like resize and scroll. If you want to
+ // rate-limit execution of a function to a single time, see the
+ // <jQuery.debounce> method.
+ //
+ // In this visualization, | is a throttled-function call and X is the actual
+ // callback execution:
+ //
+ // > Throttled with `no_trailing` specified as false or unspecified:
+ // > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
+ // > X X X X X X X X X X X X
+ // >
+ // > Throttled with `no_trailing` specified as true:
+ // > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
+ // > X X X X X X X X X X
+ //
+ // Usage:
+ //
+ // > var throttled = jQuery.throttle( delay, [ no_trailing, ] callback );
+ // >
+ // > jQuery('selector').bind( 'someevent', throttled );
+ // > jQuery('selector').unbind( 'someevent', throttled );
+ //
+ // This also works in jQuery 1.4+:
+ //
+ // > jQuery('selector').bind( 'someevent', jQuery.throttle( delay, [ no_trailing, ] callback ) );
+ // > jQuery('selector').unbind( 'someevent', callback );
+ //
+ // Arguments:
+ //
+ // delay - (Number) A zero-or-greater delay in milliseconds. For event
+ // callbacks, values around 100 or 250 (or even higher) are most useful.
+ // no_trailing - (Boolean) Optional, defaults to false. If no_trailing is
+ // true, callback will only execute every `delay` milliseconds while the
+ // throttled-function is being called. If no_trailing is false or
+ // unspecified, callback will be executed one final time after the last
+ // throttled-function call. (After the throttled-function has not been
+ // called for `delay` milliseconds, the internal counter is reset)
+ // callback - (Function) A function to be executed after delay milliseconds.
+ // The `this` context and all arguments are passed through, as-is, to
+ // `callback` when the throttled-function is executed.
+ //
+ // Returns:
+ //
+ // (Function) A new, throttled, function.
+
+ $.throttle = jq_throttle = function( delay, no_trailing, callback, debounce_mode ) {
+ // After wrapper has stopped being called, this timeout ensures that
+ // `callback` is executed at the proper times in `throttle` and `end`
+ // debounce modes.
+ var timeout_id,
+
+ // Keep track of the last time `callback` was executed.
+ last_exec = 0;
+
+ // `no_trailing` defaults to falsy.
+ if ( typeof no_trailing !== 'boolean' ) {
+ debounce_mode = callback;
+ callback = no_trailing;
+ no_trailing = undefined;
+ }
+
+ // The `wrapper` function encapsulates all of the throttling / debouncing
+ // functionality and when executed will limit the rate at which `callback`
+ // is executed.
+ function wrapper() {
+ var that = this,
+ elapsed = +new Date() - last_exec,
+ args = arguments;
+
+ // Execute `callback` and update the `last_exec` timestamp.
+ function exec() {
+ last_exec = +new Date();
+ callback.apply( that, args );
+ };
+
+ // If `debounce_mode` is true (at_begin) this is used to clear the flag
+ // to allow future `callback` executions.
+ function clear() {
+ timeout_id = undefined;
+ };
+
+ if ( debounce_mode && !timeout_id ) {
+ // Since `wrapper` is being called for the first time and
+ // `debounce_mode` is true (at_begin), execute `callback`.
+ exec();
+ }
+
+ // Clear any existing timeout.
+ timeout_id && clearTimeout( timeout_id );
+
+ if ( debounce_mode === undefined && elapsed > delay ) {
+ // In throttle mode, if `delay` time has been exceeded, execute
+ // `callback`.
+ exec();
+
+ } else if ( no_trailing !== true ) {
+ // In trailing throttle mode, since `delay` time has not been
+ // exceeded, schedule `callback` to execute `delay` ms after most
+ // recent execution.
+ //
+ // If `debounce_mode` is true (at_begin), schedule `clear` to execute
+ // after `delay` ms.
+ //
+ // If `debounce_mode` is false (at end), schedule `callback` to
+ // execute after `delay` ms.
+ timeout_id = setTimeout( debounce_mode ? clear : exec, debounce_mode === undefined ? delay - elapsed : delay );
+ }
+ };
+
+ // Set the guid of `wrapper` function to the same of original callback, so
+ // it can be removed in jQuery 1.4+ .unbind or .die by using the original
+ // callback as a reference.
+ if ( $.guid ) {
+ wrapper.guid = callback.guid = callback.guid || $.guid++;
+ }
+
+ // Return the wrapper function.
+ return wrapper;
+ };
+
+ // Method: jQuery.debounce
+ //
+ // Debounce execution of a function. Debouncing, unlike throttling,
+ // guarantees that a function is only executed a single time, either at the
+ // very beginning of a series of calls, or at the very end. If you want to
+ // simply rate-limit execution of a function, see the <jQuery.throttle>
+ // method.
+ //
+ // In this visualization, | is a debounced-function call and X is the actual
+ // callback execution:
+ //
+ // > Debounced with `at_begin` specified as false or unspecified:
+ // > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
+ // > X X
+ // >
+ // > Debounced with `at_begin` specified as true:
+ // > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
+ // > X X
+ //
+ // Usage:
+ //
+ // > var debounced = jQuery.debounce( delay, [ at_begin, ] callback );
+ // >
+ // > jQuery('selector').bind( 'someevent', debounced );
+ // > jQuery('selector').unbind( 'someevent', debounced );
+ //
+ // This also works in jQuery 1.4+:
+ //
+ // > jQuery('selector').bind( 'someevent', jQuery.debounce( delay, [ at_begin, ] callback ) );
+ // > jQuery('selector').unbind( 'someevent', callback );
+ //
+ // Arguments:
+ //
+ // delay - (Number) A zero-or-greater delay in milliseconds. For event
+ // callbacks, values around 100 or 250 (or even higher) are most useful.
+ // at_begin - (Boolean) Optional, defaults to false. If at_begin is false or
+ // unspecified, callback will only be executed `delay` milliseconds after
+ // the last debounced-function call. If at_begin is true, callback will be
+ // executed only at the first debounced-function call. (After the
+ // throttled-function has not been called for `delay` milliseconds, the
+ // internal counter is reset)
+ // callback - (Function) A function to be executed after delay milliseconds.
+ // The `this` context and all arguments are passed through, as-is, to
+ // `callback` when the debounced-function is executed.
+ //
+ // Returns:
+ //
+ // (Function) A new, debounced, function.
+
+ $.debounce = function( delay, at_begin, callback ) {
+ return callback === undefined
+ ? jq_throttle( delay, at_begin, false )
+ : jq_throttle( delay, callback, at_begin !== false );
+ };
+
+})(this);
--- /dev/null
+/*!
+ * jQuery Cookie Plugin v1.3.1
+ * https://github.com/carhartl/jquery-cookie
+ *
+ * Copyright 2013 Klaus Hartl
+ * Released under the MIT license
+ */
+(function ($, document, undefined) {
+
+ var pluses = /\+/g;
+
+ function raw(s) {
+ return s;
+ }
+
+ function decoded(s) {
+ return unRfc2068(decodeURIComponent(s.replace(pluses, ' ')));
+ }
+
+ function unRfc2068(value) {
+ if (value.indexOf('"') === 0) {
+ // This is a quoted cookie as according to RFC2068, unescape
+ value = value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
+ }
+ return value;
+ }
+
+ function fromJSON(value) {
+ return config.json ? JSON.parse(value) : value;
+ }
+
+ var config = $.cookie = function (key, value, options) {
+
+ // write
+ if (value !== undefined) {
+ options = $.extend({}, config.defaults, options);
+
+ if (value === null) {
+ options.expires = -1;
+ }
+
+ if (typeof options.expires === 'number') {
+ var days = options.expires, t = options.expires = new Date();
+ t.setDate(t.getDate() + days);
+ }
+
+ value = config.json ? JSON.stringify(value) : String(value);
+
+ return (document.cookie = [
+ encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
+ options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
+ options.path ? '; path=' + options.path : '',
+ options.domain ? '; domain=' + options.domain : '',
+ options.secure ? '; secure' : ''
+ ].join(''));
+ }
+
+ // read
+ var decode = config.raw ? raw : decoded;
+ var cookies = document.cookie.split('; ');
+ var result = key ? null : {};
+ for (var i = 0, l = cookies.length; i < l; i++) {
+ var parts = cookies[i].split('=');
+ var name = decode(parts.shift());
+ var cookie = decode(parts.join('='));
+
+ if (key && key === name) {
+ result = fromJSON(cookie);
+ break;
+ }
+
+ if (!key) {
+ result[name] = fromJSON(cookie);
+ }
+ }
+
+ return result;
+ };
+
+ config.defaults = {};
+
+ $.removeCookie = function (key, options) {
+ if ($.cookie(key) !== null) {
+ $.cookie(key, null, options);
+ return true;
+ }
+ return false;
+ };
+
+})(jQuery, document);
--- /dev/null
+/*!
+ * jQuery Form Plugin
+ * version: 3.14 (30-JUL-2012)
+ * @requires jQuery v1.3.2 or later
+ *
+ * Examples and documentation at: http://malsup.com/jquery/form/
+ * Project repository: https://github.com/malsup/form
+ * Dual licensed under the MIT and GPL licenses:
+ * http://malsup.github.com/mit-license.txt
+ * http://malsup.github.com/gpl-license-v2.txt
+ */
+/*global ActiveXObject alert */
+;(function($) {
+"use strict";
+
+/*
+ Usage Note:
+ -----------
+ Do not use both ajaxSubmit and ajaxForm on the same form. These
+ functions are mutually exclusive. Use ajaxSubmit if you want
+ to bind your own submit handler to the form. For example,
+
+ $(document).ready(function() {
+ $('#myForm').on('submit', function(e) {
+ e.preventDefault(); // <-- important
+ $(this).ajaxSubmit({
+ target: '#output'
+ });
+ });
+ });
+
+ Use ajaxForm when you want the plugin to manage all the event binding
+ for you. For example,
+
+ $(document).ready(function() {
+ $('#myForm').ajaxForm({
+ target: '#output'
+ });
+ });
+
+ You can also use ajaxForm with delegation (requires jQuery v1.7+), so the
+ form does not have to exist when you invoke ajaxForm:
+
+ $('#myForm').ajaxForm({
+ delegation: true,
+ target: '#output'
+ });
+
+ When using ajaxForm, the ajaxSubmit function will be invoked for you
+ at the appropriate time.
+*/
+
+/**
+ * Feature detection
+ */
+var feature = {};
+feature.fileapi = $("<input type='file'/>").get(0).files !== undefined;
+feature.formdata = window.FormData !== undefined;
+
+/**
+ * ajaxSubmit() provides a mechanism for immediately submitting
+ * an HTML form using AJAX.
+ */
+$.fn.ajaxSubmit = function(options) {
+ /*jshint scripturl:true */
+
+ // fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
+ if (!this.length) {
+ log('ajaxSubmit: skipping submit process - no element selected');
+ return this;
+ }
+
+ var method, action, url, $form = this;
+
+ if (typeof options == 'function') {
+ options = { success: options };
+ }
+
+ method = this.attr('method');
+ action = this.attr('action');
+ url = (typeof action === 'string') ? $.trim(action) : '';
+ url = url || window.location.href || '';
+ if (url) {
+ // clean url (don't include hash vaue)
+ url = (url.match(/^([^#]+)/)||[])[1];
+ }
+
+ options = $.extend(true, {
+ url: url,
+ success: $.ajaxSettings.success,
+ type: method || 'GET',
+ iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
+ }, options);
+
+ // hook for manipulating the form data before it is extracted;
+ // convenient for use with rich editors like tinyMCE or FCKEditor
+ var veto = {};
+ this.trigger('form-pre-serialize', [this, options, veto]);
+ if (veto.veto) {
+ log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
+ return this;
+ }
+
+ // provide opportunity to alter form data before it is serialized
+ if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
+ log('ajaxSubmit: submit aborted via beforeSerialize callback');
+ return this;
+ }
+
+ var traditional = options.traditional;
+ if ( traditional === undefined ) {
+ traditional = $.ajaxSettings.traditional;
+ }
+
+ var elements = [];
+ var qx, a = this.formToArray(options.semantic, elements);
+ if (options.data) {
+ options.extraData = options.data;
+ qx = $.param(options.data, traditional);
+ }
+
+ // give pre-submit callback an opportunity to abort the submit
+ if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
+ log('ajaxSubmit: submit aborted via beforeSubmit callback');
+ return this;
+ }
+
+ // fire vetoable 'validate' event
+ this.trigger('form-submit-validate', [a, this, options, veto]);
+ if (veto.veto) {
+ log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
+ return this;
+ }
+
+ var q = $.param(a, traditional);
+ if (qx) {
+ q = ( q ? (q + '&' + qx) : qx );
+ }
+ if (options.type.toUpperCase() == 'GET') {
+ options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
+ options.data = null; // data is null for 'get'
+ }
+ else {
+ options.data = q; // data is the query string for 'post'
+ }
+
+ var callbacks = [];
+ if (options.resetForm) {
+ callbacks.push(function() { $form.resetForm(); });
+ }
+ if (options.clearForm) {
+ callbacks.push(function() { $form.clearForm(options.includeHidden); });
+ }
+
+ // perform a load on the target only if dataType is not provided
+ if (!options.dataType && options.target) {
+ var oldSuccess = options.success || function(){};
+ callbacks.push(function(data) {
+ var fn = options.replaceTarget ? 'replaceWith' : 'html';
+ $(options.target)[fn](data).each(oldSuccess, arguments);
+ });
+ }
+ else if (options.success) {
+ callbacks.push(options.success);
+ }
+
+ options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
+ var context = options.context || this ; // jQuery 1.4+ supports scope context
+ for (var i=0, max=callbacks.length; i < max; i++) {
+ callbacks[i].apply(context, [data, status, xhr || $form, $form]);
+ }
+ };
+
+ // are there files to upload?
+ var fileInputs = $('input:file:enabled[value]', this); // [value] (issue #113)
+ var hasFileInputs = fileInputs.length > 0;
+ var mp = 'multipart/form-data';
+ var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
+
+ var fileAPI = feature.fileapi && feature.formdata;
+ log("fileAPI :" + fileAPI);
+ var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;
+
+ // options.iframe allows user to force iframe mode
+ // 06-NOV-09: now defaulting to iframe mode if file input is detected
+ if (options.iframe !== false && (options.iframe || shouldUseFrame)) {
+ // hack to fix Safari hang (thanks to Tim Molendijk for this)
+ // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
+ if (options.closeKeepAlive) {
+ $.get(options.closeKeepAlive, function() {
+ fileUploadIframe(a);
+ });
+ }
+ else {
+ fileUploadIframe(a);
+ }
+ }
+ else if ((hasFileInputs || multipart) && fileAPI) {
+ fileUploadXhr(a);
+ }
+ else {
+ $.ajax(options);
+ }
+
+ // clear element array
+ for (var k=0; k < elements.length; k++)
+ elements[k] = null;
+
+ // fire 'notify' event
+ this.trigger('form-submit-notify', [this, options]);
+ return this;
+
+ // XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
+ function fileUploadXhr(a) {
+ var formdata = new FormData();
+
+ for (var i=0; i < a.length; i++) {
+ formdata.append(a[i].name, a[i].value);
+ }
+
+ if (options.extraData) {
+ for (var p in options.extraData)
+ if (options.extraData.hasOwnProperty(p))
+ formdata.append(p, options.extraData[p]);
+ }
+
+ options.data = null;
+
+ var s = $.extend(true, {}, $.ajaxSettings, options, {
+ contentType: false,
+ processData: false,
+ cache: false,
+ type: 'POST'
+ });
+
+ if (options.uploadProgress) {
+ // workaround because jqXHR does not expose upload property
+ s.xhr = function() {
+ var xhr = jQuery.ajaxSettings.xhr();
+ if (xhr.upload) {
+ xhr.upload.onprogress = function(event) {
+ var percent = 0;
+ var position = event.loaded || event.position; /*event.position is deprecated*/
+ var total = event.total;
+ if (event.lengthComputable) {
+ percent = Math.ceil(position / total * 100);
+ }
+ options.uploadProgress(event, position, total, percent);
+ };
+ }
+ return xhr;
+ };
+ }
+
+ s.data = null;
+ var beforeSend = s.beforeSend;
+ s.beforeSend = function(xhr, o) {
+ o.data = formdata;
+ if(beforeSend)
+ beforeSend.call(this, xhr, o);
+ };
+ $.ajax(s);
+ }
+
+ // private function for handling file uploads (hat tip to YAHOO!)
+ function fileUploadIframe(a) {
+ var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle;
+ var useProp = !!$.fn.prop;
+
+ if ($(':input[name=submit],:input[id=submit]', form).length) {
+ // if there is an input with a name or id of 'submit' then we won't be
+ // able to invoke the submit fn on the form (at least not x-browser)
+ alert('Error: Form elements must not have name or id of "submit".');
+ return;
+ }
+
+ if (a) {
+ // ensure that every serialized input is still enabled
+ for (i=0; i < elements.length; i++) {
+ el = $(elements[i]);
+ if ( useProp )
+ el.prop('disabled', false);
+ else
+ el.removeAttr('disabled');
+ }
+ }
+
+ s = $.extend(true, {}, $.ajaxSettings, options);
+ s.context = s.context || s;
+ id = 'jqFormIO' + (new Date().getTime());
+ if (s.iframeTarget) {
+ $io = $(s.iframeTarget);
+ n = $io.attr('name');
+ if (!n)
+ $io.attr('name', id);
+ else
+ id = n;
+ }
+ else {
+ $io = $('<iframe name="' + id + '" src="'+ s.iframeSrc +'" />');
+ $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
+ }
+ io = $io[0];
+
+
+ xhr = { // mock object
+ aborted: 0,
+ responseText: null,
+ responseXML: null,
+ status: 0,
+ statusText: 'n/a',
+ getAllResponseHeaders: function() {},
+ getResponseHeader: function() {},
+ setRequestHeader: function() {},
+ abort: function(status) {
+ var e = (status === 'timeout' ? 'timeout' : 'aborted');
+ log('aborting upload... ' + e);
+ this.aborted = 1;
+ // #214
+ if (io.contentWindow.document.execCommand) {
+ try { // #214
+ io.contentWindow.document.execCommand('Stop');
+ } catch(ignore) {}
+ }
+ $io.attr('src', s.iframeSrc); // abort op in progress
+ xhr.error = e;
+ if (s.error)
+ s.error.call(s.context, xhr, e, status);
+ if (g)
+ $.event.trigger("ajaxError", [xhr, s, e]);
+ if (s.complete)
+ s.complete.call(s.context, xhr, e);
+ }
+ };
+
+ g = s.global;
+ // trigger ajax global events so that activity/block indicators work like normal
+ if (g && 0 === $.active++) {
+ $.event.trigger("ajaxStart");
+ }
+ if (g) {
+ $.event.trigger("ajaxSend", [xhr, s]);
+ }
+
+ if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
+ if (s.global) {
+ $.active--;
+ }
+ return;
+ }
+ if (xhr.aborted) {
+ return;
+ }
+
+ // add submitting element to data if we know it
+ sub = form.clk;
+ if (sub) {
+ n = sub.name;
+ if (n && !sub.disabled) {
+ s.extraData = s.extraData || {};
+ s.extraData[n] = sub.value;
+ if (sub.type == "image") {
+ s.extraData[n+'.x'] = form.clk_x;
+ s.extraData[n+'.y'] = form.clk_y;
+ }
+ }
+ }
+
+ var CLIENT_TIMEOUT_ABORT = 1;
+ var SERVER_ABORT = 2;
+
+ function getDoc(frame) {
+ var doc = frame.contentWindow ? frame.contentWindow.document : frame.contentDocument ? frame.contentDocument : frame.document;
+ return doc;
+ }
+
+ // Rails CSRF hack (thanks to Yvan Barthelemy)
+ var csrf_token = $('meta[name=csrf-token]').attr('content');
+ var csrf_param = $('meta[name=csrf-param]').attr('content');
+ if (csrf_param && csrf_token) {
+ s.extraData = s.extraData || {};
+ s.extraData[csrf_param] = csrf_token;
+ }
+
+ // take a breath so that pending repaints get some cpu time before the upload starts
+ function doSubmit() {
+ // make sure form attrs are set
+ var t = $form.attr('target'), a = $form.attr('action');
+
+ // update form attrs in IE friendly way
+ form.setAttribute('target',id);
+ if (!method) {
+ form.setAttribute('method', 'POST');
+ }
+ if (a != s.url) {
+ form.setAttribute('action', s.url);
+ }
+
+ // ie borks in some cases when setting encoding
+ if (! s.skipEncodingOverride && (!method || /post/i.test(method))) {
+ $form.attr({
+ encoding: 'multipart/form-data',
+ enctype: 'multipart/form-data'
+ });
+ }
+
+ // support timout
+ if (s.timeout) {
+ timeoutHandle = setTimeout(function() { timedOut = true; cb(CLIENT_TIMEOUT_ABORT); }, s.timeout);
+ }
+
+ // look for server aborts
+ function checkState() {
+ try {
+ var state = getDoc(io).readyState;
+ log('state = ' + state);
+ if (state && state.toLowerCase() == 'uninitialized')
+ setTimeout(checkState,50);
+ }
+ catch(e) {
+ log('Server abort: ' , e, ' (', e.name, ')');
+ cb(SERVER_ABORT);
+ if (timeoutHandle)
+ clearTimeout(timeoutHandle);
+ timeoutHandle = undefined;
+ }
+ }
+
+ // add "extra" data to form if provided in options
+ var extraInputs = [];
+ try {
+ if (s.extraData) {
+ for (var n in s.extraData) {
+ if (s.extraData.hasOwnProperty(n)) {
+ // if using the $.param format that allows for multiple values with the same name
+ if($.isPlainObject(s.extraData[n]) && s.extraData[n].hasOwnProperty('name') && s.extraData[n].hasOwnProperty('value')) {
+ extraInputs.push(
+ $('<input type="hidden" name="'+s.extraData[n].name+'">').attr('value',s.extraData[n].value)
+ .appendTo(form)[0]);
+ } else {
+ extraInputs.push(
+ $('<input type="hidden" name="'+n+'">').attr('value',s.extraData[n])
+ .appendTo(form)[0]);
+ }
+ }
+ }
+ }
+
+ if (!s.iframeTarget) {
+ // add iframe to doc and submit the form
+ $io.appendTo('body');
+ if (io.attachEvent)
+ io.attachEvent('onload', cb);
+ else
+ io.addEventListener('load', cb, false);
+ }
+ setTimeout(checkState,15);
+ form.submit();
+ }
+ finally {
+ // reset attrs and remove "extra" input elements
+ form.setAttribute('action',a);
+ if(t) {
+ form.setAttribute('target', t);
+ } else {
+ $form.removeAttr('target');
+ }
+ $(extraInputs).remove();
+ }
+ }
+
+ if (s.forceSync) {
+ doSubmit();
+ }
+ else {
+ setTimeout(doSubmit, 10); // this lets dom updates render
+ }
+
+ var data, doc, domCheckCount = 50, callbackProcessed;
+
+ function cb(e) {
+ if (xhr.aborted || callbackProcessed) {
+ return;
+ }
+ try {
+ doc = getDoc(io);
+ }
+ catch(ex) {
+ log('cannot access response document: ', ex);
+ e = SERVER_ABORT;
+ }
+ if (e === CLIENT_TIMEOUT_ABORT && xhr) {
+ xhr.abort('timeout');
+ return;
+ }
+ else if (e == SERVER_ABORT && xhr) {
+ xhr.abort('server abort');
+ return;
+ }
+
+ if (!doc || doc.location.href == s.iframeSrc) {
+ // response not received yet
+ if (!timedOut)
+ return;
+ }
+ if (io.detachEvent)
+ io.detachEvent('onload', cb);
+ else
+ io.removeEventListener('load', cb, false);
+
+ var status = 'success', errMsg;
+ try {
+ if (timedOut) {
+ throw 'timeout';
+ }
+
+ var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
+ log('isXml='+isXml);
+ if (!isXml && window.opera && (doc.body === null || !doc.body.innerHTML)) {
+ if (--domCheckCount) {
+ // in some browsers (Opera) the iframe DOM is not always traversable when
+ // the onload callback fires, so we loop a bit to accommodate
+ log('requeing onLoad callback, DOM not available');
+ setTimeout(cb, 250);
+ return;
+ }
+ // let this fall through because server response could be an empty document
+ //log('Could not access iframe DOM after mutiple tries.');
+ //throw 'DOMException: not available';
+ }
+
+ //log('response detected');
+ var docRoot = doc.body ? doc.body : doc.documentElement;
+ xhr.responseText = docRoot ? docRoot.innerHTML : null;
+ xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
+ if (isXml)
+ s.dataType = 'xml';
+ xhr.getResponseHeader = function(header){
+ var headers = {'content-type': s.dataType};
+ return headers[header];
+ };
+ // support for XHR 'status' & 'statusText' emulation :
+ if (docRoot) {
+ xhr.status = Number( docRoot.getAttribute('status') ) || xhr.status;
+ xhr.statusText = docRoot.getAttribute('statusText') || xhr.statusText;
+ }
+
+ var dt = (s.dataType || '').toLowerCase();
+ var scr = /(json|script|text)/.test(dt);
+ if (scr || s.textarea) {
+ // see if user embedded response in textarea
+ var ta = doc.getElementsByTagName('textarea')[0];
+ if (ta) {
+ xhr.responseText = ta.value;
+ // support for XHR 'status' & 'statusText' emulation :
+ xhr.status = Number( ta.getAttribute('status') ) || xhr.status;
+ xhr.statusText = ta.getAttribute('statusText') || xhr.statusText;
+ }
+ else if (scr) {
+ // account for browsers injecting pre around json response
+ var pre = doc.getElementsByTagName('pre')[0];
+ var b = doc.getElementsByTagName('body')[0];
+ if (pre) {
+ xhr.responseText = pre.textContent ? pre.textContent : pre.innerText;
+ }
+ else if (b) {
+ xhr.responseText = b.textContent ? b.textContent : b.innerText;
+ }
+ }
+ }
+ else if (dt == 'xml' && !xhr.responseXML && xhr.responseText) {
+ xhr.responseXML = toXml(xhr.responseText);
+ }
+
+ try {
+ data = httpData(xhr, dt, s);
+ }
+ catch (e) {
+ status = 'parsererror';
+ xhr.error = errMsg = (e || status);
+ }
+ }
+ catch (e) {
+ log('error caught: ',e);
+ status = 'error';
+ xhr.error = errMsg = (e || status);
+ }
+
+ if (xhr.aborted) {
+ log('upload aborted');
+ status = null;
+ }
+
+ if (xhr.status) { // we've set xhr.status
+ status = (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) ? 'success' : 'error';
+ }
+
+ // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
+ if (status === 'success') {
+ if (s.success)
+ s.success.call(s.context, data, 'success', xhr);
+ if (g)
+ $.event.trigger("ajaxSuccess", [xhr, s]);
+ }
+ else if (status) {
+ if (errMsg === undefined)
+ errMsg = xhr.statusText;
+ if (s.error)
+ s.error.call(s.context, xhr, status, errMsg);
+ if (g)
+ $.event.trigger("ajaxError", [xhr, s, errMsg]);
+ }
+
+ if (g)
+ $.event.trigger("ajaxComplete", [xhr, s]);
+
+ if (g && ! --$.active) {
+ $.event.trigger("ajaxStop");
+ }
+
+ if (s.complete)
+ s.complete.call(s.context, xhr, status);
+
+ callbackProcessed = true;
+ if (s.timeout)
+ clearTimeout(timeoutHandle);
+
+ // clean up
+ setTimeout(function() {
+ if (!s.iframeTarget)
+ $io.remove();
+ xhr.responseXML = null;
+ }, 100);
+ }
+
+ var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
+ if (window.ActiveXObject) {
+ doc = new ActiveXObject('Microsoft.XMLDOM');
+ doc.async = 'false';
+ doc.loadXML(s);
+ }
+ else {
+ doc = (new DOMParser()).parseFromString(s, 'text/xml');
+ }
+ return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
+ };
+ var parseJSON = $.parseJSON || function(s) {
+ /*jslint evil:true */
+ return window['eval']('(' + s + ')');
+ };
+
+ var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4
+
+ var ct = xhr.getResponseHeader('content-type') || '',
+ xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
+ data = xml ? xhr.responseXML : xhr.responseText;
+
+ if (xml && data.documentElement.nodeName === 'parsererror') {
+ if ($.error)
+ $.error('parsererror');
+ }
+ if (s && s.dataFilter) {
+ data = s.dataFilter(data, type);
+ }
+ if (typeof data === 'string') {
+ if (type === 'json' || !type && ct.indexOf('json') >= 0) {
+ data = parseJSON(data);
+ } else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
+ $.globalEval(data);
+ }
+ }
+ return data;
+ };
+ }
+};
+
+/**
+ * ajaxForm() provides a mechanism for fully automating form submission.
+ *
+ * The advantages of using this method instead of ajaxSubmit() are:
+ *
+ * 1: This method will include coordinates for <input type="image" /> elements (if the element
+ * is used to submit the form).
+ * 2. This method will include the submit element's name/value data (for the element that was
+ * used to submit the form).
+ * 3. This method binds the submit() method to the form for you.
+ *
+ * The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
+ * passes the options argument along after properly binding events for submit elements and
+ * the form itself.
+ */
+$.fn.ajaxForm = function(options) {
+ options = options || {};
+ options.delegation = options.delegation && $.isFunction($.fn.on);
+
+ // in jQuery 1.3+ we can fix mistakes with the ready state
+ if (!options.delegation && this.length === 0) {
+ var o = { s: this.selector, c: this.context };
+ if (!$.isReady && o.s) {
+ log('DOM not ready, queuing ajaxForm');
+ $(function() {
+ $(o.s,o.c).ajaxForm(options);
+ });
+ return this;
+ }
+ // is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
+ log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
+ return this;
+ }
+
+ if ( options.delegation ) {
+ $(document)
+ .off('submit.form-plugin', this.selector, doAjaxSubmit)
+ .off('click.form-plugin', this.selector, captureSubmittingElement)
+ .on('submit.form-plugin', this.selector, options, doAjaxSubmit)
+ .on('click.form-plugin', this.selector, options, captureSubmittingElement);
+ return this;
+ }
+
+ return this.ajaxFormUnbind()
+ .bind('submit.form-plugin', options, doAjaxSubmit)
+ .bind('click.form-plugin', options, captureSubmittingElement);
+};
+
+// private event handlers
+function doAjaxSubmit(e) {
+ /*jshint validthis:true */
+ var options = e.data;
+ if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
+ e.preventDefault();
+ $(this).ajaxSubmit(options);
+ }
+}
+
+function captureSubmittingElement(e) {
+ /*jshint validthis:true */
+ var target = e.target;
+ var $el = $(target);
+ if (!($el.is(":submit,input:image"))) {
+ // is this a child element of the submit el? (ex: a span within a button)
+ var t = $el.closest(':submit');
+ if (t.length === 0) {
+ return;
+ }
+ target = t[0];
+ }
+ var form = this;
+ form.clk = target;
+ if (target.type == 'image') {
+ if (e.offsetX !== undefined) {
+ form.clk_x = e.offsetX;
+ form.clk_y = e.offsetY;
+ } else if (typeof $.fn.offset == 'function') {
+ var offset = $el.offset();
+ form.clk_x = e.pageX - offset.left;
+ form.clk_y = e.pageY - offset.top;
+ } else {
+ form.clk_x = e.pageX - target.offsetLeft;
+ form.clk_y = e.pageY - target.offsetTop;
+ }
+ }
+ // clear form vars
+ setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
+}
+
+
+// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
+$.fn.ajaxFormUnbind = function() {
+ return this.unbind('submit.form-plugin click.form-plugin');
+};
+
+/**
+ * formToArray() gathers form element data into an array of objects that can
+ * be passed to any of the following ajax functions: $.get, $.post, or load.
+ * Each object in the array has both a 'name' and 'value' property. An example of
+ * an array for a simple login form might be:
+ *
+ * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
+ *
+ * It is this array that is passed to pre-submit callback functions provided to the
+ * ajaxSubmit() and ajaxForm() methods.
+ */
+$.fn.formToArray = function(semantic, elements) {
+ var a = [];
+ if (this.length === 0) {
+ return a;
+ }
+
+ var form = this[0];
+ var els = semantic ? form.getElementsByTagName('*') : form.elements;
+ if (!els) {
+ return a;
+ }
+
+ var i,j,n,v,el,max,jmax;
+ for(i=0, max=els.length; i < max; i++) {
+ el = els[i];
+ n = el.name;
+ if (!n) {
+ continue;
+ }
+
+ if (semantic && form.clk && el.type == "image") {
+ // handle image inputs on the fly when semantic == true
+ if(!el.disabled && form.clk == el) {
+ a.push({name: n, value: $(el).val(), type: el.type });
+ a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
+ }
+ continue;
+ }
+
+ v = $.fieldValue(el, true);
+ if (v && v.constructor == Array) {
+ if (elements)
+ elements.push(el);
+ for(j=0, jmax=v.length; j < jmax; j++) {
+ a.push({name: n, value: v[j]});
+ }
+ }
+ else if (feature.fileapi && el.type == 'file' && !el.disabled) {
+ if (elements)
+ elements.push(el);
+ var files = el.files;
+ if (files.length) {
+ for (j=0; j < files.length; j++) {
+ a.push({name: n, value: files[j], type: el.type});
+ }
+ }
+ else {
+ // #180
+ a.push({ name: n, value: '', type: el.type });
+ }
+ }
+ else if (v !== null && typeof v != 'undefined') {
+ if (elements)
+ elements.push(el);
+ a.push({name: n, value: v, type: el.type, required: el.required});
+ }
+ }
+
+ if (!semantic && form.clk) {
+ // input type=='image' are not found in elements array! handle it here
+ var $input = $(form.clk), input = $input[0];
+ n = input.name;
+ if (n && !input.disabled && input.type == 'image') {
+ a.push({name: n, value: $input.val()});
+ a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
+ }
+ }
+ return a;
+};
+
+/**
+ * Serializes form data into a 'submittable' string. This method will return a string
+ * in the format: name1=value1&name2=value2
+ */
+$.fn.formSerialize = function(semantic) {
+ //hand off to jQuery.param for proper encoding
+ return $.param(this.formToArray(semantic));
+};
+
+/**
+ * Serializes all field elements in the jQuery object into a query string.
+ * This method will return a string in the format: name1=value1&name2=value2
+ */
+$.fn.fieldSerialize = function(successful) {
+ var a = [];
+ this.each(function() {
+ var n = this.name;
+ if (!n) {
+ return;
+ }
+ var v = $.fieldValue(this, successful);
+ if (v && v.constructor == Array) {
+ for (var i=0,max=v.length; i < max; i++) {
+ a.push({name: n, value: v[i]});
+ }
+ }
+ else if (v !== null && typeof v != 'undefined') {
+ a.push({name: this.name, value: v});
+ }
+ });
+ //hand off to jQuery.param for proper encoding
+ return $.param(a);
+};
+
+/**
+ * Returns the value(s) of the element in the matched set. For example, consider the following form:
+ *
+ * <form><fieldset>
+ * <input name="A" type="text" />
+ * <input name="A" type="text" />
+ * <input name="B" type="checkbox" value="B1" />
+ * <input name="B" type="checkbox" value="B2"/>
+ * <input name="C" type="radio" value="C1" />
+ * <input name="C" type="radio" value="C2" />
+ * </fieldset></form>
+ *
+ * var v = $(':text').fieldValue();
+ * // if no values are entered into the text inputs
+ * v == ['','']
+ * // if values entered into the text inputs are 'foo' and 'bar'
+ * v == ['foo','bar']
+ *
+ * var v = $(':checkbox').fieldValue();
+ * // if neither checkbox is checked
+ * v === undefined
+ * // if both checkboxes are checked
+ * v == ['B1', 'B2']
+ *
+ * var v = $(':radio').fieldValue();
+ * // if neither radio is checked
+ * v === undefined
+ * // if first radio is checked
+ * v == ['C1']
+ *
+ * The successful argument controls whether or not the field element must be 'successful'
+ * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
+ * The default value of the successful argument is true. If this value is false the value(s)
+ * for each element is returned.
+ *
+ * Note: This method *always* returns an array. If no valid value can be determined the
+ * array will be empty, otherwise it will contain one or more values.
+ */
+$.fn.fieldValue = function(successful) {
+ for (var val=[], i=0, max=this.length; i < max; i++) {
+ var el = this[i];
+ var v = $.fieldValue(el, successful);
+ if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
+ continue;
+ }
+ if (v.constructor == Array)
+ $.merge(val, v);
+ else
+ val.push(v);
+ }
+ return val;
+};
+
+/**
+ * Returns the value of the field element.
+ */
+$.fieldValue = function(el, successful) {
+ var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
+ if (successful === undefined) {
+ successful = true;
+ }
+
+ if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
+ (t == 'checkbox' || t == 'radio') && !el.checked ||
+ (t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
+ tag == 'select' && el.selectedIndex == -1)) {
+ return null;
+ }
+
+ if (tag == 'select') {
+ var index = el.selectedIndex;
+ if (index < 0) {
+ return null;
+ }
+ var a = [], ops = el.options;
+ var one = (t == 'select-one');
+ var max = (one ? index+1 : ops.length);
+ for(var i=(one ? index : 0); i < max; i++) {
+ var op = ops[i];
+ if (op.selected) {
+ var v = op.value;
+ if (!v) { // extra pain for IE...
+ v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
+ }
+ if (one) {
+ return v;
+ }
+ a.push(v);
+ }
+ }
+ return a;
+ }
+ return $(el).val();
+};
+
+/**
+ * Clears the form data. Takes the following actions on the form's input fields:
+ * - input text fields will have their 'value' property set to the empty string
+ * - select elements will have their 'selectedIndex' property set to -1
+ * - checkbox and radio inputs will have their 'checked' property set to false
+ * - inputs of type submit, button, reset, and hidden will *not* be effected
+ * - button elements will *not* be effected
+ */
+$.fn.clearForm = function(includeHidden) {
+ return this.each(function() {
+ $('input,select,textarea', this).clearFields(includeHidden);
+ });
+};
+
+/**
+ * Clears the selected form elements.
+ */
+$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
+ var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
+ return this.each(function() {
+ var t = this.type, tag = this.tagName.toLowerCase();
+ if (re.test(t) || tag == 'textarea') {
+ this.value = '';
+ }
+ else if (t == 'checkbox' || t == 'radio') {
+ this.checked = false;
+ }
+ else if (tag == 'select') {
+ this.selectedIndex = -1;
+ }
+ else if (includeHidden) {
+ // includeHidden can be the value true, or it can be a selector string
+ // indicating a special test; for example:
+ // $('#myForm').clearForm('.special:hidden')
+ // the above would clean hidden inputs that have the class of 'special'
+ if ( (includeHidden === true && /hidden/.test(t)) ||
+ (typeof includeHidden == 'string' && $(this).is(includeHidden)) )
+ this.value = '';
+ }
+ });
+};
+
+/**
+ * Resets the form data. Causes all form elements to be reset to their original value.
+ */
+$.fn.resetForm = function() {
+ return this.each(function() {
+ // guard against an input with the name of 'reset'
+ // note that IE reports the reset function as an 'object'
+ if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
+ this.reset();
+ }
+ });
+};
+
+/**
+ * Enables or disables any matching elements.
+ */
+$.fn.enable = function(b) {
+ if (b === undefined) {
+ b = true;
+ }
+ return this.each(function() {
+ this.disabled = !b;
+ });
+};
+
+/**
+ * Checks/unchecks any matching checkboxes or radio buttons and
+ * selects/deselects and matching option elements.
+ */
+$.fn.selected = function(select) {
+ if (select === undefined) {
+ select = true;
+ }
+ return this.each(function() {
+ var t = this.type;
+ if (t == 'checkbox' || t == 'radio') {
+ this.checked = select;
+ }
+ else if (this.tagName.toLowerCase() == 'option') {
+ var $sel = $(this).parent('select');
+ if (select && $sel[0] && $sel[0].type == 'select-one') {
+ // deselect all other options
+ $sel.find('option').selected(false);
+ }
+ this.selected = select;
+ }
+ });
+};
+
+// expose debug var
+$.fn.ajaxSubmit.debug = false;
+
+// helper fn for console logging
+function log() {
+ if (!$.fn.ajaxSubmit.debug)
+ return;
+ var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
+ if (window.console && window.console.log) {
+ window.console.log(msg);
+ }
+ else if (window.opera && window.opera.postError) {
+ window.opera.postError(msg);
+ }
+}
+
+})(jQuery);
--- /dev/null
+/**
+ * jQuery fullscreen plugin v2.0.0-git (9f8f97d127)
+ * https://github.com/theopolisme/jquery-fullscreen
+ *
+ * Copyright (c) 2013 Theopolisme <theopolismewiki@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+( function ( $ ) {
+ var setupFullscreen,
+ fsClass = 'jq-fullscreened';
+
+ /**
+ * On fullscreenchange, trigger a jq-fullscreen-change event
+ * The event is given an object, which contains the fullscreened DOM element (element), if any
+ * and a boolean value (fullscreen) indicating if we've entered or exited fullscreen mode
+ * Also remove the 'fullscreened' class from elements that are no longer fullscreen
+ */
+ function handleFullscreenChange () {
+ var fullscreenElement = document.fullscreenElement ||
+ document.mozFullScreenElement ||
+ document.webkitFullscreenElement ||
+ document.msFullscreenElement;
+
+ if ( !fullscreenElement ) {
+ $( '.' + fsClass ).data( 'isFullscreened', false ).removeClass( fsClass );
+ }
+
+ $( document ).trigger( $.Event( 'jq-fullscreen-change', { element: fullscreenElement, fullscreen: !!fullscreenElement } ) );
+ }
+
+ /**
+ * Enters full screen with the "this" element in focus.
+ * Check the .data( 'isFullscreened' ) of the return value to check
+ * success or failure, if you're into that sort of thing.
+ * @chainable
+ * @return {jQuery}
+ */
+ function enterFullscreen () {
+ var element = this.get(0),
+ $element = this.first();
+ if ( element ) {
+ if ( element.requestFullscreen ) {
+ element.requestFullscreen();
+ } else if ( element.mozRequestFullScreen ) {
+ element.mozRequestFullScreen();
+ } else if ( element.webkitRequestFullscreen ) {
+ element.webkitRequestFullscreen();
+ } else if ( element.msRequestFullscreen ) {
+ element.msRequestFullscreen();
+ } else {
+ // Unable to make fullscreen
+ $element.data( 'isFullscreened', false );
+ return this;
+ }
+ // Add the fullscreen class and data attribute to `element`
+ $element.addClass( fsClass ).data( 'isFullscreened', true );
+ return this;
+ } else {
+ $element.data( 'isFullscreened', false );
+ return this;
+ }
+ }
+
+ /**
+ * Brings the "this" element out of fullscreen.
+ * Check the .data( 'isFullscreened' ) of the return value to check
+ * success or failure, if you're into that sort of thing.
+ * @chainable
+ * @return {jQuery}
+ */
+ function exitFullscreen () {
+ var fullscreenElement = ( document.fullscreenElement ||
+ document.mozFullScreenElement ||
+ document.webkitFullscreenElement ||
+ document.msFullscreenElement );
+
+ // Ensure that we only exit fullscreen if exitFullscreen() is being called on the same element that is currently fullscreen
+ if ( fullscreenElement && this.get(0) === fullscreenElement ) {
+ if ( document.exitFullscreen ) {
+ document.exitFullscreen();
+ } else if ( document.mozCancelFullScreen ) {
+ document.mozCancelFullScreen();
+ } else if ( document.webkitCancelFullScreen ) {
+ document.webkitCancelFullScreen();
+ } else if ( document.msExitFullscreen ) {
+ document.msExitFullscreen();
+ } else {
+ // Unable to cancel fullscreen mode
+ return this;
+ }
+ // We don't need to remove the fullscreen class here,
+ // because it will be removed in handleFullscreenChange.
+ // But we should change the data on the element so the
+ // caller can check for success.
+ this.first().data( 'isFullscreened', false );
+ }
+
+ return this;
+ }
+
+ /**
+ * Set up fullscreen handling and install necessary event handlers.
+ * Return false if fullscreen is not supported.
+ */
+ setupFullscreen = function () {
+ if ( $.support.fullscreen ) {
+ // When the fullscreen mode is changed, trigger the
+ // fullscreen events (and when exiting,
+ // also remove the fullscreen class)
+ $( document ).on( 'fullscreenchange webkitfullscreenchange mozfullscreenchange MSFullscreenChange', handleFullscreenChange);
+ // Convenience wrapper so that one only needs to listen for
+ // 'fullscreenerror', not all of the prefixed versions
+ $( document ).on( 'webkitfullscreenerror mozfullscreenerror MSFullscreenError', function () {
+ $( document ).trigger( $.Event( 'fullscreenerror' ) );
+ } );
+ // Fullscreen has been set up, so always return true
+ setupFullscreen = function () { return true; };
+ return true;
+ } else {
+ // Always return false from now on, since fullscreen is not supported
+ setupFullscreen = function () { return false; };
+ return false;
+ }
+ };
+
+ /**
+ * Set up fullscreen handling if necessary, then make the first element
+ * matching the given selector fullscreen
+ * @chainable
+ * @return {jQuery}
+ */
+ $.fn.enterFullscreen = function () {
+ if ( setupFullscreen() ) {
+ $.fn.enterFullscreen = enterFullscreen;
+ return this.enterFullscreen();
+ } else {
+ $.fn.enterFullscreen = function () { return this; };
+ return this;
+ }
+ };
+
+ /**
+ * Set up fullscreen handling if necessary, then cancel fullscreen mode
+ * for the first element matching the given selector.
+ * @chainable
+ * @return {jQuery}
+ */
+ $.fn.exitFullscreen = function () {
+ if ( setupFullscreen() ) {
+ $.fn.exitFullscreen = exitFullscreen;
+ return this.exitFullscreen();
+ } else {
+ $.fn.exitFullscreen = function () { return this; };
+ return this;
+ }
+ };
+
+ $.support.fullscreen = document.fullscreenEnabled ||
+ document.webkitFullscreenEnabled ||
+ document.mozFullScreenEnabled ||
+ document.msFullscreenEnabled;
+}( jQuery ) );
--- /dev/null
+/**
+* hoverIntent is similar to jQuery's built-in "hover" function except that
+* instead of firing the onMouseOver event immediately, hoverIntent checks
+* to see if the user's mouse has slowed down (beneath the sensitivity
+* threshold) before firing the onMouseOver event.
+*
+* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
+* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
+*
+* hoverIntent is currently available for use in all personal or commercial
+* projects under both MIT and GPL licenses. This means that you can choose
+* the license that best suits your project, and use it accordingly.
+*
+* // basic usage (just like .hover) receives onMouseOver and onMouseOut functions
+* $("ul li").hoverIntent( showNav , hideNav );
+*
+* // advanced usage receives configuration object only
+* $("ul li").hoverIntent({
+* sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
+* interval: 100, // number = milliseconds of polling interval
+* over: showNav, // function = onMouseOver callback (required)
+* timeout: 0, // number = milliseconds delay before onMouseOut function call
+* out: hideNav // function = onMouseOut callback (required)
+* });
+*
+* @param f onMouseOver function || An object with configuration options
+* @param g onMouseOut function || Nothing (use configuration options object)
+* @author Brian Cherne <brian@cherne.net>
+*/
+(function($) {
+ $.fn.hoverIntent = function(f,g) {
+ // default configuration options
+ var cfg = {
+ sensitivity: 7,
+ interval: 100,
+ timeout: 0
+ };
+ // override configuration options with user supplied object
+ cfg = $.extend(cfg, g ? { over: f, out: g } : f );
+
+ // instantiate variables
+ // cX, cY = current X and Y position of mouse, updated by mousemove event
+ // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
+ var cX, cY, pX, pY;
+
+ // A private function for getting mouse position
+ var track = function(ev) {
+ cX = ev.pageX;
+ cY = ev.pageY;
+ };
+
+ // A private function for comparing current and previous mouse position
+ var compare = function(ev,ob) {
+ ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
+ // compare mouse positions to see if they've crossed the threshold
+ if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
+ $(ob).unbind("mousemove",track);
+ // set hoverIntent state to true (so mouseOut can be called)
+ ob.hoverIntent_s = 1;
+ return cfg.over.apply(ob,[ev]);
+ } else {
+ // set previous coordinates for next time
+ pX = cX; pY = cY;
+ // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
+ ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
+ }
+ };
+
+ // A private function for delaying the mouseOut function
+ var delay = function(ev,ob) {
+ ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
+ ob.hoverIntent_s = 0;
+ return cfg.out.apply(ob,[ev]);
+ };
+
+ // A private function for handling mouse 'hovering'
+ var handleHover = function(e) {
+ // next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
+ var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
+ while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
+ if ( p == this ) { return false; }
+
+ // copy objects to be passed into t (required for event object to be passed in IE)
+ var ev = $.extend({},e);
+ var ob = this;
+
+ // cancel hoverIntent timer if it exists
+ if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
+
+ // else e.type == "onmouseover"
+ if (e.type == "mouseover") {
+ // set "previous" X and Y position based on initial entry point
+ pX = ev.pageX; pY = ev.pageY;
+ // update "current" X and Y position based on mousemove
+ $(ob).bind("mousemove",track);
+ // start polling interval (self-calling timeout) to compare mouse coordinates over time
+ if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
+
+ // else e.type == "onmouseout"
+ } else {
+ // unbind expensive mousemove event
+ $(ob).unbind("mousemove",track);
+ // if hoverIntent state is true, then call the mouseOut function after the specified delay
+ if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
+ }
+ };
+
+ // bind the function to the two event listeners
+ return this.mouseover(handleHover).mouseout(handleHover);
+ };
+})(jQuery);
\ No newline at end of file
--- /dev/null
+/*
+ * ----------------------------- JSTORAGE -------------------------------------
+ * Simple local storage wrapper to save data on the browser side, supporting
+ * all major browsers - IE6+, Firefox2+, Safari4+, Chrome4+ and Opera 10.5+
+ *
+ * Author: Andris Reinman, andris.reinman@gmail.com
+ * Project homepage: www.jstorage.info
+ *
+ * Licensed under Unlicense:
+ *
+ * This is free and unencumbered software released into the public domain.
+ *
+ * Anyone is free to copy, modify, publish, use, compile, sell, or
+ * distribute this software, either in source code form or as a compiled
+ * binary, for any purpose, commercial or non-commercial, and by any
+ * means.
+ *
+ * In jurisdictions that recognize copyright laws, the author or authors
+ * of this software dedicate any and all copyright interest in the
+ * software to the public domain. We make this dedication for the benefit
+ * of the public at large and to the detriment of our heirs and
+ * successors. We intend this dedication to be an overt act of
+ * relinquishment in perpetuity of all present and future rights to this
+ * software under copyright law.
+ *
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * For more information, please refer to <http://unlicense.org/>
+ */
+
+/* global ActiveXObject: false */
+/* jshint browser: true */
+
+(function() {
+ 'use strict';
+
+ var
+ /* jStorage version */
+ JSTORAGE_VERSION = '0.4.12',
+
+ /* detect a dollar object or create one if not found */
+ $ = window.jQuery || window.$ || (window.$ = {}),
+
+ /* check for a JSON handling support */
+ JSON = {
+ parse: window.JSON && (window.JSON.parse || window.JSON.decode) ||
+ String.prototype.evalJSON && function(str) {
+ return String(str).evalJSON();
+ } ||
+ $.parseJSON ||
+ $.evalJSON,
+ stringify: Object.toJSON ||
+ window.JSON && (window.JSON.stringify || window.JSON.encode) ||
+ $.toJSON
+ };
+
+ // Break if no JSON support was found
+ if (typeof JSON.parse !== 'function' || typeof JSON.stringify !== 'function') {
+ throw new Error('No JSON support found, include //cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js to page');
+ }
+
+ var
+ /* This is the object, that holds the cached values */
+ _storage = {
+ __jstorage_meta: {
+ CRC32: {}
+ }
+ },
+
+ /* Actual browser storage (localStorage or globalStorage['domain']) */
+ _storage_service = {
+ jStorage: '{}'
+ },
+
+ /* DOM element for older IE versions, holds userData behavior */
+ _storage_elm = null,
+
+ /* How much space does the storage take */
+ _storage_size = 0,
+
+ /* which backend is currently used */
+ _backend = false,
+
+ /* onchange observers */
+ _observers = {},
+
+ /* timeout to wait after onchange event */
+ _observer_timeout = false,
+
+ /* last update time */
+ _observer_update = 0,
+
+ /* pubsub observers */
+ _pubsub_observers = {},
+
+ /* skip published items older than current timestamp */
+ _pubsub_last = +new Date(),
+
+ /* Next check for TTL */
+ _ttl_timeout,
+
+ /**
+ * XML encoding and decoding as XML nodes can't be JSON'ized
+ * XML nodes are encoded and decoded if the node is the value to be saved
+ * but not if it's as a property of another object
+ * Eg. -
+ * $.jStorage.set('key', xmlNode); // IS OK
+ * $.jStorage.set('key', {xml: xmlNode}); // NOT OK
+ */
+ _XMLService = {
+
+ /**
+ * Validates a XML node to be XML
+ * based on jQuery.isXML function
+ */
+ isXML: function(elm) {
+ var documentElement = (elm ? elm.ownerDocument || elm : 0).documentElement;
+ return documentElement ? documentElement.nodeName !== 'HTML' : false;
+ },
+
+ /**
+ * Encodes a XML node to string
+ * based on http://www.mercurytide.co.uk/news/article/issues-when-working-ajax/
+ */
+ encode: function(xmlNode) {
+ if (!this.isXML(xmlNode)) {
+ return false;
+ }
+ try { // Mozilla, Webkit, Opera
+ return new XMLSerializer().serializeToString(xmlNode);
+ } catch (E1) {
+ try { // IE
+ return xmlNode.xml;
+ } catch (E2) {}
+ }
+ return false;
+ },
+
+ /**
+ * Decodes a XML node from string
+ * loosely based on http://outwestmedia.com/jquery-plugins/xmldom/
+ */
+ decode: function(xmlString) {
+ var dom_parser = ('DOMParser' in window && (new DOMParser()).parseFromString) ||
+ (window.ActiveXObject && function(_xmlString) {
+ var xml_doc = new ActiveXObject('Microsoft.XMLDOM');
+ xml_doc.async = 'false';
+ xml_doc.loadXML(_xmlString);
+ return xml_doc;
+ }),
+ resultXML;
+ if (!dom_parser) {
+ return false;
+ }
+ resultXML = dom_parser.call('DOMParser' in window && (new DOMParser()) || window, xmlString, 'text/xml');
+ return this.isXML(resultXML) ? resultXML : false;
+ }
+ };
+
+
+ ////////////////////////// PRIVATE METHODS ////////////////////////
+
+ /**
+ * Initialization function. Detects if the browser supports DOM Storage
+ * or userData behavior and behaves accordingly.
+ */
+ function _init() {
+ /* Check if browser supports localStorage */
+ var localStorageReallyWorks = false;
+ if ('localStorage' in window) {
+ try {
+ window.localStorage.setItem('_tmptest', 'tmpval');
+ localStorageReallyWorks = true;
+ window.localStorage.removeItem('_tmptest');
+ } catch (BogusQuotaExceededErrorOnIos5) {
+ // Thanks be to iOS5 Private Browsing mode which throws
+ // QUOTA_EXCEEDED_ERRROR DOM Exception 22.
+ }
+ }
+
+ if (localStorageReallyWorks) {
+ try {
+ if (window.localStorage) {
+ _storage_service = window.localStorage;
+ _backend = 'localStorage';
+ _observer_update = _storage_service.jStorage_update;
+ }
+ } catch (E3) { /* Firefox fails when touching localStorage and cookies are disabled */ }
+ }
+ /* Check if browser supports globalStorage */
+ else if ('globalStorage' in window) {
+ try {
+ if (window.globalStorage) {
+ if (window.location.hostname == 'localhost') {
+ _storage_service = window.globalStorage['localhost.localdomain'];
+ } else {
+ _storage_service = window.globalStorage[window.location.hostname];
+ }
+ _backend = 'globalStorage';
+ _observer_update = _storage_service.jStorage_update;
+ }
+ } catch (E4) { /* Firefox fails when touching localStorage and cookies are disabled */ }
+ }
+ /* Check if browser supports userData behavior */
+ else {
+ _storage_elm = document.createElement('link');
+ if (_storage_elm.addBehavior) {
+
+ /* Use a DOM element to act as userData storage */
+ _storage_elm.style.behavior = 'url(#default#userData)';
+
+ /* userData element needs to be inserted into the DOM! */
+ document.getElementsByTagName('head')[0].appendChild(_storage_elm);
+
+ try {
+ _storage_elm.load('jStorage');
+ } catch (E) {
+ // try to reset cache
+ _storage_elm.setAttribute('jStorage', '{}');
+ _storage_elm.save('jStorage');
+ _storage_elm.load('jStorage');
+ }
+
+ var data = '{}';
+ try {
+ data = _storage_elm.getAttribute('jStorage');
+ } catch (E5) {}
+
+ try {
+ _observer_update = _storage_elm.getAttribute('jStorage_update');
+ } catch (E6) {}
+
+ _storage_service.jStorage = data;
+ _backend = 'userDataBehavior';
+ } else {
+ _storage_elm = null;
+ return;
+ }
+ }
+
+ // Load data from storage
+ _load_storage();
+
+ // remove dead keys
+ _handleTTL();
+
+ // start listening for changes
+ _setupObserver();
+
+ // initialize publish-subscribe service
+ _handlePubSub();
+
+ // handle cached navigation
+ if ('addEventListener' in window) {
+ window.addEventListener('pageshow', function(event) {
+ if (event.persisted) {
+ _storageObserver();
+ }
+ }, false);
+ }
+ }
+
+ /**
+ * Reload data from storage when needed
+ */
+ function _reloadData() {
+ var data = '{}';
+
+ if (_backend == 'userDataBehavior') {
+ _storage_elm.load('jStorage');
+
+ try {
+ data = _storage_elm.getAttribute('jStorage');
+ } catch (E5) {}
+
+ try {
+ _observer_update = _storage_elm.getAttribute('jStorage_update');
+ } catch (E6) {}
+
+ _storage_service.jStorage = data;
+ }
+
+ _load_storage();
+
+ // remove dead keys
+ _handleTTL();
+
+ _handlePubSub();
+ }
+
+ /**
+ * Sets up a storage change observer
+ */
+ function _setupObserver() {
+ if (_backend == 'localStorage' || _backend == 'globalStorage') {
+ if ('addEventListener' in window) {
+ window.addEventListener('storage', _storageObserver, false);
+ } else {
+ document.attachEvent('onstorage', _storageObserver);
+ }
+ } else if (_backend == 'userDataBehavior') {
+ setInterval(_storageObserver, 1000);
+ }
+ }
+
+ /**
+ * Fired on any kind of data change, needs to check if anything has
+ * really been changed
+ */
+ function _storageObserver() {
+ var updateTime;
+ // cumulate change notifications with timeout
+ clearTimeout(_observer_timeout);
+ _observer_timeout = setTimeout(function() {
+
+ if (_backend == 'localStorage' || _backend == 'globalStorage') {
+ updateTime = _storage_service.jStorage_update;
+ } else if (_backend == 'userDataBehavior') {
+ _storage_elm.load('jStorage');
+ try {
+ updateTime = _storage_elm.getAttribute('jStorage_update');
+ } catch (E5) {}
+ }
+
+ if (updateTime && updateTime != _observer_update) {
+ _observer_update = updateTime;
+ _checkUpdatedKeys();
+ }
+
+ }, 25);
+ }
+
+ /**
+ * Reloads the data and checks if any keys are changed
+ */
+ function _checkUpdatedKeys() {
+ var oldCrc32List = JSON.parse(JSON.stringify(_storage.__jstorage_meta.CRC32)),
+ newCrc32List;
+
+ _reloadData();
+ newCrc32List = JSON.parse(JSON.stringify(_storage.__jstorage_meta.CRC32));
+
+ var key,
+ updated = [],
+ removed = [];
+
+ for (key in oldCrc32List) {
+ if (oldCrc32List.hasOwnProperty(key)) {
+ if (!newCrc32List[key]) {
+ removed.push(key);
+ continue;
+ }
+ if (oldCrc32List[key] != newCrc32List[key] && String(oldCrc32List[key]).substr(0, 2) == '2.') {
+ updated.push(key);
+ }
+ }
+ }
+
+ for (key in newCrc32List) {
+ if (newCrc32List.hasOwnProperty(key)) {
+ if (!oldCrc32List[key]) {
+ updated.push(key);
+ }
+ }
+ }
+
+ _fireObservers(updated, 'updated');
+ _fireObservers(removed, 'deleted');
+ }
+
+ /**
+ * Fires observers for updated keys
+ *
+ * @param {Array|String} keys Array of key names or a key
+ * @param {String} action What happened with the value (updated, deleted, flushed)
+ */
+ function _fireObservers(keys, action) {
+ keys = [].concat(keys || []);
+
+ var i, j, len, jlen;
+
+ if (action == 'flushed') {
+ keys = [];
+ for (var key in _observers) {
+ if (_observers.hasOwnProperty(key)) {
+ keys.push(key);
+ }
+ }
+ action = 'deleted';
+ }
+ for (i = 0, len = keys.length; i < len; i++) {
+ if (_observers[keys[i]]) {
+ for (j = 0, jlen = _observers[keys[i]].length; j < jlen; j++) {
+ _observers[keys[i]][j](keys[i], action);
+ }
+ }
+ if (_observers['*']) {
+ for (j = 0, jlen = _observers['*'].length; j < jlen; j++) {
+ _observers['*'][j](keys[i], action);
+ }
+ }
+ }
+ }
+
+ /**
+ * Publishes key change to listeners
+ */
+ function _publishChange() {
+ var updateTime = (+new Date()).toString();
+
+ if (_backend == 'localStorage' || _backend == 'globalStorage') {
+ try {
+ _storage_service.jStorage_update = updateTime;
+ } catch (E8) {
+ // safari private mode has been enabled after the jStorage initialization
+ _backend = false;
+ }
+ } else if (_backend == 'userDataBehavior') {
+ _storage_elm.setAttribute('jStorage_update', updateTime);
+ _storage_elm.save('jStorage');
+ }
+
+ _storageObserver();
+ }
+
+ /**
+ * Loads the data from the storage based on the supported mechanism
+ */
+ function _load_storage() {
+ /* if jStorage string is retrieved, then decode it */
+ if (_storage_service.jStorage) {
+ try {
+ _storage = JSON.parse(String(_storage_service.jStorage));
+ } catch (E6) {
+ _storage_service.jStorage = '{}';
+ }
+ } else {
+ _storage_service.jStorage = '{}';
+ }
+ _storage_size = _storage_service.jStorage ? String(_storage_service.jStorage).length : 0;
+
+ if (!_storage.__jstorage_meta) {
+ _storage.__jstorage_meta = {};
+ }
+ if (!_storage.__jstorage_meta.CRC32) {
+ _storage.__jstorage_meta.CRC32 = {};
+ }
+ }
+
+ /**
+ * This functions provides the 'save' mechanism to store the jStorage object
+ */
+ function _save() {
+ _dropOldEvents(); // remove expired events
+ try {
+ _storage_service.jStorage = JSON.stringify(_storage);
+ // If userData is used as the storage engine, additional
+ if (_storage_elm) {
+ _storage_elm.setAttribute('jStorage', _storage_service.jStorage);
+ _storage_elm.save('jStorage');
+ }
+ _storage_size = _storage_service.jStorage ? String(_storage_service.jStorage).length : 0;
+ } catch (E7) { /* probably cache is full, nothing is saved this way*/ }
+ }
+
+ /**
+ * Function checks if a key is set and is string or numberic
+ *
+ * @param {String} key Key name
+ */
+ function _checkKey(key) {
+ if (typeof key != 'string' && typeof key != 'number') {
+ throw new TypeError('Key name must be string or numeric');
+ }
+ if (key == '__jstorage_meta') {
+ throw new TypeError('Reserved key name');
+ }
+ return true;
+ }
+
+ /**
+ * Removes expired keys
+ */
+ function _handleTTL() {
+ var curtime, i, TTL, CRC32, nextExpire = Infinity,
+ changed = false,
+ deleted = [];
+
+ clearTimeout(_ttl_timeout);
+
+ if (!_storage.__jstorage_meta || typeof _storage.__jstorage_meta.TTL != 'object') {
+ // nothing to do here
+ return;
+ }
+
+ curtime = +new Date();
+ TTL = _storage.__jstorage_meta.TTL;
+
+ CRC32 = _storage.__jstorage_meta.CRC32;
+ for (i in TTL) {
+ if (TTL.hasOwnProperty(i)) {
+ if (TTL[i] <= curtime) {
+ delete TTL[i];
+ delete CRC32[i];
+ delete _storage[i];
+ changed = true;
+ deleted.push(i);
+ } else if (TTL[i] < nextExpire) {
+ nextExpire = TTL[i];
+ }
+ }
+ }
+
+ // set next check
+ if (nextExpire != Infinity) {
+ _ttl_timeout = setTimeout(_handleTTL, Math.min(nextExpire - curtime, 0x7FFFFFFF));
+ }
+
+ // save changes
+ if (changed) {
+ _save();
+ _publishChange();
+ _fireObservers(deleted, 'deleted');
+ }
+ }
+
+ /**
+ * Checks if there's any events on hold to be fired to listeners
+ */
+ function _handlePubSub() {
+ var i, len;
+ if (!_storage.__jstorage_meta.PubSub) {
+ return;
+ }
+ var pubelm,
+ _pubsubCurrent = _pubsub_last,
+ needFired = [];
+
+ for (i = len = _storage.__jstorage_meta.PubSub.length - 1; i >= 0; i--) {
+ pubelm = _storage.__jstorage_meta.PubSub[i];
+ if (pubelm[0] > _pubsub_last) {
+ _pubsubCurrent = pubelm[0];
+ needFired.unshift(pubelm);
+ }
+ }
+
+ for (i = needFired.length - 1; i >= 0; i--) {
+ _fireSubscribers(needFired[i][1], needFired[i][2]);
+ }
+
+ _pubsub_last = _pubsubCurrent;
+ }
+
+ /**
+ * Fires all subscriber listeners for a pubsub channel
+ *
+ * @param {String} channel Channel name
+ * @param {Mixed} payload Payload data to deliver
+ */
+ function _fireSubscribers(channel, payload) {
+ if (_pubsub_observers[channel]) {
+ for (var i = 0, len = _pubsub_observers[channel].length; i < len; i++) {
+ // send immutable data that can't be modified by listeners
+ try {
+ _pubsub_observers[channel][i](channel, JSON.parse(JSON.stringify(payload)));
+ } catch (E) {}
+ }
+ }
+ }
+
+ /**
+ * Remove old events from the publish stream (at least 2sec old)
+ */
+ function _dropOldEvents() {
+ if (!_storage.__jstorage_meta.PubSub) {
+ return;
+ }
+
+ var retire = +new Date() - 2000;
+
+ for (var i = 0, len = _storage.__jstorage_meta.PubSub.length; i < len; i++) {
+ if (_storage.__jstorage_meta.PubSub[i][0] <= retire) {
+ // deleteCount is needed for IE6
+ _storage.__jstorage_meta.PubSub.splice(i, _storage.__jstorage_meta.PubSub.length - i);
+ break;
+ }
+ }
+
+ if (!_storage.__jstorage_meta.PubSub.length) {
+ delete _storage.__jstorage_meta.PubSub;
+ }
+
+ }
+
+ /**
+ * Publish payload to a channel
+ *
+ * @param {String} channel Channel name
+ * @param {Mixed} payload Payload to send to the subscribers
+ */
+ function _publish(channel, payload) {
+ if (!_storage.__jstorage_meta) {
+ _storage.__jstorage_meta = {};
+ }
+ if (!_storage.__jstorage_meta.PubSub) {
+ _storage.__jstorage_meta.PubSub = [];
+ }
+
+ _storage.__jstorage_meta.PubSub.unshift([+new Date(), channel, payload]);
+
+ _save();
+ _publishChange();
+ }
+
+
+ /**
+ * JS Implementation of MurmurHash2
+ *
+ * SOURCE: https://github.com/garycourt/murmurhash-js (MIT licensed)
+ *
+ * @author <a href='mailto:gary.court@gmail.com'>Gary Court</a>
+ * @see http://github.com/garycourt/murmurhash-js
+ * @author <a href='mailto:aappleby@gmail.com'>Austin Appleby</a>
+ * @see http://sites.google.com/site/murmurhash/
+ *
+ * @param {string} str ASCII only
+ * @param {number} seed Positive integer only
+ * @return {number} 32-bit positive integer hash
+ */
+
+ function murmurhash2_32_gc(str, seed) {
+ var
+ l = str.length,
+ h = seed ^ l,
+ i = 0,
+ k;
+
+ while (l >= 4) {
+ k =
+ ((str.charCodeAt(i) & 0xff)) |
+ ((str.charCodeAt(++i) & 0xff) << 8) |
+ ((str.charCodeAt(++i) & 0xff) << 16) |
+ ((str.charCodeAt(++i) & 0xff) << 24);
+
+ k = (((k & 0xffff) * 0x5bd1e995) + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16));
+ k ^= k >>> 24;
+ k = (((k & 0xffff) * 0x5bd1e995) + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16));
+
+ h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16)) ^ k;
+
+ l -= 4;
+ ++i;
+ }
+
+ switch (l) {
+ case 3:
+ h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
+ /* falls through */
+ case 2:
+ h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
+ /* falls through */
+ case 1:
+ h ^= (str.charCodeAt(i) & 0xff);
+ h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16));
+ }
+
+ h ^= h >>> 13;
+ h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16));
+ h ^= h >>> 15;
+
+ return h >>> 0;
+ }
+
+ ////////////////////////// PUBLIC INTERFACE /////////////////////////
+
+ $.jStorage = {
+ /* Version number */
+ version: JSTORAGE_VERSION,
+
+ /**
+ * Sets a key's value.
+ *
+ * @param {String} key Key to set. If this value is not set or not
+ * a string an exception is raised.
+ * @param {Mixed} value Value to set. This can be any value that is JSON
+ * compatible (Numbers, Strings, Objects etc.).
+ * @param {Object} [options] - possible options to use
+ * @param {Number} [options.TTL] - optional TTL value, in milliseconds
+ * @return {Mixed} the used value
+ */
+ set: function(key, value, options) {
+ _checkKey(key);
+
+ options = options || {};
+
+ // undefined values are deleted automatically
+ if (typeof value == 'undefined') {
+ this.deleteKey(key);
+ return value;
+ }
+
+ if (_XMLService.isXML(value)) {
+ value = {
+ _is_xml: true,
+ xml: _XMLService.encode(value)
+ };
+ } else if (typeof value == 'function') {
+ return undefined; // functions can't be saved!
+ } else if (value && typeof value == 'object') {
+ // clone the object before saving to _storage tree
+ value = JSON.parse(JSON.stringify(value));
+ }
+
+ _storage[key] = value;
+
+ _storage.__jstorage_meta.CRC32[key] = '2.' + murmurhash2_32_gc(JSON.stringify(value), 0x9747b28c);
+
+ this.setTTL(key, options.TTL || 0); // also handles saving and _publishChange
+
+ _fireObservers(key, 'updated');
+ return value;
+ },
+
+ /**
+ * Looks up a key in cache
+ *
+ * @param {String} key - Key to look up.
+ * @param {mixed} def - Default value to return, if key didn't exist.
+ * @return {Mixed} the key value, default value or null
+ */
+ get: function(key, def) {
+ _checkKey(key);
+ if (key in _storage) {
+ if (_storage[key] && typeof _storage[key] == 'object' && _storage[key]._is_xml) {
+ return _XMLService.decode(_storage[key].xml);
+ } else {
+ return _storage[key];
+ }
+ }
+ return typeof(def) == 'undefined' ? null : def;
+ },
+
+ /**
+ * Deletes a key from cache.
+ *
+ * @param {String} key - Key to delete.
+ * @return {Boolean} true if key existed or false if it didn't
+ */
+ deleteKey: function(key) {
+ _checkKey(key);
+ if (key in _storage) {
+ delete _storage[key];
+ // remove from TTL list
+ if (typeof _storage.__jstorage_meta.TTL == 'object' &&
+ key in _storage.__jstorage_meta.TTL) {
+ delete _storage.__jstorage_meta.TTL[key];
+ }
+
+ delete _storage.__jstorage_meta.CRC32[key];
+
+ _save();
+ _publishChange();
+ _fireObservers(key, 'deleted');
+ return true;
+ }
+ return false;
+ },
+
+ /**
+ * Sets a TTL for a key, or remove it if ttl value is 0 or below
+ *
+ * @param {String} key - key to set the TTL for
+ * @param {Number} ttl - TTL timeout in milliseconds
+ * @return {Boolean} true if key existed or false if it didn't
+ */
+ setTTL: function(key, ttl) {
+ var curtime = +new Date();
+ _checkKey(key);
+ ttl = Number(ttl) || 0;
+ if (key in _storage) {
+
+ if (!_storage.__jstorage_meta.TTL) {
+ _storage.__jstorage_meta.TTL = {};
+ }
+
+ // Set TTL value for the key
+ if (ttl > 0) {
+ _storage.__jstorage_meta.TTL[key] = curtime + ttl;
+ } else {
+ delete _storage.__jstorage_meta.TTL[key];
+ }
+
+ _save();
+
+ _handleTTL();
+
+ _publishChange();
+ return true;
+ }
+ return false;
+ },
+
+ /**
+ * Gets remaining TTL (in milliseconds) for a key or 0 when no TTL has been set
+ *
+ * @param {String} key Key to check
+ * @return {Number} Remaining TTL in milliseconds
+ */
+ getTTL: function(key) {
+ var curtime = +new Date(),
+ ttl;
+ _checkKey(key);
+ if (key in _storage && _storage.__jstorage_meta.TTL && _storage.__jstorage_meta.TTL[key]) {
+ ttl = _storage.__jstorage_meta.TTL[key] - curtime;
+ return ttl || 0;
+ }
+ return 0;
+ },
+
+ /**
+ * Deletes everything in cache.
+ *
+ * @return {Boolean} Always true
+ */
+ flush: function() {
+ _storage = {
+ __jstorage_meta: {
+ CRC32: {}
+ }
+ };
+ _save();
+ _publishChange();
+ _fireObservers(null, 'flushed');
+ return true;
+ },
+
+ /**
+ * Returns a read-only copy of _storage
+ *
+ * @return {Object} Read-only copy of _storage
+ */
+ storageObj: function() {
+ function F() {}
+ F.prototype = _storage;
+ return new F();
+ },
+
+ /**
+ * Returns an index of all used keys as an array
+ * ['key1', 'key2',..'keyN']
+ *
+ * @return {Array} Used keys
+ */
+ index: function() {
+ var index = [],
+ i;
+ for (i in _storage) {
+ if (_storage.hasOwnProperty(i) && i != '__jstorage_meta') {
+ index.push(i);
+ }
+ }
+ return index;
+ },
+
+ /**
+ * How much space in bytes does the storage take?
+ *
+ * @return {Number} Storage size in chars (not the same as in bytes,
+ * since some chars may take several bytes)
+ */
+ storageSize: function() {
+ return _storage_size;
+ },
+
+ /**
+ * Which backend is currently in use?
+ *
+ * @return {String} Backend name
+ */
+ currentBackend: function() {
+ return _backend;
+ },
+
+ /**
+ * Test if storage is available
+ *
+ * @return {Boolean} True if storage can be used
+ */
+ storageAvailable: function() {
+ return !!_backend;
+ },
+
+ /**
+ * Register change listeners
+ *
+ * @param {String} key Key name
+ * @param {Function} callback Function to run when the key changes
+ */
+ listenKeyChange: function(key, callback) {
+ _checkKey(key);
+ if (!_observers[key]) {
+ _observers[key] = [];
+ }
+ _observers[key].push(callback);
+ },
+
+ /**
+ * Remove change listeners
+ *
+ * @param {String} key Key name to unregister listeners against
+ * @param {Function} [callback] If set, unregister the callback, if not - unregister all
+ */
+ stopListening: function(key, callback) {
+ _checkKey(key);
+
+ if (!_observers[key]) {
+ return;
+ }
+
+ if (!callback) {
+ delete _observers[key];
+ return;
+ }
+
+ for (var i = _observers[key].length - 1; i >= 0; i--) {
+ if (_observers[key][i] == callback) {
+ _observers[key].splice(i, 1);
+ }
+ }
+ },
+
+ /**
+ * Subscribe to a Publish/Subscribe event stream
+ *
+ * @param {String} channel Channel name
+ * @param {Function} callback Function to run when the something is published to the channel
+ */
+ subscribe: function(channel, callback) {
+ channel = (channel || '').toString();
+ if (!channel) {
+ throw new TypeError('Channel not defined');
+ }
+ if (!_pubsub_observers[channel]) {
+ _pubsub_observers[channel] = [];
+ }
+ _pubsub_observers[channel].push(callback);
+ },
+
+ /**
+ * Publish data to an event stream
+ *
+ * @param {String} channel Channel name
+ * @param {Mixed} payload Payload to deliver
+ */
+ publish: function(channel, payload) {
+ channel = (channel || '').toString();
+ if (!channel) {
+ throw new TypeError('Channel not defined');
+ }
+
+ _publish(channel, payload);
+ },
+
+ /**
+ * Reloads the data from browser storage
+ */
+ reInit: function() {
+ _reloadData();
+ },
+
+ /**
+ * Removes reference from global objects and saves it as jStorage
+ *
+ * @param {Boolean} option if needed to save object as simple 'jStorage' in windows context
+ */
+ noConflict: function(saveInGlobal) {
+ delete window.$.jStorage;
+
+ if (saveInGlobal) {
+ window.jStorage = this;
+ }
+
+ return this;
+ }
+ };
+
+ // Initialize jStorage
+ _init();
+
+})();
--- /dev/null
+/*!
+ * MockJax - jQuery Plugin to Mock Ajax requests
+ *
+ * Version: 1.4.0
+ * Released: 2011-02-04
+ * Source: http://github.com/appendto/jquery-mockjax
+ * Docs: http://enterprisejquery.com/2010/07/mock-your-ajax-requests-with-mockjax-for-rapid-development
+ * Plugin: mockjax
+ * Author: Jonathan Sharp (http://jdsharp.com)
+ * License: MIT,GPL
+ *
+ * Copyright (c) 2010 appendTo LLC.
+ * Dual licensed under the MIT or GPL licenses.
+ * http://appendto.com/open-source-licenses
+ */
+(function($) {
+ var _ajax = $.ajax,
+ mockHandlers = [];
+
+ function parseXML(xml) {
+ if ( window['DOMParser'] == undefined && window.ActiveXObject ) {
+ DOMParser = function() { };
+ DOMParser.prototype.parseFromString = function( xmlString ) {
+ var doc = new ActiveXObject('Microsoft.XMLDOM');
+ doc.async = 'false';
+ doc.loadXML( xmlString );
+ return doc;
+ };
+ }
+
+ try {
+ var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' );
+ if ( $.isXMLDoc( xmlDoc ) ) {
+ var err = $('parsererror', xmlDoc);
+ if ( err.length == 1 ) {
+ throw('Error: ' + $(xmlDoc).text() );
+ }
+ } else {
+ throw('Unable to parse XML');
+ }
+ } catch( e ) {
+ var msg = ( e.name == undefined ? e : e.name + ': ' + e.message );
+ $(document).trigger('xmlParseError', [ msg ]);
+ return undefined;
+ }
+ return xmlDoc;
+ }
+
+ $.extend({
+ ajax: function(origSettings) {
+ var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
+ mock = false;
+ // Iterate over our mock handlers (in registration order) until we find
+ // one that is willing to intercept the request
+ $.each(mockHandlers, function(k, v) {
+ if ( !mockHandlers[k] ) {
+ return;
+ }
+ var m = null;
+ // If the mock was registered with a function, let the function decide if we
+ // want to mock this request
+ if ( $.isFunction(mockHandlers[k]) ) {
+ m = mockHandlers[k](s);
+ } else {
+ m = mockHandlers[k];
+ // Inspect the URL of the request and check if the mock handler's url
+ // matches the url for this ajax request
+ if ( $.isFunction(m.url.test) ) {
+ // The user provided a regex for the url, test it
+ if ( !m.url.test( s.url ) ) {
+ m = null;
+ }
+ } else {
+ // Look for a simple wildcard '*' or a direct URL match
+ var star = m.url.indexOf('*');
+ if ( ( m.url != '*' && m.url != s.url && star == -1 ) ||
+ ( star > -1 && m.url.substr(0, star) != s.url.substr(0, star) ) ) {
+ // The url we tested did not match the wildcard *
+ m = null;
+ }
+ }
+ if ( m ) {
+ // Inspect the data submitted in the request (either POST body or GET query string)
+ if ( m.data && s.data ) {
+ var identical = false;
+ // Deep inspect the identity of the objects
+ (function ident(mock, live) {
+ // Test for situations where the data is a querystring (not an object)
+ if (typeof live === 'string') {
+ // Querystring may be a regex
+ identical = $.isFunction( mock.test ) ? mock.test(live) : mock == live;
+ return identical;
+ }
+ $.each(mock, function(k, v) {
+ if ( live[k] === undefined ) {
+ identical = false;
+ return false;
+ } else {
+ identical = true;
+ if ( typeof live[k] == 'object' ) {
+ return ident(mock[k], live[k]);
+ } else {
+ if ( $.isFunction( mock[k].test ) ) {
+ identical = mock[k].test(live[k]);
+ } else {
+ identical = ( mock[k] == live[k] );
+ }
+ return identical;
+ }
+ }
+ });
+ })(m.data, s.data);
+ // They're not identical, do not mock this request
+ if ( identical == false ) {
+ m = null;
+ }
+ }
+ // Inspect the request type
+ if ( m && m.type && m.type != s.type ) {
+ // The request type doesn't match (GET vs. POST)
+ m = null;
+ }
+ }
+ }
+ if ( m ) {
+ mock = true;
+
+ // Handle console logging
+ var c = $.extend({}, $.mockjaxSettings, m);
+ if ( c.log && $.isFunction(c.log) ) {
+ c.log('MOCK ' + s.type.toUpperCase() + ': ' + s.url, $.extend({}, s));
+ }
+
+ var jsre = /=\?(&|$)/, jsc = (new Date()).getTime();
+
+ // Handle JSONP Parameter Callbacks, we need to replicate some of the jQuery core here
+ // because there isn't an easy hook for the cross domain script tag of jsonp
+ if ( s.dataType === "jsonp" ) {
+ if ( s.type.toUpperCase() === "GET" ) {
+ if ( !jsre.test( s.url ) ) {
+ s.url += (rquery.test( s.url ) ? "&" : "?") + (s.jsonp || "callback") + "=?";
+ }
+ } else if ( !s.data || !jsre.test(s.data) ) {
+ s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
+ }
+ s.dataType = "json";
+ }
+
+ // Build temporary JSONP function
+ if ( s.dataType === "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) {
+ jsonp = s.jsonpCallback || ("jsonp" + jsc++);
+
+ // Replace the =? sequence both in the query string and the data
+ if ( s.data ) {
+ s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
+ }
+
+ s.url = s.url.replace(jsre, "=" + jsonp + "$1");
+
+ // We need to make sure
+ // that a JSONP style response is executed properly
+ s.dataType = "script";
+
+ // Handle JSONP-style loading
+ window[ jsonp ] = window[ jsonp ] || function( tmp ) {
+ data = tmp;
+ success();
+ complete();
+ // Garbage collect
+ window[ jsonp ] = undefined;
+
+ try {
+ delete window[ jsonp ];
+ } catch(e) {}
+
+ if ( head ) {
+ head.removeChild( script );
+ }
+ };
+ }
+
+ var rurl = /^(\w+:)?\/\/([^\/?#]+)/,
+ parts = rurl.exec( s.url ),
+ remote = parts && (parts[1] && parts[1] !== location.protocol || parts[2] !== location.host);
+
+ // Test if we are going to create a script tag (if so, intercept & mock)
+ if ( s.dataType === "script" && s.type.toUpperCase() === "GET" && remote ) {
+ // Synthesize the mock request for adding a script tag
+ var callbackContext = origSettings && origSettings.context || s;
+
+ function success() {
+ // If a local callback was specified, fire it and pass it the data
+ if ( s.success ) {
+ s.success.call( callbackContext, ( m.response ? m.response.toString() : m.responseText || ''), status, {} );
+ }
+
+ // Fire the global callback
+ if ( s.global ) {
+ trigger( "ajaxSuccess", [{}, s] );
+ }
+ }
+
+ function complete() {
+ // Process result
+ if ( s.complete ) {
+ s.complete.call( callbackContext, {} , status );
+ }
+
+ // The request was completed
+ if ( s.global ) {
+ trigger( "ajaxComplete", [{}, s] );
+ }
+
+ // Handle the global AJAX counter
+ if ( s.global && ! --jQuery.active ) {
+ jQuery.event.trigger( "ajaxStop" );
+ }
+ }
+
+ function trigger(type, args) {
+ (s.context ? jQuery(s.context) : jQuery.event).trigger(type, args);
+ }
+
+ if ( m.response && $.isFunction(m.response) ) {
+ m.response(origSettings);
+ } else {
+ $.globalEval(m.responseText);
+ }
+ success();
+ complete();
+ return false;
+ }
+ mock = _ajax.call($, $.extend(true, {}, origSettings, {
+ // Mock the XHR object
+ xhr: function() {
+ // Extend with our default mockjax settings
+ m = $.extend({}, $.mockjaxSettings, m);
+
+ if ( m.contentType ) {
+ m.headers['content-type'] = m.contentType;
+ }
+
+ // Return our mock xhr object
+ return {
+ status: m.status,
+ readyState: 1,
+ open: function() { },
+ send: function() {
+ // This is a substitute for < 1.4 which lacks $.proxy
+ var process = (function(that) {
+ return function() {
+ return (function() {
+ // The request has returned
+ this.status = m.status;
+ this.readyState = 4;
+
+ // We have an executable function, call it to give
+ // the mock handler a chance to update it's data
+ if ( $.isFunction(m.response) ) {
+ m.response(origSettings);
+ }
+ // Copy over our mock to our xhr object before passing control back to
+ // jQuery's onreadystatechange callback
+ if ( s.dataType == 'json' && ( typeof m.responseText == 'object' ) ) {
+ this.responseText = JSON.stringify(m.responseText);
+ } else if ( s.dataType == 'xml' ) {
+ if ( typeof m.responseXML == 'string' ) {
+ this.responseXML = parseXML(m.responseXML);
+ } else {
+ this.responseXML = m.responseXML;
+ }
+ } else {
+ this.responseText = m.responseText;
+ }
+ // jQuery < 1.4 doesn't have onreadystate change for xhr
+ if ( $.isFunction(this.onreadystatechange) ) {
+ this.onreadystatechange( m.isTimeout ? 'timeout' : undefined );
+ }
+ }).apply(that);
+ };
+ })(this);
+
+ if ( m.proxy ) {
+ // We're proxying this request and loading in an external file instead
+ _ajax({
+ global: false,
+ url: m.proxy,
+ type: m.proxyType,
+ data: m.data,
+ dataType: s.dataType,
+ complete: function(xhr, txt) {
+ m.responseXML = xhr.responseXML;
+ m.responseText = xhr.responseText;
+ this.responseTimer = setTimeout(process, m.responseTime || 0);
+ }
+ });
+ } else {
+ // type == 'POST' || 'GET' || 'DELETE'
+ if ( s.async === false ) {
+ // TODO: Blocking delay
+ process();
+ } else {
+ this.responseTimer = setTimeout(process, m.responseTime || 50);
+ }
+ }
+ },
+ abort: function() {
+ clearTimeout(this.responseTimer);
+ },
+ setRequestHeader: function() { },
+ getResponseHeader: function(header) {
+ // 'Last-modified', 'Etag', 'content-type' are all checked by jQuery
+ if ( m.headers && m.headers[header] ) {
+ // Return arbitrary headers
+ return m.headers[header];
+ } else if ( header.toLowerCase() == 'last-modified' ) {
+ return m.lastModified || (new Date()).toString();
+ } else if ( header.toLowerCase() == 'etag' ) {
+ return m.etag || '';
+ } else if ( header.toLowerCase() == 'content-type' ) {
+ return m.contentType || 'text/plain';
+ }
+ },
+ getAllResponseHeaders: function() {
+ var headers = '';
+ $.each(m.headers, function(k, v) {
+ headers += k + ': ' + v + "\n";
+ });
+ return headers;
+ }
+ };
+ }
+ }));
+ return false;
+ }
+ });
+ // We don't have a mock request, trigger a normal request
+ if ( !mock ) {
+ return _ajax.apply($, arguments);
+ } else {
+ return mock;
+ }
+ }
+ });
+
+ $.mockjaxSettings = {
+ //url: null,
+ //type: 'GET',
+ log: function(msg) {
+ window['console'] && window.console.log && window.console.log(msg);
+ },
+ status: 200,
+ responseTime: 500,
+ isTimeout: false,
+ contentType: 'text/plain',
+ response: '',
+ responseText: '',
+ responseXML: '',
+ proxy: '',
+ proxyType: 'GET',
+
+ lastModified: null,
+ etag: '',
+ headers: {
+ etag: 'IJF@H#@923uf8023hFO@I#H#',
+ 'content-type' : 'text/plain'
+ }
+ };
+
+ $.mockjax = function(settings) {
+ var i = mockHandlers.length;
+ mockHandlers[i] = settings;
+ return i;
+ };
+ $.mockjaxClear = function(i) {
+ if ( arguments.length == 1 ) {
+ mockHandlers[i] = null;
+ } else {
+ mockHandlers = [];
+ }
+ };
+})(jQuery);
--- /dev/null
+/*!
+ * jQuery xmlDOM Plugin v1.0
+ * http://outwestmedia.com/jquery-plugins/xmldom/
+ *
+ * Released: 2009-04-06
+ * Version: 1.0
+ *
+ * Copyright (c) 2009 Jonathan Sharp, Out West Media LLC.
+ * Dual licensed under the MIT and GPL licenses.
+ * http://docs.jquery.com/License
+ */
+(function($) {
+ // IE DOMParser wrapper
+ if ( window['DOMParser'] == undefined && window.ActiveXObject ) {
+ DOMParser = function() { };
+ DOMParser.prototype.parseFromString = function( xmlString ) {
+ var doc = new ActiveXObject('Microsoft.XMLDOM');
+ doc.async = 'false';
+ doc.loadXML( xmlString );
+ return doc;
+ };
+ }
+
+ $.xmlDOM = function(xml, onErrorFn) {
+ try {
+ var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' );
+ if ( $.isXMLDoc( xmlDoc ) ) {
+ var err = $('parsererror', xmlDoc);
+ if ( err.length == 1 ) {
+ throw('Error: ' + $(xmlDoc).text() );
+ }
+ } else {
+ throw('Unable to parse XML');
+ }
+ } catch( e ) {
+ var msg = ( e.name == undefined ? e : e.name + ': ' + e.message );
+ if ( $.isFunction( onErrorFn ) ) {
+ onErrorFn( msg );
+ } else {
+ $(document).trigger('xmlParseError', [ msg ]);
+ }
+ return $([]);
+ }
+ return $( xmlDoc );
+ };
+})(jQuery);
\ No newline at end of file
+++ /dev/null
-/*
- * jQuery Asynchronous Plugin 1.0
- *
- * Copyright (c) 2008 Vincent Robert (genezys.net)
- * Dual licensed under the MIT (MIT-LICENSE.txt)
- * and GPL (GPL-LICENSE.txt) licenses.
- *
- */
-(function($){
-
-// opts.delay : (default 10) delay between async call in ms
-// opts.bulk : (default 500) delay during which the loop can continue synchronously without yielding the CPU
-// opts.test : (default true) function to test in the while test part
-// opts.loop : (default empty) function to call in the while loop part
-// opts.end : (default empty) function to call at the end of the while loop
-$.whileAsync = function(opts) {
- var delay = Math.abs(opts.delay) || 10,
- bulk = isNaN(opts.bulk) ? 500 : Math.abs(opts.bulk),
- test = opts.test || function(){ return true; },
- loop = opts.loop || function(){},
- end = opts.end || function(){};
-
- (function(){
-
- var t = false,
- begin = new Date();
-
- while( t = test() ) {
- loop();
- if( bulk === 0 || (new Date() - begin) > bulk ) {
- break;
- }
- }
- if( t ) {
- setTimeout(arguments.callee, delay);
- }
- else {
- end();
- }
-
- })();
-};
-
-// opts.delay : (default 10) delay between async call in ms
-// opts.bulk : (default 500) delay during which the loop can continue synchronously without yielding the CPU
-// opts.loop : (default empty) function to call in the each loop part, signature: function(index, value) this = value
-// opts.end : (default empty) function to call at the end of the each loop
-$.eachAsync = function(array, opts) {
- var i = 0,
- l = array.length,
- loop = opts.loop || function(){};
-
- $.whileAsync(
- $.extend(opts, {
- test: function() { return i < l; },
- loop: function() {
- var val = array[i];
- return loop.call(val, i++, val);
- }
- })
- );
-};
-
-$.fn.eachAsync = function(opts) {
- $.eachAsync(this, opts);
- return this;
-}
-
-})(jQuery);
\ No newline at end of file
+++ /dev/null
-/*!
- * jQuery throttle / debounce - v1.1 - 3/7/2010
- * http://benalman.com/projects/jquery-throttle-debounce-plugin/
- *
- * Copyright (c) 2010 "Cowboy" Ben Alman
- * Dual licensed under the MIT and GPL licenses.
- * http://benalman.com/about/license/
- */
-
-// Script: jQuery throttle / debounce: Sometimes, less is more!
-//
-// *Version: 1.1, Last updated: 3/7/2010*
-//
-// Project Home - http://benalman.com/projects/jquery-throttle-debounce-plugin/
-// GitHub - http://github.com/cowboy/jquery-throttle-debounce/
-// Source - http://github.com/cowboy/jquery-throttle-debounce/raw/master/jquery.ba-throttle-debounce.js
-// (Minified) - http://github.com/cowboy/jquery-throttle-debounce/raw/master/jquery.ba-throttle-debounce.min.js (0.7kb)
-//
-// About: License
-//
-// Copyright (c) 2010 "Cowboy" Ben Alman,
-// Dual licensed under the MIT and GPL licenses.
-// http://benalman.com/about/license/
-//
-// About: Examples
-//
-// These working examples, complete with fully commented code, illustrate a few
-// ways in which this plugin can be used.
-//
-// Throttle - http://benalman.com/code/projects/jquery-throttle-debounce/examples/throttle/
-// Debounce - http://benalman.com/code/projects/jquery-throttle-debounce/examples/debounce/
-//
-// About: Support and Testing
-//
-// Information about what version or versions of jQuery this plugin has been
-// tested with, what browsers it has been tested in, and where the unit tests
-// reside (so you can test it yourself).
-//
-// jQuery Versions - none, 1.3.2, 1.4.2
-// Browsers Tested - Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome 4-5, Opera 9.6-10.1.
-// Unit Tests - http://benalman.com/code/projects/jquery-throttle-debounce/unit/
-//
-// About: Release History
-//
-// 1.1 - (3/7/2010) Fixed a bug in <jQuery.throttle> where trailing callbacks
-// executed later than they should. Reworked a fair amount of internal
-// logic as well.
-// 1.0 - (3/6/2010) Initial release as a stand-alone project. Migrated over
-// from jquery-misc repo v0.4 to jquery-throttle repo v1.0, added the
-// no_trailing throttle parameter and debounce functionality.
-//
-// Topic: Note for non-jQuery users
-//
-// jQuery isn't actually required for this plugin, because nothing internal
-// uses any jQuery methods or properties. jQuery is just used as a namespace
-// under which these methods can exist.
-//
-// Since jQuery isn't actually required for this plugin, if jQuery doesn't exist
-// when this plugin is loaded, the method described below will be created in
-// the `Cowboy` namespace. Usage will be exactly the same, but instead of
-// $.method() or jQuery.method(), you'll need to use Cowboy.method().
-
-(function(window,undefined){
- '$:nomunge'; // Used by YUI compressor.
-
- // Since jQuery really isn't required for this plugin, use `jQuery` as the
- // namespace only if it already exists, otherwise use the `Cowboy` namespace,
- // creating it if necessary.
- var $ = window.jQuery || window.Cowboy || ( window.Cowboy = {} ),
-
- // Internal method reference.
- jq_throttle;
-
- // Method: jQuery.throttle
- //
- // Throttle execution of a function. Especially useful for rate limiting
- // execution of handlers on events like resize and scroll. If you want to
- // rate-limit execution of a function to a single time, see the
- // <jQuery.debounce> method.
- //
- // In this visualization, | is a throttled-function call and X is the actual
- // callback execution:
- //
- // > Throttled with `no_trailing` specified as false or unspecified:
- // > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
- // > X X X X X X X X X X X X
- // >
- // > Throttled with `no_trailing` specified as true:
- // > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
- // > X X X X X X X X X X
- //
- // Usage:
- //
- // > var throttled = jQuery.throttle( delay, [ no_trailing, ] callback );
- // >
- // > jQuery('selector').bind( 'someevent', throttled );
- // > jQuery('selector').unbind( 'someevent', throttled );
- //
- // This also works in jQuery 1.4+:
- //
- // > jQuery('selector').bind( 'someevent', jQuery.throttle( delay, [ no_trailing, ] callback ) );
- // > jQuery('selector').unbind( 'someevent', callback );
- //
- // Arguments:
- //
- // delay - (Number) A zero-or-greater delay in milliseconds. For event
- // callbacks, values around 100 or 250 (or even higher) are most useful.
- // no_trailing - (Boolean) Optional, defaults to false. If no_trailing is
- // true, callback will only execute every `delay` milliseconds while the
- // throttled-function is being called. If no_trailing is false or
- // unspecified, callback will be executed one final time after the last
- // throttled-function call. (After the throttled-function has not been
- // called for `delay` milliseconds, the internal counter is reset)
- // callback - (Function) A function to be executed after delay milliseconds.
- // The `this` context and all arguments are passed through, as-is, to
- // `callback` when the throttled-function is executed.
- //
- // Returns:
- //
- // (Function) A new, throttled, function.
-
- $.throttle = jq_throttle = function( delay, no_trailing, callback, debounce_mode ) {
- // After wrapper has stopped being called, this timeout ensures that
- // `callback` is executed at the proper times in `throttle` and `end`
- // debounce modes.
- var timeout_id,
-
- // Keep track of the last time `callback` was executed.
- last_exec = 0;
-
- // `no_trailing` defaults to falsy.
- if ( typeof no_trailing !== 'boolean' ) {
- debounce_mode = callback;
- callback = no_trailing;
- no_trailing = undefined;
- }
-
- // The `wrapper` function encapsulates all of the throttling / debouncing
- // functionality and when executed will limit the rate at which `callback`
- // is executed.
- function wrapper() {
- var that = this,
- elapsed = +new Date() - last_exec,
- args = arguments;
-
- // Execute `callback` and update the `last_exec` timestamp.
- function exec() {
- last_exec = +new Date();
- callback.apply( that, args );
- };
-
- // If `debounce_mode` is true (at_begin) this is used to clear the flag
- // to allow future `callback` executions.
- function clear() {
- timeout_id = undefined;
- };
-
- if ( debounce_mode && !timeout_id ) {
- // Since `wrapper` is being called for the first time and
- // `debounce_mode` is true (at_begin), execute `callback`.
- exec();
- }
-
- // Clear any existing timeout.
- timeout_id && clearTimeout( timeout_id );
-
- if ( debounce_mode === undefined && elapsed > delay ) {
- // In throttle mode, if `delay` time has been exceeded, execute
- // `callback`.
- exec();
-
- } else if ( no_trailing !== true ) {
- // In trailing throttle mode, since `delay` time has not been
- // exceeded, schedule `callback` to execute `delay` ms after most
- // recent execution.
- //
- // If `debounce_mode` is true (at_begin), schedule `clear` to execute
- // after `delay` ms.
- //
- // If `debounce_mode` is false (at end), schedule `callback` to
- // execute after `delay` ms.
- timeout_id = setTimeout( debounce_mode ? clear : exec, debounce_mode === undefined ? delay - elapsed : delay );
- }
- };
-
- // Set the guid of `wrapper` function to the same of original callback, so
- // it can be removed in jQuery 1.4+ .unbind or .die by using the original
- // callback as a reference.
- if ( $.guid ) {
- wrapper.guid = callback.guid = callback.guid || $.guid++;
- }
-
- // Return the wrapper function.
- return wrapper;
- };
-
- // Method: jQuery.debounce
- //
- // Debounce execution of a function. Debouncing, unlike throttling,
- // guarantees that a function is only executed a single time, either at the
- // very beginning of a series of calls, or at the very end. If you want to
- // simply rate-limit execution of a function, see the <jQuery.throttle>
- // method.
- //
- // In this visualization, | is a debounced-function call and X is the actual
- // callback execution:
- //
- // > Debounced with `at_begin` specified as false or unspecified:
- // > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
- // > X X
- // >
- // > Debounced with `at_begin` specified as true:
- // > ||||||||||||||||||||||||| (pause) |||||||||||||||||||||||||
- // > X X
- //
- // Usage:
- //
- // > var debounced = jQuery.debounce( delay, [ at_begin, ] callback );
- // >
- // > jQuery('selector').bind( 'someevent', debounced );
- // > jQuery('selector').unbind( 'someevent', debounced );
- //
- // This also works in jQuery 1.4+:
- //
- // > jQuery('selector').bind( 'someevent', jQuery.debounce( delay, [ at_begin, ] callback ) );
- // > jQuery('selector').unbind( 'someevent', callback );
- //
- // Arguments:
- //
- // delay - (Number) A zero-or-greater delay in milliseconds. For event
- // callbacks, values around 100 or 250 (or even higher) are most useful.
- // at_begin - (Boolean) Optional, defaults to false. If at_begin is false or
- // unspecified, callback will only be executed `delay` milliseconds after
- // the last debounced-function call. If at_begin is true, callback will be
- // executed only at the first debounced-function call. (After the
- // throttled-function has not been called for `delay` milliseconds, the
- // internal counter is reset)
- // callback - (Function) A function to be executed after delay milliseconds.
- // The `this` context and all arguments are passed through, as-is, to
- // `callback` when the debounced-function is executed.
- //
- // Returns:
- //
- // (Function) A new, debounced, function.
-
- $.debounce = function( delay, at_begin, callback ) {
- return callback === undefined
- ? jq_throttle( delay, at_begin, false )
- : jq_throttle( delay, callback, at_begin !== false );
- };
-
-})(this);
+++ /dev/null
-/*!
- * jQuery Cookie Plugin v1.3.1
- * https://github.com/carhartl/jquery-cookie
- *
- * Copyright 2013 Klaus Hartl
- * Released under the MIT license
- */
-(function ($, document, undefined) {
-
- var pluses = /\+/g;
-
- function raw(s) {
- return s;
- }
-
- function decoded(s) {
- return unRfc2068(decodeURIComponent(s.replace(pluses, ' ')));
- }
-
- function unRfc2068(value) {
- if (value.indexOf('"') === 0) {
- // This is a quoted cookie as according to RFC2068, unescape
- value = value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
- }
- return value;
- }
-
- function fromJSON(value) {
- return config.json ? JSON.parse(value) : value;
- }
-
- var config = $.cookie = function (key, value, options) {
-
- // write
- if (value !== undefined) {
- options = $.extend({}, config.defaults, options);
-
- if (value === null) {
- options.expires = -1;
- }
-
- if (typeof options.expires === 'number') {
- var days = options.expires, t = options.expires = new Date();
- t.setDate(t.getDate() + days);
- }
-
- value = config.json ? JSON.stringify(value) : String(value);
-
- return (document.cookie = [
- encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
- options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
- options.path ? '; path=' + options.path : '',
- options.domain ? '; domain=' + options.domain : '',
- options.secure ? '; secure' : ''
- ].join(''));
- }
-
- // read
- var decode = config.raw ? raw : decoded;
- var cookies = document.cookie.split('; ');
- var result = key ? null : {};
- for (var i = 0, l = cookies.length; i < l; i++) {
- var parts = cookies[i].split('=');
- var name = decode(parts.shift());
- var cookie = decode(parts.join('='));
-
- if (key && key === name) {
- result = fromJSON(cookie);
- break;
- }
-
- if (!key) {
- result[name] = fromJSON(cookie);
- }
- }
-
- return result;
- };
-
- config.defaults = {};
-
- $.removeCookie = function (key, options) {
- if ($.cookie(key) !== null) {
- $.cookie(key, null, options);
- return true;
- }
- return false;
- };
-
-})(jQuery, document);
+++ /dev/null
-/*!
- * jQuery Form Plugin
- * version: 3.14 (30-JUL-2012)
- * @requires jQuery v1.3.2 or later
- *
- * Examples and documentation at: http://malsup.com/jquery/form/
- * Project repository: https://github.com/malsup/form
- * Dual licensed under the MIT and GPL licenses:
- * http://malsup.github.com/mit-license.txt
- * http://malsup.github.com/gpl-license-v2.txt
- */
-/*global ActiveXObject alert */
-;(function($) {
-"use strict";
-
-/*
- Usage Note:
- -----------
- Do not use both ajaxSubmit and ajaxForm on the same form. These
- functions are mutually exclusive. Use ajaxSubmit if you want
- to bind your own submit handler to the form. For example,
-
- $(document).ready(function() {
- $('#myForm').on('submit', function(e) {
- e.preventDefault(); // <-- important
- $(this).ajaxSubmit({
- target: '#output'
- });
- });
- });
-
- Use ajaxForm when you want the plugin to manage all the event binding
- for you. For example,
-
- $(document).ready(function() {
- $('#myForm').ajaxForm({
- target: '#output'
- });
- });
-
- You can also use ajaxForm with delegation (requires jQuery v1.7+), so the
- form does not have to exist when you invoke ajaxForm:
-
- $('#myForm').ajaxForm({
- delegation: true,
- target: '#output'
- });
-
- When using ajaxForm, the ajaxSubmit function will be invoked for you
- at the appropriate time.
-*/
-
-/**
- * Feature detection
- */
-var feature = {};
-feature.fileapi = $("<input type='file'/>").get(0).files !== undefined;
-feature.formdata = window.FormData !== undefined;
-
-/**
- * ajaxSubmit() provides a mechanism for immediately submitting
- * an HTML form using AJAX.
- */
-$.fn.ajaxSubmit = function(options) {
- /*jshint scripturl:true */
-
- // fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
- if (!this.length) {
- log('ajaxSubmit: skipping submit process - no element selected');
- return this;
- }
-
- var method, action, url, $form = this;
-
- if (typeof options == 'function') {
- options = { success: options };
- }
-
- method = this.attr('method');
- action = this.attr('action');
- url = (typeof action === 'string') ? $.trim(action) : '';
- url = url || window.location.href || '';
- if (url) {
- // clean url (don't include hash vaue)
- url = (url.match(/^([^#]+)/)||[])[1];
- }
-
- options = $.extend(true, {
- url: url,
- success: $.ajaxSettings.success,
- type: method || 'GET',
- iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
- }, options);
-
- // hook for manipulating the form data before it is extracted;
- // convenient for use with rich editors like tinyMCE or FCKEditor
- var veto = {};
- this.trigger('form-pre-serialize', [this, options, veto]);
- if (veto.veto) {
- log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
- return this;
- }
-
- // provide opportunity to alter form data before it is serialized
- if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
- log('ajaxSubmit: submit aborted via beforeSerialize callback');
- return this;
- }
-
- var traditional = options.traditional;
- if ( traditional === undefined ) {
- traditional = $.ajaxSettings.traditional;
- }
-
- var elements = [];
- var qx, a = this.formToArray(options.semantic, elements);
- if (options.data) {
- options.extraData = options.data;
- qx = $.param(options.data, traditional);
- }
-
- // give pre-submit callback an opportunity to abort the submit
- if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
- log('ajaxSubmit: submit aborted via beforeSubmit callback');
- return this;
- }
-
- // fire vetoable 'validate' event
- this.trigger('form-submit-validate', [a, this, options, veto]);
- if (veto.veto) {
- log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
- return this;
- }
-
- var q = $.param(a, traditional);
- if (qx) {
- q = ( q ? (q + '&' + qx) : qx );
- }
- if (options.type.toUpperCase() == 'GET') {
- options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
- options.data = null; // data is null for 'get'
- }
- else {
- options.data = q; // data is the query string for 'post'
- }
-
- var callbacks = [];
- if (options.resetForm) {
- callbacks.push(function() { $form.resetForm(); });
- }
- if (options.clearForm) {
- callbacks.push(function() { $form.clearForm(options.includeHidden); });
- }
-
- // perform a load on the target only if dataType is not provided
- if (!options.dataType && options.target) {
- var oldSuccess = options.success || function(){};
- callbacks.push(function(data) {
- var fn = options.replaceTarget ? 'replaceWith' : 'html';
- $(options.target)[fn](data).each(oldSuccess, arguments);
- });
- }
- else if (options.success) {
- callbacks.push(options.success);
- }
-
- options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
- var context = options.context || this ; // jQuery 1.4+ supports scope context
- for (var i=0, max=callbacks.length; i < max; i++) {
- callbacks[i].apply(context, [data, status, xhr || $form, $form]);
- }
- };
-
- // are there files to upload?
- var fileInputs = $('input:file:enabled[value]', this); // [value] (issue #113)
- var hasFileInputs = fileInputs.length > 0;
- var mp = 'multipart/form-data';
- var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
-
- var fileAPI = feature.fileapi && feature.formdata;
- log("fileAPI :" + fileAPI);
- var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;
-
- // options.iframe allows user to force iframe mode
- // 06-NOV-09: now defaulting to iframe mode if file input is detected
- if (options.iframe !== false && (options.iframe || shouldUseFrame)) {
- // hack to fix Safari hang (thanks to Tim Molendijk for this)
- // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
- if (options.closeKeepAlive) {
- $.get(options.closeKeepAlive, function() {
- fileUploadIframe(a);
- });
- }
- else {
- fileUploadIframe(a);
- }
- }
- else if ((hasFileInputs || multipart) && fileAPI) {
- fileUploadXhr(a);
- }
- else {
- $.ajax(options);
- }
-
- // clear element array
- for (var k=0; k < elements.length; k++)
- elements[k] = null;
-
- // fire 'notify' event
- this.trigger('form-submit-notify', [this, options]);
- return this;
-
- // XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
- function fileUploadXhr(a) {
- var formdata = new FormData();
-
- for (var i=0; i < a.length; i++) {
- formdata.append(a[i].name, a[i].value);
- }
-
- if (options.extraData) {
- for (var p in options.extraData)
- if (options.extraData.hasOwnProperty(p))
- formdata.append(p, options.extraData[p]);
- }
-
- options.data = null;
-
- var s = $.extend(true, {}, $.ajaxSettings, options, {
- contentType: false,
- processData: false,
- cache: false,
- type: 'POST'
- });
-
- if (options.uploadProgress) {
- // workaround because jqXHR does not expose upload property
- s.xhr = function() {
- var xhr = jQuery.ajaxSettings.xhr();
- if (xhr.upload) {
- xhr.upload.onprogress = function(event) {
- var percent = 0;
- var position = event.loaded || event.position; /*event.position is deprecated*/
- var total = event.total;
- if (event.lengthComputable) {
- percent = Math.ceil(position / total * 100);
- }
- options.uploadProgress(event, position, total, percent);
- };
- }
- return xhr;
- };
- }
-
- s.data = null;
- var beforeSend = s.beforeSend;
- s.beforeSend = function(xhr, o) {
- o.data = formdata;
- if(beforeSend)
- beforeSend.call(this, xhr, o);
- };
- $.ajax(s);
- }
-
- // private function for handling file uploads (hat tip to YAHOO!)
- function fileUploadIframe(a) {
- var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle;
- var useProp = !!$.fn.prop;
-
- if ($(':input[name=submit],:input[id=submit]', form).length) {
- // if there is an input with a name or id of 'submit' then we won't be
- // able to invoke the submit fn on the form (at least not x-browser)
- alert('Error: Form elements must not have name or id of "submit".');
- return;
- }
-
- if (a) {
- // ensure that every serialized input is still enabled
- for (i=0; i < elements.length; i++) {
- el = $(elements[i]);
- if ( useProp )
- el.prop('disabled', false);
- else
- el.removeAttr('disabled');
- }
- }
-
- s = $.extend(true, {}, $.ajaxSettings, options);
- s.context = s.context || s;
- id = 'jqFormIO' + (new Date().getTime());
- if (s.iframeTarget) {
- $io = $(s.iframeTarget);
- n = $io.attr('name');
- if (!n)
- $io.attr('name', id);
- else
- id = n;
- }
- else {
- $io = $('<iframe name="' + id + '" src="'+ s.iframeSrc +'" />');
- $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
- }
- io = $io[0];
-
-
- xhr = { // mock object
- aborted: 0,
- responseText: null,
- responseXML: null,
- status: 0,
- statusText: 'n/a',
- getAllResponseHeaders: function() {},
- getResponseHeader: function() {},
- setRequestHeader: function() {},
- abort: function(status) {
- var e = (status === 'timeout' ? 'timeout' : 'aborted');
- log('aborting upload... ' + e);
- this.aborted = 1;
- // #214
- if (io.contentWindow.document.execCommand) {
- try { // #214
- io.contentWindow.document.execCommand('Stop');
- } catch(ignore) {}
- }
- $io.attr('src', s.iframeSrc); // abort op in progress
- xhr.error = e;
- if (s.error)
- s.error.call(s.context, xhr, e, status);
- if (g)
- $.event.trigger("ajaxError", [xhr, s, e]);
- if (s.complete)
- s.complete.call(s.context, xhr, e);
- }
- };
-
- g = s.global;
- // trigger ajax global events so that activity/block indicators work like normal
- if (g && 0 === $.active++) {
- $.event.trigger("ajaxStart");
- }
- if (g) {
- $.event.trigger("ajaxSend", [xhr, s]);
- }
-
- if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
- if (s.global) {
- $.active--;
- }
- return;
- }
- if (xhr.aborted) {
- return;
- }
-
- // add submitting element to data if we know it
- sub = form.clk;
- if (sub) {
- n = sub.name;
- if (n && !sub.disabled) {
- s.extraData = s.extraData || {};
- s.extraData[n] = sub.value;
- if (sub.type == "image") {
- s.extraData[n+'.x'] = form.clk_x;
- s.extraData[n+'.y'] = form.clk_y;
- }
- }
- }
-
- var CLIENT_TIMEOUT_ABORT = 1;
- var SERVER_ABORT = 2;
-
- function getDoc(frame) {
- var doc = frame.contentWindow ? frame.contentWindow.document : frame.contentDocument ? frame.contentDocument : frame.document;
- return doc;
- }
-
- // Rails CSRF hack (thanks to Yvan Barthelemy)
- var csrf_token = $('meta[name=csrf-token]').attr('content');
- var csrf_param = $('meta[name=csrf-param]').attr('content');
- if (csrf_param && csrf_token) {
- s.extraData = s.extraData || {};
- s.extraData[csrf_param] = csrf_token;
- }
-
- // take a breath so that pending repaints get some cpu time before the upload starts
- function doSubmit() {
- // make sure form attrs are set
- var t = $form.attr('target'), a = $form.attr('action');
-
- // update form attrs in IE friendly way
- form.setAttribute('target',id);
- if (!method) {
- form.setAttribute('method', 'POST');
- }
- if (a != s.url) {
- form.setAttribute('action', s.url);
- }
-
- // ie borks in some cases when setting encoding
- if (! s.skipEncodingOverride && (!method || /post/i.test(method))) {
- $form.attr({
- encoding: 'multipart/form-data',
- enctype: 'multipart/form-data'
- });
- }
-
- // support timout
- if (s.timeout) {
- timeoutHandle = setTimeout(function() { timedOut = true; cb(CLIENT_TIMEOUT_ABORT); }, s.timeout);
- }
-
- // look for server aborts
- function checkState() {
- try {
- var state = getDoc(io).readyState;
- log('state = ' + state);
- if (state && state.toLowerCase() == 'uninitialized')
- setTimeout(checkState,50);
- }
- catch(e) {
- log('Server abort: ' , e, ' (', e.name, ')');
- cb(SERVER_ABORT);
- if (timeoutHandle)
- clearTimeout(timeoutHandle);
- timeoutHandle = undefined;
- }
- }
-
- // add "extra" data to form if provided in options
- var extraInputs = [];
- try {
- if (s.extraData) {
- for (var n in s.extraData) {
- if (s.extraData.hasOwnProperty(n)) {
- // if using the $.param format that allows for multiple values with the same name
- if($.isPlainObject(s.extraData[n]) && s.extraData[n].hasOwnProperty('name') && s.extraData[n].hasOwnProperty('value')) {
- extraInputs.push(
- $('<input type="hidden" name="'+s.extraData[n].name+'">').attr('value',s.extraData[n].value)
- .appendTo(form)[0]);
- } else {
- extraInputs.push(
- $('<input type="hidden" name="'+n+'">').attr('value',s.extraData[n])
- .appendTo(form)[0]);
- }
- }
- }
- }
-
- if (!s.iframeTarget) {
- // add iframe to doc and submit the form
- $io.appendTo('body');
- if (io.attachEvent)
- io.attachEvent('onload', cb);
- else
- io.addEventListener('load', cb, false);
- }
- setTimeout(checkState,15);
- form.submit();
- }
- finally {
- // reset attrs and remove "extra" input elements
- form.setAttribute('action',a);
- if(t) {
- form.setAttribute('target', t);
- } else {
- $form.removeAttr('target');
- }
- $(extraInputs).remove();
- }
- }
-
- if (s.forceSync) {
- doSubmit();
- }
- else {
- setTimeout(doSubmit, 10); // this lets dom updates render
- }
-
- var data, doc, domCheckCount = 50, callbackProcessed;
-
- function cb(e) {
- if (xhr.aborted || callbackProcessed) {
- return;
- }
- try {
- doc = getDoc(io);
- }
- catch(ex) {
- log('cannot access response document: ', ex);
- e = SERVER_ABORT;
- }
- if (e === CLIENT_TIMEOUT_ABORT && xhr) {
- xhr.abort('timeout');
- return;
- }
- else if (e == SERVER_ABORT && xhr) {
- xhr.abort('server abort');
- return;
- }
-
- if (!doc || doc.location.href == s.iframeSrc) {
- // response not received yet
- if (!timedOut)
- return;
- }
- if (io.detachEvent)
- io.detachEvent('onload', cb);
- else
- io.removeEventListener('load', cb, false);
-
- var status = 'success', errMsg;
- try {
- if (timedOut) {
- throw 'timeout';
- }
-
- var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
- log('isXml='+isXml);
- if (!isXml && window.opera && (doc.body === null || !doc.body.innerHTML)) {
- if (--domCheckCount) {
- // in some browsers (Opera) the iframe DOM is not always traversable when
- // the onload callback fires, so we loop a bit to accommodate
- log('requeing onLoad callback, DOM not available');
- setTimeout(cb, 250);
- return;
- }
- // let this fall through because server response could be an empty document
- //log('Could not access iframe DOM after mutiple tries.');
- //throw 'DOMException: not available';
- }
-
- //log('response detected');
- var docRoot = doc.body ? doc.body : doc.documentElement;
- xhr.responseText = docRoot ? docRoot.innerHTML : null;
- xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
- if (isXml)
- s.dataType = 'xml';
- xhr.getResponseHeader = function(header){
- var headers = {'content-type': s.dataType};
- return headers[header];
- };
- // support for XHR 'status' & 'statusText' emulation :
- if (docRoot) {
- xhr.status = Number( docRoot.getAttribute('status') ) || xhr.status;
- xhr.statusText = docRoot.getAttribute('statusText') || xhr.statusText;
- }
-
- var dt = (s.dataType || '').toLowerCase();
- var scr = /(json|script|text)/.test(dt);
- if (scr || s.textarea) {
- // see if user embedded response in textarea
- var ta = doc.getElementsByTagName('textarea')[0];
- if (ta) {
- xhr.responseText = ta.value;
- // support for XHR 'status' & 'statusText' emulation :
- xhr.status = Number( ta.getAttribute('status') ) || xhr.status;
- xhr.statusText = ta.getAttribute('statusText') || xhr.statusText;
- }
- else if (scr) {
- // account for browsers injecting pre around json response
- var pre = doc.getElementsByTagName('pre')[0];
- var b = doc.getElementsByTagName('body')[0];
- if (pre) {
- xhr.responseText = pre.textContent ? pre.textContent : pre.innerText;
- }
- else if (b) {
- xhr.responseText = b.textContent ? b.textContent : b.innerText;
- }
- }
- }
- else if (dt == 'xml' && !xhr.responseXML && xhr.responseText) {
- xhr.responseXML = toXml(xhr.responseText);
- }
-
- try {
- data = httpData(xhr, dt, s);
- }
- catch (e) {
- status = 'parsererror';
- xhr.error = errMsg = (e || status);
- }
- }
- catch (e) {
- log('error caught: ',e);
- status = 'error';
- xhr.error = errMsg = (e || status);
- }
-
- if (xhr.aborted) {
- log('upload aborted');
- status = null;
- }
-
- if (xhr.status) { // we've set xhr.status
- status = (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) ? 'success' : 'error';
- }
-
- // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
- if (status === 'success') {
- if (s.success)
- s.success.call(s.context, data, 'success', xhr);
- if (g)
- $.event.trigger("ajaxSuccess", [xhr, s]);
- }
- else if (status) {
- if (errMsg === undefined)
- errMsg = xhr.statusText;
- if (s.error)
- s.error.call(s.context, xhr, status, errMsg);
- if (g)
- $.event.trigger("ajaxError", [xhr, s, errMsg]);
- }
-
- if (g)
- $.event.trigger("ajaxComplete", [xhr, s]);
-
- if (g && ! --$.active) {
- $.event.trigger("ajaxStop");
- }
-
- if (s.complete)
- s.complete.call(s.context, xhr, status);
-
- callbackProcessed = true;
- if (s.timeout)
- clearTimeout(timeoutHandle);
-
- // clean up
- setTimeout(function() {
- if (!s.iframeTarget)
- $io.remove();
- xhr.responseXML = null;
- }, 100);
- }
-
- var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
- if (window.ActiveXObject) {
- doc = new ActiveXObject('Microsoft.XMLDOM');
- doc.async = 'false';
- doc.loadXML(s);
- }
- else {
- doc = (new DOMParser()).parseFromString(s, 'text/xml');
- }
- return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
- };
- var parseJSON = $.parseJSON || function(s) {
- /*jslint evil:true */
- return window['eval']('(' + s + ')');
- };
-
- var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4
-
- var ct = xhr.getResponseHeader('content-type') || '',
- xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
- data = xml ? xhr.responseXML : xhr.responseText;
-
- if (xml && data.documentElement.nodeName === 'parsererror') {
- if ($.error)
- $.error('parsererror');
- }
- if (s && s.dataFilter) {
- data = s.dataFilter(data, type);
- }
- if (typeof data === 'string') {
- if (type === 'json' || !type && ct.indexOf('json') >= 0) {
- data = parseJSON(data);
- } else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
- $.globalEval(data);
- }
- }
- return data;
- };
- }
-};
-
-/**
- * ajaxForm() provides a mechanism for fully automating form submission.
- *
- * The advantages of using this method instead of ajaxSubmit() are:
- *
- * 1: This method will include coordinates for <input type="image" /> elements (if the element
- * is used to submit the form).
- * 2. This method will include the submit element's name/value data (for the element that was
- * used to submit the form).
- * 3. This method binds the submit() method to the form for you.
- *
- * The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
- * passes the options argument along after properly binding events for submit elements and
- * the form itself.
- */
-$.fn.ajaxForm = function(options) {
- options = options || {};
- options.delegation = options.delegation && $.isFunction($.fn.on);
-
- // in jQuery 1.3+ we can fix mistakes with the ready state
- if (!options.delegation && this.length === 0) {
- var o = { s: this.selector, c: this.context };
- if (!$.isReady && o.s) {
- log('DOM not ready, queuing ajaxForm');
- $(function() {
- $(o.s,o.c).ajaxForm(options);
- });
- return this;
- }
- // is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
- log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
- return this;
- }
-
- if ( options.delegation ) {
- $(document)
- .off('submit.form-plugin', this.selector, doAjaxSubmit)
- .off('click.form-plugin', this.selector, captureSubmittingElement)
- .on('submit.form-plugin', this.selector, options, doAjaxSubmit)
- .on('click.form-plugin', this.selector, options, captureSubmittingElement);
- return this;
- }
-
- return this.ajaxFormUnbind()
- .bind('submit.form-plugin', options, doAjaxSubmit)
- .bind('click.form-plugin', options, captureSubmittingElement);
-};
-
-// private event handlers
-function doAjaxSubmit(e) {
- /*jshint validthis:true */
- var options = e.data;
- if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
- e.preventDefault();
- $(this).ajaxSubmit(options);
- }
-}
-
-function captureSubmittingElement(e) {
- /*jshint validthis:true */
- var target = e.target;
- var $el = $(target);
- if (!($el.is(":submit,input:image"))) {
- // is this a child element of the submit el? (ex: a span within a button)
- var t = $el.closest(':submit');
- if (t.length === 0) {
- return;
- }
- target = t[0];
- }
- var form = this;
- form.clk = target;
- if (target.type == 'image') {
- if (e.offsetX !== undefined) {
- form.clk_x = e.offsetX;
- form.clk_y = e.offsetY;
- } else if (typeof $.fn.offset == 'function') {
- var offset = $el.offset();
- form.clk_x = e.pageX - offset.left;
- form.clk_y = e.pageY - offset.top;
- } else {
- form.clk_x = e.pageX - target.offsetLeft;
- form.clk_y = e.pageY - target.offsetTop;
- }
- }
- // clear form vars
- setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
-}
-
-
-// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
-$.fn.ajaxFormUnbind = function() {
- return this.unbind('submit.form-plugin click.form-plugin');
-};
-
-/**
- * formToArray() gathers form element data into an array of objects that can
- * be passed to any of the following ajax functions: $.get, $.post, or load.
- * Each object in the array has both a 'name' and 'value' property. An example of
- * an array for a simple login form might be:
- *
- * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
- *
- * It is this array that is passed to pre-submit callback functions provided to the
- * ajaxSubmit() and ajaxForm() methods.
- */
-$.fn.formToArray = function(semantic, elements) {
- var a = [];
- if (this.length === 0) {
- return a;
- }
-
- var form = this[0];
- var els = semantic ? form.getElementsByTagName('*') : form.elements;
- if (!els) {
- return a;
- }
-
- var i,j,n,v,el,max,jmax;
- for(i=0, max=els.length; i < max; i++) {
- el = els[i];
- n = el.name;
- if (!n) {
- continue;
- }
-
- if (semantic && form.clk && el.type == "image") {
- // handle image inputs on the fly when semantic == true
- if(!el.disabled && form.clk == el) {
- a.push({name: n, value: $(el).val(), type: el.type });
- a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
- }
- continue;
- }
-
- v = $.fieldValue(el, true);
- if (v && v.constructor == Array) {
- if (elements)
- elements.push(el);
- for(j=0, jmax=v.length; j < jmax; j++) {
- a.push({name: n, value: v[j]});
- }
- }
- else if (feature.fileapi && el.type == 'file' && !el.disabled) {
- if (elements)
- elements.push(el);
- var files = el.files;
- if (files.length) {
- for (j=0; j < files.length; j++) {
- a.push({name: n, value: files[j], type: el.type});
- }
- }
- else {
- // #180
- a.push({ name: n, value: '', type: el.type });
- }
- }
- else if (v !== null && typeof v != 'undefined') {
- if (elements)
- elements.push(el);
- a.push({name: n, value: v, type: el.type, required: el.required});
- }
- }
-
- if (!semantic && form.clk) {
- // input type=='image' are not found in elements array! handle it here
- var $input = $(form.clk), input = $input[0];
- n = input.name;
- if (n && !input.disabled && input.type == 'image') {
- a.push({name: n, value: $input.val()});
- a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
- }
- }
- return a;
-};
-
-/**
- * Serializes form data into a 'submittable' string. This method will return a string
- * in the format: name1=value1&name2=value2
- */
-$.fn.formSerialize = function(semantic) {
- //hand off to jQuery.param for proper encoding
- return $.param(this.formToArray(semantic));
-};
-
-/**
- * Serializes all field elements in the jQuery object into a query string.
- * This method will return a string in the format: name1=value1&name2=value2
- */
-$.fn.fieldSerialize = function(successful) {
- var a = [];
- this.each(function() {
- var n = this.name;
- if (!n) {
- return;
- }
- var v = $.fieldValue(this, successful);
- if (v && v.constructor == Array) {
- for (var i=0,max=v.length; i < max; i++) {
- a.push({name: n, value: v[i]});
- }
- }
- else if (v !== null && typeof v != 'undefined') {
- a.push({name: this.name, value: v});
- }
- });
- //hand off to jQuery.param for proper encoding
- return $.param(a);
-};
-
-/**
- * Returns the value(s) of the element in the matched set. For example, consider the following form:
- *
- * <form><fieldset>
- * <input name="A" type="text" />
- * <input name="A" type="text" />
- * <input name="B" type="checkbox" value="B1" />
- * <input name="B" type="checkbox" value="B2"/>
- * <input name="C" type="radio" value="C1" />
- * <input name="C" type="radio" value="C2" />
- * </fieldset></form>
- *
- * var v = $(':text').fieldValue();
- * // if no values are entered into the text inputs
- * v == ['','']
- * // if values entered into the text inputs are 'foo' and 'bar'
- * v == ['foo','bar']
- *
- * var v = $(':checkbox').fieldValue();
- * // if neither checkbox is checked
- * v === undefined
- * // if both checkboxes are checked
- * v == ['B1', 'B2']
- *
- * var v = $(':radio').fieldValue();
- * // if neither radio is checked
- * v === undefined
- * // if first radio is checked
- * v == ['C1']
- *
- * The successful argument controls whether or not the field element must be 'successful'
- * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
- * The default value of the successful argument is true. If this value is false the value(s)
- * for each element is returned.
- *
- * Note: This method *always* returns an array. If no valid value can be determined the
- * array will be empty, otherwise it will contain one or more values.
- */
-$.fn.fieldValue = function(successful) {
- for (var val=[], i=0, max=this.length; i < max; i++) {
- var el = this[i];
- var v = $.fieldValue(el, successful);
- if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
- continue;
- }
- if (v.constructor == Array)
- $.merge(val, v);
- else
- val.push(v);
- }
- return val;
-};
-
-/**
- * Returns the value of the field element.
- */
-$.fieldValue = function(el, successful) {
- var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
- if (successful === undefined) {
- successful = true;
- }
-
- if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
- (t == 'checkbox' || t == 'radio') && !el.checked ||
- (t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
- tag == 'select' && el.selectedIndex == -1)) {
- return null;
- }
-
- if (tag == 'select') {
- var index = el.selectedIndex;
- if (index < 0) {
- return null;
- }
- var a = [], ops = el.options;
- var one = (t == 'select-one');
- var max = (one ? index+1 : ops.length);
- for(var i=(one ? index : 0); i < max; i++) {
- var op = ops[i];
- if (op.selected) {
- var v = op.value;
- if (!v) { // extra pain for IE...
- v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
- }
- if (one) {
- return v;
- }
- a.push(v);
- }
- }
- return a;
- }
- return $(el).val();
-};
-
-/**
- * Clears the form data. Takes the following actions on the form's input fields:
- * - input text fields will have their 'value' property set to the empty string
- * - select elements will have their 'selectedIndex' property set to -1
- * - checkbox and radio inputs will have their 'checked' property set to false
- * - inputs of type submit, button, reset, and hidden will *not* be effected
- * - button elements will *not* be effected
- */
-$.fn.clearForm = function(includeHidden) {
- return this.each(function() {
- $('input,select,textarea', this).clearFields(includeHidden);
- });
-};
-
-/**
- * Clears the selected form elements.
- */
-$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
- var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
- return this.each(function() {
- var t = this.type, tag = this.tagName.toLowerCase();
- if (re.test(t) || tag == 'textarea') {
- this.value = '';
- }
- else if (t == 'checkbox' || t == 'radio') {
- this.checked = false;
- }
- else if (tag == 'select') {
- this.selectedIndex = -1;
- }
- else if (includeHidden) {
- // includeHidden can be the value true, or it can be a selector string
- // indicating a special test; for example:
- // $('#myForm').clearForm('.special:hidden')
- // the above would clean hidden inputs that have the class of 'special'
- if ( (includeHidden === true && /hidden/.test(t)) ||
- (typeof includeHidden == 'string' && $(this).is(includeHidden)) )
- this.value = '';
- }
- });
-};
-
-/**
- * Resets the form data. Causes all form elements to be reset to their original value.
- */
-$.fn.resetForm = function() {
- return this.each(function() {
- // guard against an input with the name of 'reset'
- // note that IE reports the reset function as an 'object'
- if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
- this.reset();
- }
- });
-};
-
-/**
- * Enables or disables any matching elements.
- */
-$.fn.enable = function(b) {
- if (b === undefined) {
- b = true;
- }
- return this.each(function() {
- this.disabled = !b;
- });
-};
-
-/**
- * Checks/unchecks any matching checkboxes or radio buttons and
- * selects/deselects and matching option elements.
- */
-$.fn.selected = function(select) {
- if (select === undefined) {
- select = true;
- }
- return this.each(function() {
- var t = this.type;
- if (t == 'checkbox' || t == 'radio') {
- this.checked = select;
- }
- else if (this.tagName.toLowerCase() == 'option') {
- var $sel = $(this).parent('select');
- if (select && $sel[0] && $sel[0].type == 'select-one') {
- // deselect all other options
- $sel.find('option').selected(false);
- }
- this.selected = select;
- }
- });
-};
-
-// expose debug var
-$.fn.ajaxSubmit.debug = false;
-
-// helper fn for console logging
-function log() {
- if (!$.fn.ajaxSubmit.debug)
- return;
- var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
- if (window.console && window.console.log) {
- window.console.log(msg);
- }
- else if (window.opera && window.opera.postError) {
- window.opera.postError(msg);
- }
-}
-
-})(jQuery);
+++ /dev/null
-/**
- * jQuery fullscreen plugin v2.0.0-git (9f8f97d127)
- * https://github.com/theopolisme/jquery-fullscreen
- *
- * Copyright (c) 2013 Theopolisme <theopolismewiki@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-( function ( $ ) {
- var setupFullscreen,
- fsClass = 'jq-fullscreened';
-
- /**
- * On fullscreenchange, trigger a jq-fullscreen-change event
- * The event is given an object, which contains the fullscreened DOM element (element), if any
- * and a boolean value (fullscreen) indicating if we've entered or exited fullscreen mode
- * Also remove the 'fullscreened' class from elements that are no longer fullscreen
- */
- function handleFullscreenChange () {
- var fullscreenElement = document.fullscreenElement ||
- document.mozFullScreenElement ||
- document.webkitFullscreenElement ||
- document.msFullscreenElement;
-
- if ( !fullscreenElement ) {
- $( '.' + fsClass ).data( 'isFullscreened', false ).removeClass( fsClass );
- }
-
- $( document ).trigger( $.Event( 'jq-fullscreen-change', { element: fullscreenElement, fullscreen: !!fullscreenElement } ) );
- }
-
- /**
- * Enters full screen with the "this" element in focus.
- * Check the .data( 'isFullscreened' ) of the return value to check
- * success or failure, if you're into that sort of thing.
- * @chainable
- * @return {jQuery}
- */
- function enterFullscreen () {
- var element = this.get(0),
- $element = this.first();
- if ( element ) {
- if ( element.requestFullscreen ) {
- element.requestFullscreen();
- } else if ( element.mozRequestFullScreen ) {
- element.mozRequestFullScreen();
- } else if ( element.webkitRequestFullscreen ) {
- element.webkitRequestFullscreen();
- } else if ( element.msRequestFullscreen ) {
- element.msRequestFullscreen();
- } else {
- // Unable to make fullscreen
- $element.data( 'isFullscreened', false );
- return this;
- }
- // Add the fullscreen class and data attribute to `element`
- $element.addClass( fsClass ).data( 'isFullscreened', true );
- return this;
- } else {
- $element.data( 'isFullscreened', false );
- return this;
- }
- }
-
- /**
- * Brings the "this" element out of fullscreen.
- * Check the .data( 'isFullscreened' ) of the return value to check
- * success or failure, if you're into that sort of thing.
- * @chainable
- * @return {jQuery}
- */
- function exitFullscreen () {
- var fullscreenElement = ( document.fullscreenElement ||
- document.mozFullScreenElement ||
- document.webkitFullscreenElement ||
- document.msFullscreenElement );
-
- // Ensure that we only exit fullscreen if exitFullscreen() is being called on the same element that is currently fullscreen
- if ( fullscreenElement && this.get(0) === fullscreenElement ) {
- if ( document.exitFullscreen ) {
- document.exitFullscreen();
- } else if ( document.mozCancelFullScreen ) {
- document.mozCancelFullScreen();
- } else if ( document.webkitCancelFullScreen ) {
- document.webkitCancelFullScreen();
- } else if ( document.msExitFullscreen ) {
- document.msExitFullscreen();
- } else {
- // Unable to cancel fullscreen mode
- return this;
- }
- // We don't need to remove the fullscreen class here,
- // because it will be removed in handleFullscreenChange.
- // But we should change the data on the element so the
- // caller can check for success.
- this.first().data( 'isFullscreened', false );
- }
-
- return this;
- }
-
- /**
- * Set up fullscreen handling and install necessary event handlers.
- * Return false if fullscreen is not supported.
- */
- setupFullscreen = function () {
- if ( $.support.fullscreen ) {
- // When the fullscreen mode is changed, trigger the
- // fullscreen events (and when exiting,
- // also remove the fullscreen class)
- $( document ).on( 'fullscreenchange webkitfullscreenchange mozfullscreenchange MSFullscreenChange', handleFullscreenChange);
- // Convenience wrapper so that one only needs to listen for
- // 'fullscreenerror', not all of the prefixed versions
- $( document ).on( 'webkitfullscreenerror mozfullscreenerror MSFullscreenError', function () {
- $( document ).trigger( $.Event( 'fullscreenerror' ) );
- } );
- // Fullscreen has been set up, so always return true
- setupFullscreen = function () { return true; };
- return true;
- } else {
- // Always return false from now on, since fullscreen is not supported
- setupFullscreen = function () { return false; };
- return false;
- }
- };
-
- /**
- * Set up fullscreen handling if necessary, then make the first element
- * matching the given selector fullscreen
- * @chainable
- * @return {jQuery}
- */
- $.fn.enterFullscreen = function () {
- if ( setupFullscreen() ) {
- $.fn.enterFullscreen = enterFullscreen;
- return this.enterFullscreen();
- } else {
- $.fn.enterFullscreen = function () { return this; };
- return this;
- }
- };
-
- /**
- * Set up fullscreen handling if necessary, then cancel fullscreen mode
- * for the first element matching the given selector.
- * @chainable
- * @return {jQuery}
- */
- $.fn.exitFullscreen = function () {
- if ( setupFullscreen() ) {
- $.fn.exitFullscreen = exitFullscreen;
- return this.exitFullscreen();
- } else {
- $.fn.exitFullscreen = function () { return this; };
- return this;
- }
- };
-
- $.support.fullscreen = document.fullscreenEnabled ||
- document.webkitFullscreenEnabled ||
- document.mozFullScreenEnabled ||
- document.msFullscreenEnabled;
-}( jQuery ) );
+++ /dev/null
-/**
-* hoverIntent is similar to jQuery's built-in "hover" function except that
-* instead of firing the onMouseOver event immediately, hoverIntent checks
-* to see if the user's mouse has slowed down (beneath the sensitivity
-* threshold) before firing the onMouseOver event.
-*
-* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
-* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
-*
-* hoverIntent is currently available for use in all personal or commercial
-* projects under both MIT and GPL licenses. This means that you can choose
-* the license that best suits your project, and use it accordingly.
-*
-* // basic usage (just like .hover) receives onMouseOver and onMouseOut functions
-* $("ul li").hoverIntent( showNav , hideNav );
-*
-* // advanced usage receives configuration object only
-* $("ul li").hoverIntent({
-* sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
-* interval: 100, // number = milliseconds of polling interval
-* over: showNav, // function = onMouseOver callback (required)
-* timeout: 0, // number = milliseconds delay before onMouseOut function call
-* out: hideNav // function = onMouseOut callback (required)
-* });
-*
-* @param f onMouseOver function || An object with configuration options
-* @param g onMouseOut function || Nothing (use configuration options object)
-* @author Brian Cherne <brian@cherne.net>
-*/
-(function($) {
- $.fn.hoverIntent = function(f,g) {
- // default configuration options
- var cfg = {
- sensitivity: 7,
- interval: 100,
- timeout: 0
- };
- // override configuration options with user supplied object
- cfg = $.extend(cfg, g ? { over: f, out: g } : f );
-
- // instantiate variables
- // cX, cY = current X and Y position of mouse, updated by mousemove event
- // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
- var cX, cY, pX, pY;
-
- // A private function for getting mouse position
- var track = function(ev) {
- cX = ev.pageX;
- cY = ev.pageY;
- };
-
- // A private function for comparing current and previous mouse position
- var compare = function(ev,ob) {
- ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
- // compare mouse positions to see if they've crossed the threshold
- if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
- $(ob).unbind("mousemove",track);
- // set hoverIntent state to true (so mouseOut can be called)
- ob.hoverIntent_s = 1;
- return cfg.over.apply(ob,[ev]);
- } else {
- // set previous coordinates for next time
- pX = cX; pY = cY;
- // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
- ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
- }
- };
-
- // A private function for delaying the mouseOut function
- var delay = function(ev,ob) {
- ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
- ob.hoverIntent_s = 0;
- return cfg.out.apply(ob,[ev]);
- };
-
- // A private function for handling mouse 'hovering'
- var handleHover = function(e) {
- // next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
- var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
- while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
- if ( p == this ) { return false; }
-
- // copy objects to be passed into t (required for event object to be passed in IE)
- var ev = $.extend({},e);
- var ob = this;
-
- // cancel hoverIntent timer if it exists
- if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
-
- // else e.type == "onmouseover"
- if (e.type == "mouseover") {
- // set "previous" X and Y position based on initial entry point
- pX = ev.pageX; pY = ev.pageY;
- // update "current" X and Y position based on mousemove
- $(ob).bind("mousemove",track);
- // start polling interval (self-calling timeout) to compare mouse coordinates over time
- if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
-
- // else e.type == "onmouseout"
- } else {
- // unbind expensive mousemove event
- $(ob).unbind("mousemove",track);
- // if hoverIntent state is true, then call the mouseOut function after the specified delay
- if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
- }
- };
-
- // bind the function to the two event listeners
- return this.mouseover(handleHover).mouseout(handleHover);
- };
-})(jQuery);
\ No newline at end of file
+++ /dev/null
-/*
- * ----------------------------- JSTORAGE -------------------------------------
- * Simple local storage wrapper to save data on the browser side, supporting
- * all major browsers - IE6+, Firefox2+, Safari4+, Chrome4+ and Opera 10.5+
- *
- * Author: Andris Reinman, andris.reinman@gmail.com
- * Project homepage: www.jstorage.info
- *
- * Licensed under Unlicense:
- *
- * This is free and unencumbered software released into the public domain.
- *
- * Anyone is free to copy, modify, publish, use, compile, sell, or
- * distribute this software, either in source code form or as a compiled
- * binary, for any purpose, commercial or non-commercial, and by any
- * means.
- *
- * In jurisdictions that recognize copyright laws, the author or authors
- * of this software dedicate any and all copyright interest in the
- * software to the public domain. We make this dedication for the benefit
- * of the public at large and to the detriment of our heirs and
- * successors. We intend this dedication to be an overt act of
- * relinquishment in perpetuity of all present and future rights to this
- * software under copyright law.
- *
- * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * For more information, please refer to <http://unlicense.org/>
- */
-
-/* global ActiveXObject: false */
-/* jshint browser: true */
-
-(function() {
- 'use strict';
-
- var
- /* jStorage version */
- JSTORAGE_VERSION = '0.4.12',
-
- /* detect a dollar object or create one if not found */
- $ = window.jQuery || window.$ || (window.$ = {}),
-
- /* check for a JSON handling support */
- JSON = {
- parse: window.JSON && (window.JSON.parse || window.JSON.decode) ||
- String.prototype.evalJSON && function(str) {
- return String(str).evalJSON();
- } ||
- $.parseJSON ||
- $.evalJSON,
- stringify: Object.toJSON ||
- window.JSON && (window.JSON.stringify || window.JSON.encode) ||
- $.toJSON
- };
-
- // Break if no JSON support was found
- if (typeof JSON.parse !== 'function' || typeof JSON.stringify !== 'function') {
- throw new Error('No JSON support found, include //cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js to page');
- }
-
- var
- /* This is the object, that holds the cached values */
- _storage = {
- __jstorage_meta: {
- CRC32: {}
- }
- },
-
- /* Actual browser storage (localStorage or globalStorage['domain']) */
- _storage_service = {
- jStorage: '{}'
- },
-
- /* DOM element for older IE versions, holds userData behavior */
- _storage_elm = null,
-
- /* How much space does the storage take */
- _storage_size = 0,
-
- /* which backend is currently used */
- _backend = false,
-
- /* onchange observers */
- _observers = {},
-
- /* timeout to wait after onchange event */
- _observer_timeout = false,
-
- /* last update time */
- _observer_update = 0,
-
- /* pubsub observers */
- _pubsub_observers = {},
-
- /* skip published items older than current timestamp */
- _pubsub_last = +new Date(),
-
- /* Next check for TTL */
- _ttl_timeout,
-
- /**
- * XML encoding and decoding as XML nodes can't be JSON'ized
- * XML nodes are encoded and decoded if the node is the value to be saved
- * but not if it's as a property of another object
- * Eg. -
- * $.jStorage.set('key', xmlNode); // IS OK
- * $.jStorage.set('key', {xml: xmlNode}); // NOT OK
- */
- _XMLService = {
-
- /**
- * Validates a XML node to be XML
- * based on jQuery.isXML function
- */
- isXML: function(elm) {
- var documentElement = (elm ? elm.ownerDocument || elm : 0).documentElement;
- return documentElement ? documentElement.nodeName !== 'HTML' : false;
- },
-
- /**
- * Encodes a XML node to string
- * based on http://www.mercurytide.co.uk/news/article/issues-when-working-ajax/
- */
- encode: function(xmlNode) {
- if (!this.isXML(xmlNode)) {
- return false;
- }
- try { // Mozilla, Webkit, Opera
- return new XMLSerializer().serializeToString(xmlNode);
- } catch (E1) {
- try { // IE
- return xmlNode.xml;
- } catch (E2) {}
- }
- return false;
- },
-
- /**
- * Decodes a XML node from string
- * loosely based on http://outwestmedia.com/jquery-plugins/xmldom/
- */
- decode: function(xmlString) {
- var dom_parser = ('DOMParser' in window && (new DOMParser()).parseFromString) ||
- (window.ActiveXObject && function(_xmlString) {
- var xml_doc = new ActiveXObject('Microsoft.XMLDOM');
- xml_doc.async = 'false';
- xml_doc.loadXML(_xmlString);
- return xml_doc;
- }),
- resultXML;
- if (!dom_parser) {
- return false;
- }
- resultXML = dom_parser.call('DOMParser' in window && (new DOMParser()) || window, xmlString, 'text/xml');
- return this.isXML(resultXML) ? resultXML : false;
- }
- };
-
-
- ////////////////////////// PRIVATE METHODS ////////////////////////
-
- /**
- * Initialization function. Detects if the browser supports DOM Storage
- * or userData behavior and behaves accordingly.
- */
- function _init() {
- /* Check if browser supports localStorage */
- var localStorageReallyWorks = false;
- if ('localStorage' in window) {
- try {
- window.localStorage.setItem('_tmptest', 'tmpval');
- localStorageReallyWorks = true;
- window.localStorage.removeItem('_tmptest');
- } catch (BogusQuotaExceededErrorOnIos5) {
- // Thanks be to iOS5 Private Browsing mode which throws
- // QUOTA_EXCEEDED_ERRROR DOM Exception 22.
- }
- }
-
- if (localStorageReallyWorks) {
- try {
- if (window.localStorage) {
- _storage_service = window.localStorage;
- _backend = 'localStorage';
- _observer_update = _storage_service.jStorage_update;
- }
- } catch (E3) { /* Firefox fails when touching localStorage and cookies are disabled */ }
- }
- /* Check if browser supports globalStorage */
- else if ('globalStorage' in window) {
- try {
- if (window.globalStorage) {
- if (window.location.hostname == 'localhost') {
- _storage_service = window.globalStorage['localhost.localdomain'];
- } else {
- _storage_service = window.globalStorage[window.location.hostname];
- }
- _backend = 'globalStorage';
- _observer_update = _storage_service.jStorage_update;
- }
- } catch (E4) { /* Firefox fails when touching localStorage and cookies are disabled */ }
- }
- /* Check if browser supports userData behavior */
- else {
- _storage_elm = document.createElement('link');
- if (_storage_elm.addBehavior) {
-
- /* Use a DOM element to act as userData storage */
- _storage_elm.style.behavior = 'url(#default#userData)';
-
- /* userData element needs to be inserted into the DOM! */
- document.getElementsByTagName('head')[0].appendChild(_storage_elm);
-
- try {
- _storage_elm.load('jStorage');
- } catch (E) {
- // try to reset cache
- _storage_elm.setAttribute('jStorage', '{}');
- _storage_elm.save('jStorage');
- _storage_elm.load('jStorage');
- }
-
- var data = '{}';
- try {
- data = _storage_elm.getAttribute('jStorage');
- } catch (E5) {}
-
- try {
- _observer_update = _storage_elm.getAttribute('jStorage_update');
- } catch (E6) {}
-
- _storage_service.jStorage = data;
- _backend = 'userDataBehavior';
- } else {
- _storage_elm = null;
- return;
- }
- }
-
- // Load data from storage
- _load_storage();
-
- // remove dead keys
- _handleTTL();
-
- // start listening for changes
- _setupObserver();
-
- // initialize publish-subscribe service
- _handlePubSub();
-
- // handle cached navigation
- if ('addEventListener' in window) {
- window.addEventListener('pageshow', function(event) {
- if (event.persisted) {
- _storageObserver();
- }
- }, false);
- }
- }
-
- /**
- * Reload data from storage when needed
- */
- function _reloadData() {
- var data = '{}';
-
- if (_backend == 'userDataBehavior') {
- _storage_elm.load('jStorage');
-
- try {
- data = _storage_elm.getAttribute('jStorage');
- } catch (E5) {}
-
- try {
- _observer_update = _storage_elm.getAttribute('jStorage_update');
- } catch (E6) {}
-
- _storage_service.jStorage = data;
- }
-
- _load_storage();
-
- // remove dead keys
- _handleTTL();
-
- _handlePubSub();
- }
-
- /**
- * Sets up a storage change observer
- */
- function _setupObserver() {
- if (_backend == 'localStorage' || _backend == 'globalStorage') {
- if ('addEventListener' in window) {
- window.addEventListener('storage', _storageObserver, false);
- } else {
- document.attachEvent('onstorage', _storageObserver);
- }
- } else if (_backend == 'userDataBehavior') {
- setInterval(_storageObserver, 1000);
- }
- }
-
- /**
- * Fired on any kind of data change, needs to check if anything has
- * really been changed
- */
- function _storageObserver() {
- var updateTime;
- // cumulate change notifications with timeout
- clearTimeout(_observer_timeout);
- _observer_timeout = setTimeout(function() {
-
- if (_backend == 'localStorage' || _backend == 'globalStorage') {
- updateTime = _storage_service.jStorage_update;
- } else if (_backend == 'userDataBehavior') {
- _storage_elm.load('jStorage');
- try {
- updateTime = _storage_elm.getAttribute('jStorage_update');
- } catch (E5) {}
- }
-
- if (updateTime && updateTime != _observer_update) {
- _observer_update = updateTime;
- _checkUpdatedKeys();
- }
-
- }, 25);
- }
-
- /**
- * Reloads the data and checks if any keys are changed
- */
- function _checkUpdatedKeys() {
- var oldCrc32List = JSON.parse(JSON.stringify(_storage.__jstorage_meta.CRC32)),
- newCrc32List;
-
- _reloadData();
- newCrc32List = JSON.parse(JSON.stringify(_storage.__jstorage_meta.CRC32));
-
- var key,
- updated = [],
- removed = [];
-
- for (key in oldCrc32List) {
- if (oldCrc32List.hasOwnProperty(key)) {
- if (!newCrc32List[key]) {
- removed.push(key);
- continue;
- }
- if (oldCrc32List[key] != newCrc32List[key] && String(oldCrc32List[key]).substr(0, 2) == '2.') {
- updated.push(key);
- }
- }
- }
-
- for (key in newCrc32List) {
- if (newCrc32List.hasOwnProperty(key)) {
- if (!oldCrc32List[key]) {
- updated.push(key);
- }
- }
- }
-
- _fireObservers(updated, 'updated');
- _fireObservers(removed, 'deleted');
- }
-
- /**
- * Fires observers for updated keys
- *
- * @param {Array|String} keys Array of key names or a key
- * @param {String} action What happened with the value (updated, deleted, flushed)
- */
- function _fireObservers(keys, action) {
- keys = [].concat(keys || []);
-
- var i, j, len, jlen;
-
- if (action == 'flushed') {
- keys = [];
- for (var key in _observers) {
- if (_observers.hasOwnProperty(key)) {
- keys.push(key);
- }
- }
- action = 'deleted';
- }
- for (i = 0, len = keys.length; i < len; i++) {
- if (_observers[keys[i]]) {
- for (j = 0, jlen = _observers[keys[i]].length; j < jlen; j++) {
- _observers[keys[i]][j](keys[i], action);
- }
- }
- if (_observers['*']) {
- for (j = 0, jlen = _observers['*'].length; j < jlen; j++) {
- _observers['*'][j](keys[i], action);
- }
- }
- }
- }
-
- /**
- * Publishes key change to listeners
- */
- function _publishChange() {
- var updateTime = (+new Date()).toString();
-
- if (_backend == 'localStorage' || _backend == 'globalStorage') {
- try {
- _storage_service.jStorage_update = updateTime;
- } catch (E8) {
- // safari private mode has been enabled after the jStorage initialization
- _backend = false;
- }
- } else if (_backend == 'userDataBehavior') {
- _storage_elm.setAttribute('jStorage_update', updateTime);
- _storage_elm.save('jStorage');
- }
-
- _storageObserver();
- }
-
- /**
- * Loads the data from the storage based on the supported mechanism
- */
- function _load_storage() {
- /* if jStorage string is retrieved, then decode it */
- if (_storage_service.jStorage) {
- try {
- _storage = JSON.parse(String(_storage_service.jStorage));
- } catch (E6) {
- _storage_service.jStorage = '{}';
- }
- } else {
- _storage_service.jStorage = '{}';
- }
- _storage_size = _storage_service.jStorage ? String(_storage_service.jStorage).length : 0;
-
- if (!_storage.__jstorage_meta) {
- _storage.__jstorage_meta = {};
- }
- if (!_storage.__jstorage_meta.CRC32) {
- _storage.__jstorage_meta.CRC32 = {};
- }
- }
-
- /**
- * This functions provides the 'save' mechanism to store the jStorage object
- */
- function _save() {
- _dropOldEvents(); // remove expired events
- try {
- _storage_service.jStorage = JSON.stringify(_storage);
- // If userData is used as the storage engine, additional
- if (_storage_elm) {
- _storage_elm.setAttribute('jStorage', _storage_service.jStorage);
- _storage_elm.save('jStorage');
- }
- _storage_size = _storage_service.jStorage ? String(_storage_service.jStorage).length : 0;
- } catch (E7) { /* probably cache is full, nothing is saved this way*/ }
- }
-
- /**
- * Function checks if a key is set and is string or numberic
- *
- * @param {String} key Key name
- */
- function _checkKey(key) {
- if (typeof key != 'string' && typeof key != 'number') {
- throw new TypeError('Key name must be string or numeric');
- }
- if (key == '__jstorage_meta') {
- throw new TypeError('Reserved key name');
- }
- return true;
- }
-
- /**
- * Removes expired keys
- */
- function _handleTTL() {
- var curtime, i, TTL, CRC32, nextExpire = Infinity,
- changed = false,
- deleted = [];
-
- clearTimeout(_ttl_timeout);
-
- if (!_storage.__jstorage_meta || typeof _storage.__jstorage_meta.TTL != 'object') {
- // nothing to do here
- return;
- }
-
- curtime = +new Date();
- TTL = _storage.__jstorage_meta.TTL;
-
- CRC32 = _storage.__jstorage_meta.CRC32;
- for (i in TTL) {
- if (TTL.hasOwnProperty(i)) {
- if (TTL[i] <= curtime) {
- delete TTL[i];
- delete CRC32[i];
- delete _storage[i];
- changed = true;
- deleted.push(i);
- } else if (TTL[i] < nextExpire) {
- nextExpire = TTL[i];
- }
- }
- }
-
- // set next check
- if (nextExpire != Infinity) {
- _ttl_timeout = setTimeout(_handleTTL, Math.min(nextExpire - curtime, 0x7FFFFFFF));
- }
-
- // save changes
- if (changed) {
- _save();
- _publishChange();
- _fireObservers(deleted, 'deleted');
- }
- }
-
- /**
- * Checks if there's any events on hold to be fired to listeners
- */
- function _handlePubSub() {
- var i, len;
- if (!_storage.__jstorage_meta.PubSub) {
- return;
- }
- var pubelm,
- _pubsubCurrent = _pubsub_last,
- needFired = [];
-
- for (i = len = _storage.__jstorage_meta.PubSub.length - 1; i >= 0; i--) {
- pubelm = _storage.__jstorage_meta.PubSub[i];
- if (pubelm[0] > _pubsub_last) {
- _pubsubCurrent = pubelm[0];
- needFired.unshift(pubelm);
- }
- }
-
- for (i = needFired.length - 1; i >= 0; i--) {
- _fireSubscribers(needFired[i][1], needFired[i][2]);
- }
-
- _pubsub_last = _pubsubCurrent;
- }
-
- /**
- * Fires all subscriber listeners for a pubsub channel
- *
- * @param {String} channel Channel name
- * @param {Mixed} payload Payload data to deliver
- */
- function _fireSubscribers(channel, payload) {
- if (_pubsub_observers[channel]) {
- for (var i = 0, len = _pubsub_observers[channel].length; i < len; i++) {
- // send immutable data that can't be modified by listeners
- try {
- _pubsub_observers[channel][i](channel, JSON.parse(JSON.stringify(payload)));
- } catch (E) {}
- }
- }
- }
-
- /**
- * Remove old events from the publish stream (at least 2sec old)
- */
- function _dropOldEvents() {
- if (!_storage.__jstorage_meta.PubSub) {
- return;
- }
-
- var retire = +new Date() - 2000;
-
- for (var i = 0, len = _storage.__jstorage_meta.PubSub.length; i < len; i++) {
- if (_storage.__jstorage_meta.PubSub[i][0] <= retire) {
- // deleteCount is needed for IE6
- _storage.__jstorage_meta.PubSub.splice(i, _storage.__jstorage_meta.PubSub.length - i);
- break;
- }
- }
-
- if (!_storage.__jstorage_meta.PubSub.length) {
- delete _storage.__jstorage_meta.PubSub;
- }
-
- }
-
- /**
- * Publish payload to a channel
- *
- * @param {String} channel Channel name
- * @param {Mixed} payload Payload to send to the subscribers
- */
- function _publish(channel, payload) {
- if (!_storage.__jstorage_meta) {
- _storage.__jstorage_meta = {};
- }
- if (!_storage.__jstorage_meta.PubSub) {
- _storage.__jstorage_meta.PubSub = [];
- }
-
- _storage.__jstorage_meta.PubSub.unshift([+new Date(), channel, payload]);
-
- _save();
- _publishChange();
- }
-
-
- /**
- * JS Implementation of MurmurHash2
- *
- * SOURCE: https://github.com/garycourt/murmurhash-js (MIT licensed)
- *
- * @author <a href='mailto:gary.court@gmail.com'>Gary Court</a>
- * @see http://github.com/garycourt/murmurhash-js
- * @author <a href='mailto:aappleby@gmail.com'>Austin Appleby</a>
- * @see http://sites.google.com/site/murmurhash/
- *
- * @param {string} str ASCII only
- * @param {number} seed Positive integer only
- * @return {number} 32-bit positive integer hash
- */
-
- function murmurhash2_32_gc(str, seed) {
- var
- l = str.length,
- h = seed ^ l,
- i = 0,
- k;
-
- while (l >= 4) {
- k =
- ((str.charCodeAt(i) & 0xff)) |
- ((str.charCodeAt(++i) & 0xff) << 8) |
- ((str.charCodeAt(++i) & 0xff) << 16) |
- ((str.charCodeAt(++i) & 0xff) << 24);
-
- k = (((k & 0xffff) * 0x5bd1e995) + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16));
- k ^= k >>> 24;
- k = (((k & 0xffff) * 0x5bd1e995) + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16));
-
- h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16)) ^ k;
-
- l -= 4;
- ++i;
- }
-
- switch (l) {
- case 3:
- h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
- /* falls through */
- case 2:
- h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
- /* falls through */
- case 1:
- h ^= (str.charCodeAt(i) & 0xff);
- h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16));
- }
-
- h ^= h >>> 13;
- h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16));
- h ^= h >>> 15;
-
- return h >>> 0;
- }
-
- ////////////////////////// PUBLIC INTERFACE /////////////////////////
-
- $.jStorage = {
- /* Version number */
- version: JSTORAGE_VERSION,
-
- /**
- * Sets a key's value.
- *
- * @param {String} key Key to set. If this value is not set or not
- * a string an exception is raised.
- * @param {Mixed} value Value to set. This can be any value that is JSON
- * compatible (Numbers, Strings, Objects etc.).
- * @param {Object} [options] - possible options to use
- * @param {Number} [options.TTL] - optional TTL value, in milliseconds
- * @return {Mixed} the used value
- */
- set: function(key, value, options) {
- _checkKey(key);
-
- options = options || {};
-
- // undefined values are deleted automatically
- if (typeof value == 'undefined') {
- this.deleteKey(key);
- return value;
- }
-
- if (_XMLService.isXML(value)) {
- value = {
- _is_xml: true,
- xml: _XMLService.encode(value)
- };
- } else if (typeof value == 'function') {
- return undefined; // functions can't be saved!
- } else if (value && typeof value == 'object') {
- // clone the object before saving to _storage tree
- value = JSON.parse(JSON.stringify(value));
- }
-
- _storage[key] = value;
-
- _storage.__jstorage_meta.CRC32[key] = '2.' + murmurhash2_32_gc(JSON.stringify(value), 0x9747b28c);
-
- this.setTTL(key, options.TTL || 0); // also handles saving and _publishChange
-
- _fireObservers(key, 'updated');
- return value;
- },
-
- /**
- * Looks up a key in cache
- *
- * @param {String} key - Key to look up.
- * @param {mixed} def - Default value to return, if key didn't exist.
- * @return {Mixed} the key value, default value or null
- */
- get: function(key, def) {
- _checkKey(key);
- if (key in _storage) {
- if (_storage[key] && typeof _storage[key] == 'object' && _storage[key]._is_xml) {
- return _XMLService.decode(_storage[key].xml);
- } else {
- return _storage[key];
- }
- }
- return typeof(def) == 'undefined' ? null : def;
- },
-
- /**
- * Deletes a key from cache.
- *
- * @param {String} key - Key to delete.
- * @return {Boolean} true if key existed or false if it didn't
- */
- deleteKey: function(key) {
- _checkKey(key);
- if (key in _storage) {
- delete _storage[key];
- // remove from TTL list
- if (typeof _storage.__jstorage_meta.TTL == 'object' &&
- key in _storage.__jstorage_meta.TTL) {
- delete _storage.__jstorage_meta.TTL[key];
- }
-
- delete _storage.__jstorage_meta.CRC32[key];
-
- _save();
- _publishChange();
- _fireObservers(key, 'deleted');
- return true;
- }
- return false;
- },
-
- /**
- * Sets a TTL for a key, or remove it if ttl value is 0 or below
- *
- * @param {String} key - key to set the TTL for
- * @param {Number} ttl - TTL timeout in milliseconds
- * @return {Boolean} true if key existed or false if it didn't
- */
- setTTL: function(key, ttl) {
- var curtime = +new Date();
- _checkKey(key);
- ttl = Number(ttl) || 0;
- if (key in _storage) {
-
- if (!_storage.__jstorage_meta.TTL) {
- _storage.__jstorage_meta.TTL = {};
- }
-
- // Set TTL value for the key
- if (ttl > 0) {
- _storage.__jstorage_meta.TTL[key] = curtime + ttl;
- } else {
- delete _storage.__jstorage_meta.TTL[key];
- }
-
- _save();
-
- _handleTTL();
-
- _publishChange();
- return true;
- }
- return false;
- },
-
- /**
- * Gets remaining TTL (in milliseconds) for a key or 0 when no TTL has been set
- *
- * @param {String} key Key to check
- * @return {Number} Remaining TTL in milliseconds
- */
- getTTL: function(key) {
- var curtime = +new Date(),
- ttl;
- _checkKey(key);
- if (key in _storage && _storage.__jstorage_meta.TTL && _storage.__jstorage_meta.TTL[key]) {
- ttl = _storage.__jstorage_meta.TTL[key] - curtime;
- return ttl || 0;
- }
- return 0;
- },
-
- /**
- * Deletes everything in cache.
- *
- * @return {Boolean} Always true
- */
- flush: function() {
- _storage = {
- __jstorage_meta: {
- CRC32: {}
- }
- };
- _save();
- _publishChange();
- _fireObservers(null, 'flushed');
- return true;
- },
-
- /**
- * Returns a read-only copy of _storage
- *
- * @return {Object} Read-only copy of _storage
- */
- storageObj: function() {
- function F() {}
- F.prototype = _storage;
- return new F();
- },
-
- /**
- * Returns an index of all used keys as an array
- * ['key1', 'key2',..'keyN']
- *
- * @return {Array} Used keys
- */
- index: function() {
- var index = [],
- i;
- for (i in _storage) {
- if (_storage.hasOwnProperty(i) && i != '__jstorage_meta') {
- index.push(i);
- }
- }
- return index;
- },
-
- /**
- * How much space in bytes does the storage take?
- *
- * @return {Number} Storage size in chars (not the same as in bytes,
- * since some chars may take several bytes)
- */
- storageSize: function() {
- return _storage_size;
- },
-
- /**
- * Which backend is currently in use?
- *
- * @return {String} Backend name
- */
- currentBackend: function() {
- return _backend;
- },
-
- /**
- * Test if storage is available
- *
- * @return {Boolean} True if storage can be used
- */
- storageAvailable: function() {
- return !!_backend;
- },
-
- /**
- * Register change listeners
- *
- * @param {String} key Key name
- * @param {Function} callback Function to run when the key changes
- */
- listenKeyChange: function(key, callback) {
- _checkKey(key);
- if (!_observers[key]) {
- _observers[key] = [];
- }
- _observers[key].push(callback);
- },
-
- /**
- * Remove change listeners
- *
- * @param {String} key Key name to unregister listeners against
- * @param {Function} [callback] If set, unregister the callback, if not - unregister all
- */
- stopListening: function(key, callback) {
- _checkKey(key);
-
- if (!_observers[key]) {
- return;
- }
-
- if (!callback) {
- delete _observers[key];
- return;
- }
-
- for (var i = _observers[key].length - 1; i >= 0; i--) {
- if (_observers[key][i] == callback) {
- _observers[key].splice(i, 1);
- }
- }
- },
-
- /**
- * Subscribe to a Publish/Subscribe event stream
- *
- * @param {String} channel Channel name
- * @param {Function} callback Function to run when the something is published to the channel
- */
- subscribe: function(channel, callback) {
- channel = (channel || '').toString();
- if (!channel) {
- throw new TypeError('Channel not defined');
- }
- if (!_pubsub_observers[channel]) {
- _pubsub_observers[channel] = [];
- }
- _pubsub_observers[channel].push(callback);
- },
-
- /**
- * Publish data to an event stream
- *
- * @param {String} channel Channel name
- * @param {Mixed} payload Payload to deliver
- */
- publish: function(channel, payload) {
- channel = (channel || '').toString();
- if (!channel) {
- throw new TypeError('Channel not defined');
- }
-
- _publish(channel, payload);
- },
-
- /**
- * Reloads the data from browser storage
- */
- reInit: function() {
- _reloadData();
- },
-
- /**
- * Removes reference from global objects and saves it as jStorage
- *
- * @param {Boolean} option if needed to save object as simple 'jStorage' in windows context
- */
- noConflict: function(saveInGlobal) {
- delete window.$.jStorage;
-
- if (saveInGlobal) {
- window.jStorage = this;
- }
-
- return this;
- }
- };
-
- // Initialize jStorage
- _init();
-
-})();
+++ /dev/null
-/*!
- * MockJax - jQuery Plugin to Mock Ajax requests
- *
- * Version: 1.4.0
- * Released: 2011-02-04
- * Source: http://github.com/appendto/jquery-mockjax
- * Docs: http://enterprisejquery.com/2010/07/mock-your-ajax-requests-with-mockjax-for-rapid-development
- * Plugin: mockjax
- * Author: Jonathan Sharp (http://jdsharp.com)
- * License: MIT,GPL
- *
- * Copyright (c) 2010 appendTo LLC.
- * Dual licensed under the MIT or GPL licenses.
- * http://appendto.com/open-source-licenses
- */
-(function($) {
- var _ajax = $.ajax,
- mockHandlers = [];
-
- function parseXML(xml) {
- if ( window['DOMParser'] == undefined && window.ActiveXObject ) {
- DOMParser = function() { };
- DOMParser.prototype.parseFromString = function( xmlString ) {
- var doc = new ActiveXObject('Microsoft.XMLDOM');
- doc.async = 'false';
- doc.loadXML( xmlString );
- return doc;
- };
- }
-
- try {
- var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' );
- if ( $.isXMLDoc( xmlDoc ) ) {
- var err = $('parsererror', xmlDoc);
- if ( err.length == 1 ) {
- throw('Error: ' + $(xmlDoc).text() );
- }
- } else {
- throw('Unable to parse XML');
- }
- } catch( e ) {
- var msg = ( e.name == undefined ? e : e.name + ': ' + e.message );
- $(document).trigger('xmlParseError', [ msg ]);
- return undefined;
- }
- return xmlDoc;
- }
-
- $.extend({
- ajax: function(origSettings) {
- var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
- mock = false;
- // Iterate over our mock handlers (in registration order) until we find
- // one that is willing to intercept the request
- $.each(mockHandlers, function(k, v) {
- if ( !mockHandlers[k] ) {
- return;
- }
- var m = null;
- // If the mock was registered with a function, let the function decide if we
- // want to mock this request
- if ( $.isFunction(mockHandlers[k]) ) {
- m = mockHandlers[k](s);
- } else {
- m = mockHandlers[k];
- // Inspect the URL of the request and check if the mock handler's url
- // matches the url for this ajax request
- if ( $.isFunction(m.url.test) ) {
- // The user provided a regex for the url, test it
- if ( !m.url.test( s.url ) ) {
- m = null;
- }
- } else {
- // Look for a simple wildcard '*' or a direct URL match
- var star = m.url.indexOf('*');
- if ( ( m.url != '*' && m.url != s.url && star == -1 ) ||
- ( star > -1 && m.url.substr(0, star) != s.url.substr(0, star) ) ) {
- // The url we tested did not match the wildcard *
- m = null;
- }
- }
- if ( m ) {
- // Inspect the data submitted in the request (either POST body or GET query string)
- if ( m.data && s.data ) {
- var identical = false;
- // Deep inspect the identity of the objects
- (function ident(mock, live) {
- // Test for situations where the data is a querystring (not an object)
- if (typeof live === 'string') {
- // Querystring may be a regex
- identical = $.isFunction( mock.test ) ? mock.test(live) : mock == live;
- return identical;
- }
- $.each(mock, function(k, v) {
- if ( live[k] === undefined ) {
- identical = false;
- return false;
- } else {
- identical = true;
- if ( typeof live[k] == 'object' ) {
- return ident(mock[k], live[k]);
- } else {
- if ( $.isFunction( mock[k].test ) ) {
- identical = mock[k].test(live[k]);
- } else {
- identical = ( mock[k] == live[k] );
- }
- return identical;
- }
- }
- });
- })(m.data, s.data);
- // They're not identical, do not mock this request
- if ( identical == false ) {
- m = null;
- }
- }
- // Inspect the request type
- if ( m && m.type && m.type != s.type ) {
- // The request type doesn't match (GET vs. POST)
- m = null;
- }
- }
- }
- if ( m ) {
- mock = true;
-
- // Handle console logging
- var c = $.extend({}, $.mockjaxSettings, m);
- if ( c.log && $.isFunction(c.log) ) {
- c.log('MOCK ' + s.type.toUpperCase() + ': ' + s.url, $.extend({}, s));
- }
-
- var jsre = /=\?(&|$)/, jsc = (new Date()).getTime();
-
- // Handle JSONP Parameter Callbacks, we need to replicate some of the jQuery core here
- // because there isn't an easy hook for the cross domain script tag of jsonp
- if ( s.dataType === "jsonp" ) {
- if ( s.type.toUpperCase() === "GET" ) {
- if ( !jsre.test( s.url ) ) {
- s.url += (rquery.test( s.url ) ? "&" : "?") + (s.jsonp || "callback") + "=?";
- }
- } else if ( !s.data || !jsre.test(s.data) ) {
- s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
- }
- s.dataType = "json";
- }
-
- // Build temporary JSONP function
- if ( s.dataType === "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) {
- jsonp = s.jsonpCallback || ("jsonp" + jsc++);
-
- // Replace the =? sequence both in the query string and the data
- if ( s.data ) {
- s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
- }
-
- s.url = s.url.replace(jsre, "=" + jsonp + "$1");
-
- // We need to make sure
- // that a JSONP style response is executed properly
- s.dataType = "script";
-
- // Handle JSONP-style loading
- window[ jsonp ] = window[ jsonp ] || function( tmp ) {
- data = tmp;
- success();
- complete();
- // Garbage collect
- window[ jsonp ] = undefined;
-
- try {
- delete window[ jsonp ];
- } catch(e) {}
-
- if ( head ) {
- head.removeChild( script );
- }
- };
- }
-
- var rurl = /^(\w+:)?\/\/([^\/?#]+)/,
- parts = rurl.exec( s.url ),
- remote = parts && (parts[1] && parts[1] !== location.protocol || parts[2] !== location.host);
-
- // Test if we are going to create a script tag (if so, intercept & mock)
- if ( s.dataType === "script" && s.type.toUpperCase() === "GET" && remote ) {
- // Synthesize the mock request for adding a script tag
- var callbackContext = origSettings && origSettings.context || s;
-
- function success() {
- // If a local callback was specified, fire it and pass it the data
- if ( s.success ) {
- s.success.call( callbackContext, ( m.response ? m.response.toString() : m.responseText || ''), status, {} );
- }
-
- // Fire the global callback
- if ( s.global ) {
- trigger( "ajaxSuccess", [{}, s] );
- }
- }
-
- function complete() {
- // Process result
- if ( s.complete ) {
- s.complete.call( callbackContext, {} , status );
- }
-
- // The request was completed
- if ( s.global ) {
- trigger( "ajaxComplete", [{}, s] );
- }
-
- // Handle the global AJAX counter
- if ( s.global && ! --jQuery.active ) {
- jQuery.event.trigger( "ajaxStop" );
- }
- }
-
- function trigger(type, args) {
- (s.context ? jQuery(s.context) : jQuery.event).trigger(type, args);
- }
-
- if ( m.response && $.isFunction(m.response) ) {
- m.response(origSettings);
- } else {
- $.globalEval(m.responseText);
- }
- success();
- complete();
- return false;
- }
- mock = _ajax.call($, $.extend(true, {}, origSettings, {
- // Mock the XHR object
- xhr: function() {
- // Extend with our default mockjax settings
- m = $.extend({}, $.mockjaxSettings, m);
-
- if ( m.contentType ) {
- m.headers['content-type'] = m.contentType;
- }
-
- // Return our mock xhr object
- return {
- status: m.status,
- readyState: 1,
- open: function() { },
- send: function() {
- // This is a substitute for < 1.4 which lacks $.proxy
- var process = (function(that) {
- return function() {
- return (function() {
- // The request has returned
- this.status = m.status;
- this.readyState = 4;
-
- // We have an executable function, call it to give
- // the mock handler a chance to update it's data
- if ( $.isFunction(m.response) ) {
- m.response(origSettings);
- }
- // Copy over our mock to our xhr object before passing control back to
- // jQuery's onreadystatechange callback
- if ( s.dataType == 'json' && ( typeof m.responseText == 'object' ) ) {
- this.responseText = JSON.stringify(m.responseText);
- } else if ( s.dataType == 'xml' ) {
- if ( typeof m.responseXML == 'string' ) {
- this.responseXML = parseXML(m.responseXML);
- } else {
- this.responseXML = m.responseXML;
- }
- } else {
- this.responseText = m.responseText;
- }
- // jQuery < 1.4 doesn't have onreadystate change for xhr
- if ( $.isFunction(this.onreadystatechange) ) {
- this.onreadystatechange( m.isTimeout ? 'timeout' : undefined );
- }
- }).apply(that);
- };
- })(this);
-
- if ( m.proxy ) {
- // We're proxying this request and loading in an external file instead
- _ajax({
- global: false,
- url: m.proxy,
- type: m.proxyType,
- data: m.data,
- dataType: s.dataType,
- complete: function(xhr, txt) {
- m.responseXML = xhr.responseXML;
- m.responseText = xhr.responseText;
- this.responseTimer = setTimeout(process, m.responseTime || 0);
- }
- });
- } else {
- // type == 'POST' || 'GET' || 'DELETE'
- if ( s.async === false ) {
- // TODO: Blocking delay
- process();
- } else {
- this.responseTimer = setTimeout(process, m.responseTime || 50);
- }
- }
- },
- abort: function() {
- clearTimeout(this.responseTimer);
- },
- setRequestHeader: function() { },
- getResponseHeader: function(header) {
- // 'Last-modified', 'Etag', 'content-type' are all checked by jQuery
- if ( m.headers && m.headers[header] ) {
- // Return arbitrary headers
- return m.headers[header];
- } else if ( header.toLowerCase() == 'last-modified' ) {
- return m.lastModified || (new Date()).toString();
- } else if ( header.toLowerCase() == 'etag' ) {
- return m.etag || '';
- } else if ( header.toLowerCase() == 'content-type' ) {
- return m.contentType || 'text/plain';
- }
- },
- getAllResponseHeaders: function() {
- var headers = '';
- $.each(m.headers, function(k, v) {
- headers += k + ': ' + v + "\n";
- });
- return headers;
- }
- };
- }
- }));
- return false;
- }
- });
- // We don't have a mock request, trigger a normal request
- if ( !mock ) {
- return _ajax.apply($, arguments);
- } else {
- return mock;
- }
- }
- });
-
- $.mockjaxSettings = {
- //url: null,
- //type: 'GET',
- log: function(msg) {
- window['console'] && window.console.log && window.console.log(msg);
- },
- status: 200,
- responseTime: 500,
- isTimeout: false,
- contentType: 'text/plain',
- response: '',
- responseText: '',
- responseXML: '',
- proxy: '',
- proxyType: 'GET',
-
- lastModified: null,
- etag: '',
- headers: {
- etag: 'IJF@H#@923uf8023hFO@I#H#',
- 'content-type' : 'text/plain'
- }
- };
-
- $.mockjax = function(settings) {
- var i = mockHandlers.length;
- mockHandlers[i] = settings;
- return i;
- };
- $.mockjaxClear = function(i) {
- if ( arguments.length == 1 ) {
- mockHandlers[i] = null;
- } else {
- mockHandlers = [];
- }
- };
-})(jQuery);
+++ /dev/null
-/*!
- * jQuery xmlDOM Plugin v1.0
- * http://outwestmedia.com/jquery-plugins/xmldom/
- *
- * Released: 2009-04-06
- * Version: 1.0
- *
- * Copyright (c) 2009 Jonathan Sharp, Out West Media LLC.
- * Dual licensed under the MIT and GPL licenses.
- * http://docs.jquery.com/License
- */
-(function($) {
- // IE DOMParser wrapper
- if ( window['DOMParser'] == undefined && window.ActiveXObject ) {
- DOMParser = function() { };
- DOMParser.prototype.parseFromString = function( xmlString ) {
- var doc = new ActiveXObject('Microsoft.XMLDOM');
- doc.async = 'false';
- doc.loadXML( xmlString );
- return doc;
- };
- }
-
- $.xmlDOM = function(xml, onErrorFn) {
- try {
- var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' );
- if ( $.isXMLDoc( xmlDoc ) ) {
- var err = $('parsererror', xmlDoc);
- if ( err.length == 1 ) {
- throw('Error: ' + $(xmlDoc).text() );
- }
- } else {
- throw('Unable to parse XML');
- }
- } catch( e ) {
- var msg = ( e.name == undefined ? e : e.name + ': ' + e.message );
- if ( $.isFunction( onErrorFn ) ) {
- onErrorFn( msg );
- } else {
- $(document).trigger('xmlParseError', [ msg ]);
- }
- return $([]);
- }
- return $( xmlDoc );
- };
-})(jQuery);
\ No newline at end of file