Version Description
Security fix
Download this release
Release Info
| Developer | tlovett1 |
| Plugin | |
| Version | 5.1.0.4 |
| Comparing to | |
| See all releases | |
Code changes from version 5.1.0.3 to 5.1.0.4
- README.md +0 -4
- custom-contact-forms-admin.php +0 -6
- custom-contact-forms.php +2 -2
- js/jquery.form.js +864 -864
- readme.txt +4 -1
README.md
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
custom-contact-forms
|
| 2 |
-
====================
|
| 3 |
-
|
| 4 |
-
Custom Contact Forms is a WordPress plugin
|
|
|
|
|
|
|
|
|
|
|
|
custom-contact-forms-admin.php
CHANGED
|
@@ -7,12 +7,6 @@
|
|
| 7 |
if (!class_exists('CustomContactFormsAdmin')) {
|
| 8 |
class CustomContactFormsAdmin extends CustomContactForms {
|
| 9 |
var $action_complete = '';
|
| 10 |
-
|
| 11 |
-
function adminInit() {
|
| 12 |
-
$this->downloadExportFile();
|
| 13 |
-
$this->downloadCSVExportFile();
|
| 14 |
-
$this->runImport();
|
| 15 |
-
}
|
| 16 |
|
| 17 |
function insertUsagePopover() {
|
| 18 |
ccf_utils::load_module('usage_popover/custom-contact-forms-usage-popover.php');
|
| 7 |
if (!class_exists('CustomContactFormsAdmin')) {
|
| 8 |
class CustomContactFormsAdmin extends CustomContactForms {
|
| 9 |
var $action_complete = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
function insertUsagePopover() {
|
| 12 |
ccf_utils::load_module('usage_popover/custom-contact-forms-usage-popover.php');
|
custom-contact-forms.php
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
Plugin Name: Custom Contact Forms
|
| 4 |
Plugin URI: http://taylorlovett.com/wordpress-plugins
|
| 5 |
Description: Guaranteed to be 1000X more customizable and intuitive than Fast Secure Contact Forms or Contact Form 7. Customize every aspect of your forms without any knowledge of CSS: borders, padding, sizes, colors. Ton's of great features. Required fields, form submissions saved to database, captchas, tooltip popovers, unlimited fields/forms/form styles, import/export, use a custom thank you page or built-in popover with a custom success message set for each form.
|
| 6 |
-
Version: 5.1.0.
|
| 7 |
Author: Taylor Lovett
|
| 8 |
Author URI: http://www.taylorlovett.com
|
| 9 |
*/
|
|
@@ -120,7 +120,7 @@ if (!is_admin()) { /* is front */
|
|
| 120 |
}
|
| 121 |
add_action('wp_dashboard_setup', array(&$ccf_dashboard, 'install'));
|
| 122 |
}
|
| 123 |
-
|
| 124 |
if ($custom_contact_admin->isPluginAdminPage()) {
|
| 125 |
add_action('admin_print_styles', array(&$custom_contact_admin, 'insertBackEndStyles'), 1);
|
| 126 |
add_action('admin_enqueue_scripts', array(&$custom_contact_admin, 'insertAdminScripts'), 1);
|
| 3 |
Plugin Name: Custom Contact Forms
|
| 4 |
Plugin URI: http://taylorlovett.com/wordpress-plugins
|
| 5 |
Description: Guaranteed to be 1000X more customizable and intuitive than Fast Secure Contact Forms or Contact Form 7. Customize every aspect of your forms without any knowledge of CSS: borders, padding, sizes, colors. Ton's of great features. Required fields, form submissions saved to database, captchas, tooltip popovers, unlimited fields/forms/form styles, import/export, use a custom thank you page or built-in popover with a custom success message set for each form.
|
| 6 |
+
Version: 5.1.0.4
|
| 7 |
Author: Taylor Lovett
|
| 8 |
Author URI: http://www.taylorlovett.com
|
| 9 |
*/
|
| 120 |
}
|
| 121 |
add_action('wp_dashboard_setup', array(&$ccf_dashboard, 'install'));
|
| 122 |
}
|
| 123 |
+
|
| 124 |
if ($custom_contact_admin->isPluginAdminPage()) {
|
| 125 |
add_action('admin_print_styles', array(&$custom_contact_admin, 'insertBackEndStyles'), 1);
|
| 126 |
add_action('admin_enqueue_scripts', array(&$custom_contact_admin, 'insertAdminScripts'), 1);
|
js/jquery.form.js
CHANGED
|
@@ -1,864 +1,864 @@
|
|
| 1 |
-
/*!
|
| 2 |
-
* jQuery Form Plugin
|
| 3 |
-
* version: 2.80 (25-MAY-2011)
|
| 4 |
-
* @requires jQuery v1.3.2 or later
|
| 5 |
-
*
|
| 6 |
-
* Examples and documentation at: http://malsup.com/jquery/form/
|
| 7 |
-
* Dual licensed under the MIT and GPL licenses:
|
| 8 |
-
* http://www.opensource.org/licenses/mit-license.php
|
| 9 |
-
* http://www.gnu.org/licenses/gpl.html
|
| 10 |
-
*/
|
| 11 |
-
;(function($) {
|
| 12 |
-
|
| 13 |
-
/*
|
| 14 |
-
Usage Note:
|
| 15 |
-
-----------
|
| 16 |
-
Do not use both ajaxSubmit and ajaxForm on the same form. These
|
| 17 |
-
functions are intended to be exclusive. Use ajaxSubmit if you want
|
| 18 |
-
to bind your own submit handler to the form. For example,
|
| 19 |
-
|
| 20 |
-
$(document).ready(function() {
|
| 21 |
-
$('#myForm').bind('submit', function(e) {
|
| 22 |
-
e.preventDefault(); // <-- important
|
| 23 |
-
$(this).ajaxSubmit({
|
| 24 |
-
target: '#output'
|
| 25 |
-
});
|
| 26 |
-
});
|
| 27 |
-
});
|
| 28 |
-
|
| 29 |
-
Use ajaxForm when you want the plugin to manage all the event binding
|
| 30 |
-
for you. For example,
|
| 31 |
-
|
| 32 |
-
$(document).ready(function() {
|
| 33 |
-
$('#myForm').ajaxForm({
|
| 34 |
-
target: '#output'
|
| 35 |
-
});
|
| 36 |
-
});
|
| 37 |
-
|
| 38 |
-
When using ajaxForm, the ajaxSubmit function will be invoked for you
|
| 39 |
-
at the appropriate time.
|
| 40 |
-
*/
|
| 41 |
-
|
| 42 |
-
/**
|
| 43 |
-
* ajaxSubmit() provides a mechanism for immediately submitting
|
| 44 |
-
* an HTML form using AJAX.
|
| 45 |
-
*/
|
| 46 |
-
$.fn.ajaxSubmit = function(options) {
|
| 47 |
-
// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
|
| 48 |
-
if (!this.length) {
|
| 49 |
-
log('ajaxSubmit: skipping submit process - no element selected');
|
| 50 |
-
return this;
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
if (typeof options == 'function') {
|
| 54 |
-
options = { success: options };
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
var action = this.attr('action');
|
| 58 |
-
var url = (typeof action === 'string') ? $.trim(action) : '';
|
| 59 |
-
url = url || window.location.href || '';
|
| 60 |
-
if (url) {
|
| 61 |
-
// clean url (don't include hash vaue)
|
| 62 |
-
url = (url.match(/^([^#]+)/)||[])[1];
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
options = $.extend(true, {
|
| 66 |
-
url: url,
|
| 67 |
-
success: $.ajaxSettings.success,
|
| 68 |
-
type: this[0].getAttribute('method') || 'GET', // IE7 massage (see issue 57)
|
| 69 |
-
iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
|
| 70 |
-
}, options);
|
| 71 |
-
|
| 72 |
-
// hook for manipulating the form data before it is extracted;
|
| 73 |
-
// convenient for use with rich editors like tinyMCE or FCKEditor
|
| 74 |
-
var veto = {};
|
| 75 |
-
this.trigger('form-pre-serialize', [this, options, veto]);
|
| 76 |
-
if (veto.veto) {
|
| 77 |
-
log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
|
| 78 |
-
return this;
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
// provide opportunity to alter form data before it is serialized
|
| 82 |
-
if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
|
| 83 |
-
log('ajaxSubmit: submit aborted via beforeSerialize callback');
|
| 84 |
-
return this;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
var n,v,a = this.formToArray(options.semantic);
|
| 88 |
-
if (options.data) {
|
| 89 |
-
options.extraData = options.data;
|
| 90 |
-
for (n in options.data) {
|
| 91 |
-
if(options.data[n] instanceof Array) {
|
| 92 |
-
for (var k in options.data[n]) {
|
| 93 |
-
a.push( { name: n, value: options.data[n][k] } );
|
| 94 |
-
}
|
| 95 |
-
}
|
| 96 |
-
else {
|
| 97 |
-
v = options.data[n];
|
| 98 |
-
v = $.isFunction(v) ? v() : v; // if value is fn, invoke it
|
| 99 |
-
a.push( { name: n, value: v } );
|
| 100 |
-
}
|
| 101 |
-
}
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
// give pre-submit callback an opportunity to abort the submit
|
| 105 |
-
if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
|
| 106 |
-
log('ajaxSubmit: submit aborted via beforeSubmit callback');
|
| 107 |
-
return this;
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
// fire vetoable 'validate' event
|
| 111 |
-
this.trigger('form-submit-validate', [a, this, options, veto]);
|
| 112 |
-
if (veto.veto) {
|
| 113 |
-
log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
|
| 114 |
-
return this;
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
var q = $.param(a);
|
| 118 |
-
|
| 119 |
-
if (options.type.toUpperCase() == 'GET') {
|
| 120 |
-
options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
|
| 121 |
-
options.data = null; // data is null for 'get'
|
| 122 |
-
}
|
| 123 |
-
else {
|
| 124 |
-
options.data = q; // data is the query string for 'post'
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
var $form = this, callbacks = [];
|
| 128 |
-
if (options.resetForm) {
|
| 129 |
-
callbacks.push(function() { $form.resetForm(); });
|
| 130 |
-
}
|
| 131 |
-
if (options.clearForm) {
|
| 132 |
-
callbacks.push(function() { $form.clearForm(); });
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
// perform a load on the target only if dataType is not provided
|
| 136 |
-
if (!options.dataType && options.target) {
|
| 137 |
-
var oldSuccess = options.success || function(){};
|
| 138 |
-
callbacks.push(function(data) {
|
| 139 |
-
var fn = options.replaceTarget ? 'replaceWith' : 'html';
|
| 140 |
-
$(options.target)[fn](data).each(oldSuccess, arguments);
|
| 141 |
-
});
|
| 142 |
-
}
|
| 143 |
-
else if (options.success) {
|
| 144 |
-
callbacks.push(options.success);
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
|
| 148 |
-
var context = options.context || options; // jQuery 1.4+ supports scope context
|
| 149 |
-
for (var i=0, max=callbacks.length; i < max; i++) {
|
| 150 |
-
callbacks[i].apply(context, [data, status, xhr || $form, $form]);
|
| 151 |
-
}
|
| 152 |
-
};
|
| 153 |
-
|
| 154 |
-
// are there files to upload?
|
| 155 |
-
var fileInputs = $('input:file', this).length > 0;
|
| 156 |
-
var mp = 'multipart/form-data';
|
| 157 |
-
var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
|
| 158 |
-
|
| 159 |
-
// options.iframe allows user to force iframe mode
|
| 160 |
-
// 06-NOV-09: now defaulting to iframe mode if file input is detected
|
| 161 |
-
if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
|
| 162 |
-
// hack to fix Safari hang (thanks to Tim Molendijk for this)
|
| 163 |
-
// see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
|
| 164 |
-
if (options.closeKeepAlive) {
|
| 165 |
-
$.get(options.closeKeepAlive, function() { fileUpload(a); });
|
| 166 |
-
}
|
| 167 |
-
else {
|
| 168 |
-
fileUpload(a);
|
| 169 |
-
}
|
| 170 |
-
}
|
| 171 |
-
else {
|
| 172 |
-
$.ajax(options);
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
-
// fire 'notify' event
|
| 176 |
-
this.trigger('form-submit-notify', [this, options]);
|
| 177 |
-
return this;
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
// private function for handling file uploads (hat tip to YAHOO!)
|
| 181 |
-
function fileUpload(a) {
|
| 182 |
-
var form = $form[0], i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle;
|
| 183 |
-
|
| 184 |
-
if (a) {
|
| 185 |
-
// ensure that every serialized input is still enabled
|
| 186 |
-
for (i=0; i < a.length; i++) {
|
| 187 |
-
$(form[a[i].name]).attr('disabled', false);
|
| 188 |
-
}
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
if ($(':input[name=submit],:input[id=submit]', form).length) {
|
| 192 |
-
// if there is an input with a name or id of 'submit' then we won't be
|
| 193 |
-
// able to invoke the submit fn on the form (at least not x-browser)
|
| 194 |
-
alert('Error: Form elements must not have name or id of "submit".');
|
| 195 |
-
return;
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
s = $.extend(true, {}, $.ajaxSettings, options);
|
| 199 |
-
s.context = s.context || s;
|
| 200 |
-
id = 'jqFormIO' + (new Date().getTime());
|
| 201 |
-
if (s.iframeTarget) {
|
| 202 |
-
$io = $(s.iframeTarget);
|
| 203 |
-
n = $io.attr('name');
|
| 204 |
-
if (n == null)
|
| 205 |
-
$io.attr('name', id);
|
| 206 |
-
else
|
| 207 |
-
id = n;
|
| 208 |
-
}
|
| 209 |
-
else {
|
| 210 |
-
$io = $('<iframe name="' + id + '" src="'+ s.iframeSrc +'" />');
|
| 211 |
-
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
|
| 212 |
-
}
|
| 213 |
-
io = $io[0];
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
xhr = { // mock object
|
| 217 |
-
aborted: 0,
|
| 218 |
-
responseText: null,
|
| 219 |
-
responseXML: null,
|
| 220 |
-
status: 0,
|
| 221 |
-
statusText: 'n/a',
|
| 222 |
-
getAllResponseHeaders: function() {},
|
| 223 |
-
getResponseHeader: function() {},
|
| 224 |
-
setRequestHeader: function() {},
|
| 225 |
-
abort: function(status) {
|
| 226 |
-
var e = (status === 'timeout' ? 'timeout' : 'aborted');
|
| 227 |
-
log('aborting upload... ' + e);
|
| 228 |
-
this.aborted = 1;
|
| 229 |
-
$io.attr('src', s.iframeSrc); // abort op in progress
|
| 230 |
-
xhr.error = e;
|
| 231 |
-
s.error && s.error.call(s.context, xhr, e, e);
|
| 232 |
-
g && $.event.trigger("ajaxError", [xhr, s, e]);
|
| 233 |
-
s.complete && s.complete.call(s.context, xhr, e);
|
| 234 |
-
}
|
| 235 |
-
};
|
| 236 |
-
|
| 237 |
-
g = s.global;
|
| 238 |
-
// trigger ajax global events so that activity/block indicators work like normal
|
| 239 |
-
if (g && ! $.active++) {
|
| 240 |
-
$.event.trigger("ajaxStart");
|
| 241 |
-
}
|
| 242 |
-
if (g) {
|
| 243 |
-
$.event.trigger("ajaxSend", [xhr, s]);
|
| 244 |
-
}
|
| 245 |
-
|
| 246 |
-
if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
|
| 247 |
-
if (s.global) {
|
| 248 |
-
$.active--;
|
| 249 |
-
}
|
| 250 |
-
return;
|
| 251 |
-
}
|
| 252 |
-
if (xhr.aborted) {
|
| 253 |
-
return;
|
| 254 |
-
}
|
| 255 |
-
|
| 256 |
-
// add submitting element to data if we know it
|
| 257 |
-
sub = form.clk;
|
| 258 |
-
if (sub) {
|
| 259 |
-
n = sub.name;
|
| 260 |
-
if (n && !sub.disabled) {
|
| 261 |
-
s.extraData = s.extraData || {};
|
| 262 |
-
s.extraData[n] = sub.value;
|
| 263 |
-
if (sub.type == "image") {
|
| 264 |
-
s.extraData[n+'.x'] = form.clk_x;
|
| 265 |
-
s.extraData[n+'.y'] = form.clk_y;
|
| 266 |
-
}
|
| 267 |
-
}
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
// take a breath so that pending repaints get some cpu time before the upload starts
|
| 271 |
-
function doSubmit() {
|
| 272 |
-
// make sure form attrs are set
|
| 273 |
-
var t = $form.attr('target'), a = $form.attr('action');
|
| 274 |
-
|
| 275 |
-
// update form attrs in IE friendly way
|
| 276 |
-
form.setAttribute('target',id);
|
| 277 |
-
if (form.getAttribute('method') != 'POST') {
|
| 278 |
-
form.setAttribute('method', 'POST');
|
| 279 |
-
}
|
| 280 |
-
if (form.getAttribute('action') != s.url) {
|
| 281 |
-
form.setAttribute('action', s.url);
|
| 282 |
-
}
|
| 283 |
-
|
| 284 |
-
// ie borks in some cases when setting encoding
|
| 285 |
-
if (! s.skipEncodingOverride) {
|
| 286 |
-
$form.attr({
|
| 287 |
-
encoding: 'multipart/form-data',
|
| 288 |
-
enctype: 'multipart/form-data'
|
| 289 |
-
});
|
| 290 |
-
}
|
| 291 |
-
|
| 292 |
-
// support timout
|
| 293 |
-
if (s.timeout) {
|
| 294 |
-
timeoutHandle = setTimeout(function() { timedOut = true; cb(true); }, s.timeout);
|
| 295 |
-
}
|
| 296 |
-
|
| 297 |
-
// add "extra" data to form if provided in options
|
| 298 |
-
var extraInputs = [];
|
| 299 |
-
try {
|
| 300 |
-
if (s.extraData) {
|
| 301 |
-
for (var n in s.extraData) {
|
| 302 |
-
extraInputs.push(
|
| 303 |
-
$('<input type="hidden" name="'+n+'" value="'+s.extraData[n]+'" />')
|
| 304 |
-
.appendTo(form)[0]);
|
| 305 |
-
}
|
| 306 |
-
}
|
| 307 |
-
|
| 308 |
-
if (!s.iframeTarget) {
|
| 309 |
-
// add iframe to doc and submit the form
|
| 310 |
-
$io.appendTo('body');
|
| 311 |
-
io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
|
| 312 |
-
}
|
| 313 |
-
form.submit();
|
| 314 |
-
}
|
| 315 |
-
finally {
|
| 316 |
-
// reset attrs and remove "extra" input elements
|
| 317 |
-
form.setAttribute('action',a);
|
| 318 |
-
if(t) {
|
| 319 |
-
form.setAttribute('target', t);
|
| 320 |
-
} else {
|
| 321 |
-
$form.removeAttr('target');
|
| 322 |
-
}
|
| 323 |
-
$(extraInputs).remove();
|
| 324 |
-
}
|
| 325 |
-
}
|
| 326 |
-
|
| 327 |
-
if (s.forceSync) {
|
| 328 |
-
doSubmit();
|
| 329 |
-
}
|
| 330 |
-
else {
|
| 331 |
-
setTimeout(doSubmit, 10); // this lets dom updates render
|
| 332 |
-
}
|
| 333 |
-
|
| 334 |
-
var data, doc, domCheckCount = 50, callbackProcessed;
|
| 335 |
-
|
| 336 |
-
function cb(e) {
|
| 337 |
-
if (xhr.aborted || callbackProcessed) {
|
| 338 |
-
return;
|
| 339 |
-
}
|
| 340 |
-
if (e === true && xhr) {
|
| 341 |
-
xhr.abort('timeout');
|
| 342 |
-
return;
|
| 343 |
-
}
|
| 344 |
-
|
| 345 |
-
var doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
|
| 346 |
-
if (!doc || doc.location.href == s.iframeSrc) {
|
| 347 |
-
// response not received yet
|
| 348 |
-
if (!timedOut)
|
| 349 |
-
return;
|
| 350 |
-
}
|
| 351 |
-
io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
|
| 352 |
-
|
| 353 |
-
var status = 'success', errMsg;
|
| 354 |
-
try {
|
| 355 |
-
if (timedOut) {
|
| 356 |
-
throw 'timeout';
|
| 357 |
-
}
|
| 358 |
-
|
| 359 |
-
var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
|
| 360 |
-
log('isXml='+isXml);
|
| 361 |
-
if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) {
|
| 362 |
-
if (--domCheckCount) {
|
| 363 |
-
// in some browsers (Opera) the iframe DOM is not always traversable when
|
| 364 |
-
// the onload callback fires, so we loop a bit to accommodate
|
| 365 |
-
log('requeing onLoad callback, DOM not available');
|
| 366 |
-
setTimeout(cb, 250);
|
| 367 |
-
return;
|
| 368 |
-
}
|
| 369 |
-
// let this fall through because server response could be an empty document
|
| 370 |
-
//log('Could not access iframe DOM after mutiple tries.');
|
| 371 |
-
//throw 'DOMException: not available';
|
| 372 |
-
}
|
| 373 |
-
|
| 374 |
-
//log('response detected');
|
| 375 |
-
var docRoot = doc.body ? doc.body : doc.documentElement;
|
| 376 |
-
xhr.responseText = docRoot ? docRoot.innerHTML : null;
|
| 377 |
-
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
|
| 378 |
-
if (isXml)
|
| 379 |
-
s.dataType = 'xml';
|
| 380 |
-
xhr.getResponseHeader = function(header){
|
| 381 |
-
var headers = {'content-type': s.dataType};
|
| 382 |
-
return headers[header];
|
| 383 |
-
};
|
| 384 |
-
// support for XHR 'status' & 'statusText' emulation :
|
| 385 |
-
if (docRoot) {
|
| 386 |
-
xhr.status = Number( docRoot.getAttribute('status') ) || xhr.status;
|
| 387 |
-
xhr.statusText = docRoot.getAttribute('statusText') || xhr.statusText;
|
| 388 |
-
}
|
| 389 |
-
|
| 390 |
-
var dt = s.dataType || '';
|
| 391 |
-
var scr = /(json|script|text)/.test(dt.toLowerCase());
|
| 392 |
-
if (scr || s.textarea) {
|
| 393 |
-
// see if user embedded response in textarea
|
| 394 |
-
var ta = doc.getElementsByTagName('textarea')[0];
|
| 395 |
-
if (ta) {
|
| 396 |
-
xhr.responseText = ta.value;
|
| 397 |
-
// support for XHR 'status' & 'statusText' emulation :
|
| 398 |
-
xhr.status = Number( ta.getAttribute('status') ) || xhr.status;
|
| 399 |
-
xhr.statusText = ta.getAttribute('statusText') || xhr.statusText;
|
| 400 |
-
}
|
| 401 |
-
else if (scr) {
|
| 402 |
-
// account for browsers injecting pre around json response
|
| 403 |
-
var pre = doc.getElementsByTagName('pre')[0];
|
| 404 |
-
var b = doc.getElementsByTagName('body')[0];
|
| 405 |
-
if (pre) {
|
| 406 |
-
xhr.responseText = pre.textContent ? pre.textContent : pre.innerHTML;
|
| 407 |
-
}
|
| 408 |
-
else if (b) {
|
| 409 |
-
xhr.responseText = b.innerHTML;
|
| 410 |
-
}
|
| 411 |
-
}
|
| 412 |
-
}
|
| 413 |
-
else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
|
| 414 |
-
xhr.responseXML = toXml(xhr.responseText);
|
| 415 |
-
}
|
| 416 |
-
|
| 417 |
-
try {
|
| 418 |
-
data = httpData(xhr, s.dataType, s);
|
| 419 |
-
}
|
| 420 |
-
catch (e) {
|
| 421 |
-
status = 'parsererror';
|
| 422 |
-
xhr.error = errMsg = (e || status);
|
| 423 |
-
}
|
| 424 |
-
}
|
| 425 |
-
catch (e) {
|
| 426 |
-
log('error caught',e);
|
| 427 |
-
status = 'error';
|
| 428 |
-
xhr.error = errMsg = (e || status);
|
| 429 |
-
}
|
| 430 |
-
|
| 431 |
-
if (xhr.aborted) {
|
| 432 |
-
log('upload aborted');
|
| 433 |
-
status = null;
|
| 434 |
-
}
|
| 435 |
-
|
| 436 |
-
if (xhr.status) { // we've set xhr.status
|
| 437 |
-
status = (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) ? 'success' : 'error';
|
| 438 |
-
}
|
| 439 |
-
|
| 440 |
-
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
|
| 441 |
-
if (status === 'success') {
|
| 442 |
-
s.success && s.success.call(s.context, data, 'success', xhr);
|
| 443 |
-
g && $.event.trigger("ajaxSuccess", [xhr, s]);
|
| 444 |
-
}
|
| 445 |
-
else if (status) {
|
| 446 |
-
if (errMsg == undefined)
|
| 447 |
-
errMsg = xhr.statusText;
|
| 448 |
-
s.error && s.error.call(s.context, xhr, status, errMsg);
|
| 449 |
-
g && $.event.trigger("ajaxError", [xhr, s, errMsg]);
|
| 450 |
-
}
|
| 451 |
-
|
| 452 |
-
g && $.event.trigger("ajaxComplete", [xhr, s]);
|
| 453 |
-
|
| 454 |
-
if (g && ! --$.active) {
|
| 455 |
-
$.event.trigger("ajaxStop");
|
| 456 |
-
}
|
| 457 |
-
|
| 458 |
-
s.complete && s.complete.call(s.context, xhr, status);
|
| 459 |
-
|
| 460 |
-
callbackProcessed = true;
|
| 461 |
-
if (s.timeout)
|
| 462 |
-
clearTimeout(timeoutHandle);
|
| 463 |
-
|
| 464 |
-
// clean up
|
| 465 |
-
setTimeout(function() {
|
| 466 |
-
if (!s.iframeTarget)
|
| 467 |
-
$io.remove();
|
| 468 |
-
xhr.responseXML = null;
|
| 469 |
-
}, 100);
|
| 470 |
-
}
|
| 471 |
-
|
| 472 |
-
var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
|
| 473 |
-
if (window.ActiveXObject) {
|
| 474 |
-
doc = new ActiveXObject('Microsoft.XMLDOM');
|
| 475 |
-
doc.async = 'false';
|
| 476 |
-
doc.loadXML(s);
|
| 477 |
-
}
|
| 478 |
-
else {
|
| 479 |
-
doc = (new DOMParser()).parseFromString(s, 'text/xml');
|
| 480 |
-
}
|
| 481 |
-
return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
|
| 482 |
-
};
|
| 483 |
-
var parseJSON = $.parseJSON || function(s) {
|
| 484 |
-
return window['eval']('(' + s + ')');
|
| 485 |
-
};
|
| 486 |
-
|
| 487 |
-
var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4
|
| 488 |
-
|
| 489 |
-
var ct = xhr.getResponseHeader('content-type') || '',
|
| 490 |
-
xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
|
| 491 |
-
data = xml ? xhr.responseXML : xhr.responseText;
|
| 492 |
-
|
| 493 |
-
if (xml && data.documentElement.nodeName === 'parsererror') {
|
| 494 |
-
$.error && $.error('parsererror');
|
| 495 |
-
}
|
| 496 |
-
if (s && s.dataFilter) {
|
| 497 |
-
data = s.dataFilter(data, type);
|
| 498 |
-
}
|
| 499 |
-
if (typeof data === 'string') {
|
| 500 |
-
if (type === 'json' || !type && ct.indexOf('json') >= 0) {
|
| 501 |
-
data = parseJSON(data);
|
| 502 |
-
} else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
|
| 503 |
-
$.globalEval(data);
|
| 504 |
-
}
|
| 505 |
-
}
|
| 506 |
-
return data;
|
| 507 |
-
};
|
| 508 |
-
}
|
| 509 |
-
};
|
| 510 |
-
|
| 511 |
-
/**
|
| 512 |
-
* ajaxForm() provides a mechanism for fully automating form submission.
|
| 513 |
-
*
|
| 514 |
-
* The advantages of using this method instead of ajaxSubmit() are:
|
| 515 |
-
*
|
| 516 |
-
* 1: This method will include coordinates for <input type="image" /> elements (if the element
|
| 517 |
-
* is used to submit the form).
|
| 518 |
-
* 2. This method will include the submit element's name/value data (for the element that was
|
| 519 |
-
* used to submit the form).
|
| 520 |
-
* 3. This method binds the submit() method to the form for you.
|
| 521 |
-
*
|
| 522 |
-
* The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
|
| 523 |
-
* passes the options argument along after properly binding events for submit elements and
|
| 524 |
-
* the form itself.
|
| 525 |
-
*/
|
| 526 |
-
$.fn.ajaxForm = function(options) {
|
| 527 |
-
// in jQuery 1.3+ we can fix mistakes with the ready state
|
| 528 |
-
if (this.length === 0) {
|
| 529 |
-
var o = { s: this.selector, c: this.context };
|
| 530 |
-
if (!$.isReady && o.s) {
|
| 531 |
-
log('DOM not ready, queuing ajaxForm');
|
| 532 |
-
$(function() {
|
| 533 |
-
$(o.s,o.c).ajaxForm(options);
|
| 534 |
-
});
|
| 535 |
-
return this;
|
| 536 |
-
}
|
| 537 |
-
// is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
|
| 538 |
-
log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
|
| 539 |
-
return this;
|
| 540 |
-
}
|
| 541 |
-
|
| 542 |
-
return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
|
| 543 |
-
if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
|
| 544 |
-
e.preventDefault();
|
| 545 |
-
$(this).ajaxSubmit(options);
|
| 546 |
-
}
|
| 547 |
-
}).bind('click.form-plugin', function(e) {
|
| 548 |
-
var target = e.target;
|
| 549 |
-
var $el = $(target);
|
| 550 |
-
if (!($el.is(":submit,input:image"))) {
|
| 551 |
-
// is this a child element of the submit el? (ex: a span within a button)
|
| 552 |
-
var t = $el.closest(':submit');
|
| 553 |
-
if (t.length == 0) {
|
| 554 |
-
return;
|
| 555 |
-
}
|
| 556 |
-
target = t[0];
|
| 557 |
-
}
|
| 558 |
-
var form = this;
|
| 559 |
-
form.clk = target;
|
| 560 |
-
if (target.type == 'image') {
|
| 561 |
-
if (e.offsetX != undefined) {
|
| 562 |
-
form.clk_x = e.offsetX;
|
| 563 |
-
form.clk_y = e.offsetY;
|
| 564 |
-
} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
|
| 565 |
-
var offset = $el.offset();
|
| 566 |
-
form.clk_x = e.pageX - offset.left;
|
| 567 |
-
form.clk_y = e.pageY - offset.top;
|
| 568 |
-
} else {
|
| 569 |
-
form.clk_x = e.pageX - target.offsetLeft;
|
| 570 |
-
form.clk_y = e.pageY - target.offsetTop;
|
| 571 |
-
}
|
| 572 |
-
}
|
| 573 |
-
// clear form vars
|
| 574 |
-
setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
|
| 575 |
-
});
|
| 576 |
-
};
|
| 577 |
-
|
| 578 |
-
// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
|
| 579 |
-
$.fn.ajaxFormUnbind = function() {
|
| 580 |
-
return this.unbind('submit.form-plugin click.form-plugin');
|
| 581 |
-
};
|
| 582 |
-
|
| 583 |
-
/**
|
| 584 |
-
* formToArray() gathers form element data into an array of objects that can
|
| 585 |
-
* be passed to any of the following ajax functions: $.get, $.post, or load.
|
| 586 |
-
* Each object in the array has both a 'name' and 'value' property. An example of
|
| 587 |
-
* an array for a simple login form might be:
|
| 588 |
-
*
|
| 589 |
-
* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
|
| 590 |
-
*
|
| 591 |
-
* It is this array that is passed to pre-submit callback functions provided to the
|
| 592 |
-
* ajaxSubmit() and ajaxForm() methods.
|
| 593 |
-
*/
|
| 594 |
-
$.fn.formToArray = function(semantic) {
|
| 595 |
-
var a = [];
|
| 596 |
-
if (this.length === 0) {
|
| 597 |
-
return a;
|
| 598 |
-
}
|
| 599 |
-
|
| 600 |
-
var form = this[0];
|
| 601 |
-
var els = semantic ? form.getElementsByTagName('*') : form.elements;
|
| 602 |
-
if (!els) {
|
| 603 |
-
return a;
|
| 604 |
-
}
|
| 605 |
-
|
| 606 |
-
var i,j,n,v,el,max,jmax;
|
| 607 |
-
for(i=0, max=els.length; i < max; i++) {
|
| 608 |
-
el = els[i];
|
| 609 |
-
n = el.name;
|
| 610 |
-
if (!n) {
|
| 611 |
-
continue;
|
| 612 |
-
}
|
| 613 |
-
|
| 614 |
-
if (semantic && form.clk && el.type == "image") {
|
| 615 |
-
// handle image inputs on the fly when semantic == true
|
| 616 |
-
if(!el.disabled && form.clk == el) {
|
| 617 |
-
a.push({name: n, value: $(el).val()});
|
| 618 |
-
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
| 619 |
-
}
|
| 620 |
-
continue;
|
| 621 |
-
}
|
| 622 |
-
|
| 623 |
-
v = $.fieldValue(el, true);
|
| 624 |
-
if (v && v.constructor == Array) {
|
| 625 |
-
for(j=0, jmax=v.length; j < jmax; j++) {
|
| 626 |
-
a.push({name: n, value: v[j]});
|
| 627 |
-
}
|
| 628 |
-
}
|
| 629 |
-
else if (v !== null && typeof v != 'undefined') {
|
| 630 |
-
a.push({name: n, value: v});
|
| 631 |
-
}
|
| 632 |
-
}
|
| 633 |
-
|
| 634 |
-
if (!semantic && form.clk) {
|
| 635 |
-
// input type=='image' are not found in elements array! handle it here
|
| 636 |
-
var $input = $(form.clk), input = $input[0];
|
| 637 |
-
n = input.name;
|
| 638 |
-
if (n && !input.disabled && input.type == 'image') {
|
| 639 |
-
a.push({name: n, value: $input.val()});
|
| 640 |
-
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
| 641 |
-
}
|
| 642 |
-
}
|
| 643 |
-
return a;
|
| 644 |
-
};
|
| 645 |
-
|
| 646 |
-
/**
|
| 647 |
-
* Serializes form data into a 'submittable' string. This method will return a string
|
| 648 |
-
* in the format: name1=value1&name2=value2
|
| 649 |
-
*/
|
| 650 |
-
$.fn.formSerialize = function(semantic) {
|
| 651 |
-
//hand off to jQuery.param for proper encoding
|
| 652 |
-
return $.param(this.formToArray(semantic));
|
| 653 |
-
};
|
| 654 |
-
|
| 655 |
-
/**
|
| 656 |
-
* Serializes all field elements in the jQuery object into a query string.
|
| 657 |
-
* This method will return a string in the format: name1=value1&name2=value2
|
| 658 |
-
*/
|
| 659 |
-
$.fn.fieldSerialize = function(successful) {
|
| 660 |
-
var a = [];
|
| 661 |
-
this.each(function() {
|
| 662 |
-
var n = this.name;
|
| 663 |
-
if (!n) {
|
| 664 |
-
return;
|
| 665 |
-
}
|
| 666 |
-
var v = $.fieldValue(this, successful);
|
| 667 |
-
if (v && v.constructor == Array) {
|
| 668 |
-
for (var i=0,max=v.length; i < max; i++) {
|
| 669 |
-
a.push({name: n, value: v[i]});
|
| 670 |
-
}
|
| 671 |
-
}
|
| 672 |
-
else if (v !== null && typeof v != 'undefined') {
|
| 673 |
-
a.push({name: this.name, value: v});
|
| 674 |
-
}
|
| 675 |
-
});
|
| 676 |
-
//hand off to jQuery.param for proper encoding
|
| 677 |
-
return $.param(a);
|
| 678 |
-
};
|
| 679 |
-
|
| 680 |
-
/**
|
| 681 |
-
* Returns the value(s) of the element in the matched set. For example, consider the following form:
|
| 682 |
-
*
|
| 683 |
-
* <form><fieldset>
|
| 684 |
-
* <input name="A" type="text" />
|
| 685 |
-
* <input name="A" type="text" />
|
| 686 |
-
* <input name="B" type="checkbox" value="B1" />
|
| 687 |
-
* <input name="B" type="checkbox" value="B2"/>
|
| 688 |
-
* <input name="C" type="radio" value="C1" />
|
| 689 |
-
* <input name="C" type="radio" value="C2" />
|
| 690 |
-
* </fieldset></form>
|
| 691 |
-
*
|
| 692 |
-
* var v = $(':text').fieldValue();
|
| 693 |
-
* // if no values are entered into the text inputs
|
| 694 |
-
* v == ['','']
|
| 695 |
-
* // if values entered into the text inputs are 'foo' and 'bar'
|
| 696 |
-
* v == ['foo','bar']
|
| 697 |
-
*
|
| 698 |
-
* var v = $(':checkbox').fieldValue();
|
| 699 |
-
* // if neither checkbox is checked
|
| 700 |
-
* v === undefined
|
| 701 |
-
* // if both checkboxes are checked
|
| 702 |
-
* v == ['B1', 'B2']
|
| 703 |
-
*
|
| 704 |
-
* var v = $(':radio').fieldValue();
|
| 705 |
-
* // if neither radio is checked
|
| 706 |
-
* v === undefined
|
| 707 |
-
* // if first radio is checked
|
| 708 |
-
* v == ['C1']
|
| 709 |
-
*
|
| 710 |
-
* The successful argument controls whether or not the field element must be 'successful'
|
| 711 |
-
* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
|
| 712 |
-
* The default value of the successful argument is true. If this value is false the value(s)
|
| 713 |
-
* for each element is returned.
|
| 714 |
-
*
|
| 715 |
-
* Note: This method *always* returns an array. If no valid value can be determined the
|
| 716 |
-
* array will be empty, otherwise it will contain one or more values.
|
| 717 |
-
*/
|
| 718 |
-
$.fn.fieldValue = function(successful) {
|
| 719 |
-
for (var val=[], i=0, max=this.length; i < max; i++) {
|
| 720 |
-
var el = this[i];
|
| 721 |
-
var v = $.fieldValue(el, successful);
|
| 722 |
-
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
|
| 723 |
-
continue;
|
| 724 |
-
}
|
| 725 |
-
v.constructor == Array ? $.merge(val, v) : val.push(v);
|
| 726 |
-
}
|
| 727 |
-
return val;
|
| 728 |
-
};
|
| 729 |
-
|
| 730 |
-
/**
|
| 731 |
-
* Returns the value of the field element.
|
| 732 |
-
*/
|
| 733 |
-
$.fieldValue = function(el, successful) {
|
| 734 |
-
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
|
| 735 |
-
if (successful === undefined) {
|
| 736 |
-
successful = true;
|
| 737 |
-
}
|
| 738 |
-
|
| 739 |
-
if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
|
| 740 |
-
(t == 'checkbox' || t == 'radio') && !el.checked ||
|
| 741 |
-
(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
|
| 742 |
-
tag == 'select' && el.selectedIndex == -1)) {
|
| 743 |
-
return null;
|
| 744 |
-
}
|
| 745 |
-
|
| 746 |
-
if (tag == 'select') {
|
| 747 |
-
var index = el.selectedIndex;
|
| 748 |
-
if (index < 0) {
|
| 749 |
-
return null;
|
| 750 |
-
}
|
| 751 |
-
var a = [], ops = el.options;
|
| 752 |
-
var one = (t == 'select-one');
|
| 753 |
-
var max = (one ? index+1 : ops.length);
|
| 754 |
-
for(var i=(one ? index : 0); i < max; i++) {
|
| 755 |
-
var op = ops[i];
|
| 756 |
-
if (op.selected) {
|
| 757 |
-
var v = op.value;
|
| 758 |
-
if (!v) { // extra pain for IE...
|
| 759 |
-
v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
|
| 760 |
-
}
|
| 761 |
-
if (one) {
|
| 762 |
-
return v;
|
| 763 |
-
}
|
| 764 |
-
a.push(v);
|
| 765 |
-
}
|
| 766 |
-
}
|
| 767 |
-
return a;
|
| 768 |
-
}
|
| 769 |
-
return $(el).val();
|
| 770 |
-
};
|
| 771 |
-
|
| 772 |
-
/**
|
| 773 |
-
* Clears the form data. Takes the following actions on the form's input fields:
|
| 774 |
-
* - input text fields will have their 'value' property set to the empty string
|
| 775 |
-
* - select elements will have their 'selectedIndex' property set to -1
|
| 776 |
-
* - checkbox and radio inputs will have their 'checked' property set to false
|
| 777 |
-
* - inputs of type submit, button, reset, and hidden will *not* be effected
|
| 778 |
-
* - button elements will *not* be effected
|
| 779 |
-
*/
|
| 780 |
-
$.fn.clearForm = function() {
|
| 781 |
-
return this.each(function() {
|
| 782 |
-
$('input,select,textarea', this).clearFields();
|
| 783 |
-
});
|
| 784 |
-
};
|
| 785 |
-
|
| 786 |
-
/**
|
| 787 |
-
* Clears the selected form elements.
|
| 788 |
-
*/
|
| 789 |
-
$.fn.clearFields = $.fn.clearInputs = function() {
|
| 790 |
-
return this.each(function() {
|
| 791 |
-
var t = this.type, tag = this.tagName.toLowerCase();
|
| 792 |
-
if (t == 'text' || t == 'password' || tag == 'textarea') {
|
| 793 |
-
this.value = '';
|
| 794 |
-
}
|
| 795 |
-
else if (t == 'checkbox' || t == 'radio') {
|
| 796 |
-
this.checked = false;
|
| 797 |
-
}
|
| 798 |
-
else if (tag == 'select') {
|
| 799 |
-
this.selectedIndex = -1;
|
| 800 |
-
}
|
| 801 |
-
});
|
| 802 |
-
};
|
| 803 |
-
|
| 804 |
-
/**
|
| 805 |
-
* Resets the form data. Causes all form elements to be reset to their original value.
|
| 806 |
-
*/
|
| 807 |
-
$.fn.resetForm = function() {
|
| 808 |
-
return this.each(function() {
|
| 809 |
-
// guard against an input with the name of 'reset'
|
| 810 |
-
// note that IE reports the reset function as an 'object'
|
| 811 |
-
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
|
| 812 |
-
this.reset();
|
| 813 |
-
}
|
| 814 |
-
});
|
| 815 |
-
};
|
| 816 |
-
|
| 817 |
-
/**
|
| 818 |
-
* Enables or disables any matching elements.
|
| 819 |
-
*/
|
| 820 |
-
$.fn.enable = function(b) {
|
| 821 |
-
if (b === undefined) {
|
| 822 |
-
b = true;
|
| 823 |
-
}
|
| 824 |
-
return this.each(function() {
|
| 825 |
-
this.disabled = !b;
|
| 826 |
-
});
|
| 827 |
-
};
|
| 828 |
-
|
| 829 |
-
/**
|
| 830 |
-
* Checks/unchecks any matching checkboxes or radio buttons and
|
| 831 |
-
* selects/deselects and matching option elements.
|
| 832 |
-
*/
|
| 833 |
-
$.fn.selected = function(select) {
|
| 834 |
-
if (select === undefined) {
|
| 835 |
-
select = true;
|
| 836 |
-
}
|
| 837 |
-
return this.each(function() {
|
| 838 |
-
var t = this.type;
|
| 839 |
-
if (t == 'checkbox' || t == 'radio') {
|
| 840 |
-
this.checked = select;
|
| 841 |
-
}
|
| 842 |
-
else if (this.tagName.toLowerCase() == 'option') {
|
| 843 |
-
var $sel = $(this).parent('select');
|
| 844 |
-
if (select && $sel[0] && $sel[0].type == 'select-one') {
|
| 845 |
-
// deselect all other options
|
| 846 |
-
$sel.find('option').selected(false);
|
| 847 |
-
}
|
| 848 |
-
this.selected = select;
|
| 849 |
-
}
|
| 850 |
-
});
|
| 851 |
-
};
|
| 852 |
-
|
| 853 |
-
// helper fn for console logging
|
| 854 |
-
function log() {
|
| 855 |
-
var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
|
| 856 |
-
if (window.console && window.console.log) {
|
| 857 |
-
window.console.log(msg);
|
| 858 |
-
}
|
| 859 |
-
else if (window.opera && window.opera.postError) {
|
| 860 |
-
window.opera.postError(msg);
|
| 861 |
-
}
|
| 862 |
-
};
|
| 863 |
-
|
| 864 |
-
})(jQuery);
|
| 1 |
+
/*!
|
| 2 |
+
* jQuery Form Plugin
|
| 3 |
+
* version: 2.80 (25-MAY-2011)
|
| 4 |
+
* @requires jQuery v1.3.2 or later
|
| 5 |
+
*
|
| 6 |
+
* Examples and documentation at: http://malsup.com/jquery/form/
|
| 7 |
+
* Dual licensed under the MIT and GPL licenses:
|
| 8 |
+
* http://www.opensource.org/licenses/mit-license.php
|
| 9 |
+
* http://www.gnu.org/licenses/gpl.html
|
| 10 |
+
*/
|
| 11 |
+
;(function($) {
|
| 12 |
+
|
| 13 |
+
/*
|
| 14 |
+
Usage Note:
|
| 15 |
+
-----------
|
| 16 |
+
Do not use both ajaxSubmit and ajaxForm on the same form. These
|
| 17 |
+
functions are intended to be exclusive. Use ajaxSubmit if you want
|
| 18 |
+
to bind your own submit handler to the form. For example,
|
| 19 |
+
|
| 20 |
+
$(document).ready(function() {
|
| 21 |
+
$('#myForm').bind('submit', function(e) {
|
| 22 |
+
e.preventDefault(); // <-- important
|
| 23 |
+
$(this).ajaxSubmit({
|
| 24 |
+
target: '#output'
|
| 25 |
+
});
|
| 26 |
+
});
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
Use ajaxForm when you want the plugin to manage all the event binding
|
| 30 |
+
for you. For example,
|
| 31 |
+
|
| 32 |
+
$(document).ready(function() {
|
| 33 |
+
$('#myForm').ajaxForm({
|
| 34 |
+
target: '#output'
|
| 35 |
+
});
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
When using ajaxForm, the ajaxSubmit function will be invoked for you
|
| 39 |
+
at the appropriate time.
|
| 40 |
+
*/
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* ajaxSubmit() provides a mechanism for immediately submitting
|
| 44 |
+
* an HTML form using AJAX.
|
| 45 |
+
*/
|
| 46 |
+
$.fn.ajaxSubmit = function(options) {
|
| 47 |
+
// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
|
| 48 |
+
if (!this.length) {
|
| 49 |
+
log('ajaxSubmit: skipping submit process - no element selected');
|
| 50 |
+
return this;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
if (typeof options == 'function') {
|
| 54 |
+
options = { success: options };
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
var action = this.attr('action');
|
| 58 |
+
var url = (typeof action === 'string') ? $.trim(action) : '';
|
| 59 |
+
url = url || window.location.href || '';
|
| 60 |
+
if (url) {
|
| 61 |
+
// clean url (don't include hash vaue)
|
| 62 |
+
url = (url.match(/^([^#]+)/)||[])[1];
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
options = $.extend(true, {
|
| 66 |
+
url: url,
|
| 67 |
+
success: $.ajaxSettings.success,
|
| 68 |
+
type: this[0].getAttribute('method') || 'GET', // IE7 massage (see issue 57)
|
| 69 |
+
iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
|
| 70 |
+
}, options);
|
| 71 |
+
|
| 72 |
+
// hook for manipulating the form data before it is extracted;
|
| 73 |
+
// convenient for use with rich editors like tinyMCE or FCKEditor
|
| 74 |
+
var veto = {};
|
| 75 |
+
this.trigger('form-pre-serialize', [this, options, veto]);
|
| 76 |
+
if (veto.veto) {
|
| 77 |
+
log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
|
| 78 |
+
return this;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// provide opportunity to alter form data before it is serialized
|
| 82 |
+
if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
|
| 83 |
+
log('ajaxSubmit: submit aborted via beforeSerialize callback');
|
| 84 |
+
return this;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
var n,v,a = this.formToArray(options.semantic);
|
| 88 |
+
if (options.data) {
|
| 89 |
+
options.extraData = options.data;
|
| 90 |
+
for (n in options.data) {
|
| 91 |
+
if(options.data[n] instanceof Array) {
|
| 92 |
+
for (var k in options.data[n]) {
|
| 93 |
+
a.push( { name: n, value: options.data[n][k] } );
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
else {
|
| 97 |
+
v = options.data[n];
|
| 98 |
+
v = $.isFunction(v) ? v() : v; // if value is fn, invoke it
|
| 99 |
+
a.push( { name: n, value: v } );
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// give pre-submit callback an opportunity to abort the submit
|
| 105 |
+
if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
|
| 106 |
+
log('ajaxSubmit: submit aborted via beforeSubmit callback');
|
| 107 |
+
return this;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// fire vetoable 'validate' event
|
| 111 |
+
this.trigger('form-submit-validate', [a, this, options, veto]);
|
| 112 |
+
if (veto.veto) {
|
| 113 |
+
log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
|
| 114 |
+
return this;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
var q = $.param(a);
|
| 118 |
+
|
| 119 |
+
if (options.type.toUpperCase() == 'GET') {
|
| 120 |
+
options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
|
| 121 |
+
options.data = null; // data is null for 'get'
|
| 122 |
+
}
|
| 123 |
+
else {
|
| 124 |
+
options.data = q; // data is the query string for 'post'
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
var $form = this, callbacks = [];
|
| 128 |
+
if (options.resetForm) {
|
| 129 |
+
callbacks.push(function() { $form.resetForm(); });
|
| 130 |
+
}
|
| 131 |
+
if (options.clearForm) {
|
| 132 |
+
callbacks.push(function() { $form.clearForm(); });
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// perform a load on the target only if dataType is not provided
|
| 136 |
+
if (!options.dataType && options.target) {
|
| 137 |
+
var oldSuccess = options.success || function(){};
|
| 138 |
+
callbacks.push(function(data) {
|
| 139 |
+
var fn = options.replaceTarget ? 'replaceWith' : 'html';
|
| 140 |
+
$(options.target)[fn](data).each(oldSuccess, arguments);
|
| 141 |
+
});
|
| 142 |
+
}
|
| 143 |
+
else if (options.success) {
|
| 144 |
+
callbacks.push(options.success);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
|
| 148 |
+
var context = options.context || options; // jQuery 1.4+ supports scope context
|
| 149 |
+
for (var i=0, max=callbacks.length; i < max; i++) {
|
| 150 |
+
callbacks[i].apply(context, [data, status, xhr || $form, $form]);
|
| 151 |
+
}
|
| 152 |
+
};
|
| 153 |
+
|
| 154 |
+
// are there files to upload?
|
| 155 |
+
var fileInputs = $('input:file', this).length > 0;
|
| 156 |
+
var mp = 'multipart/form-data';
|
| 157 |
+
var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
|
| 158 |
+
|
| 159 |
+
// options.iframe allows user to force iframe mode
|
| 160 |
+
// 06-NOV-09: now defaulting to iframe mode if file input is detected
|
| 161 |
+
if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
|
| 162 |
+
// hack to fix Safari hang (thanks to Tim Molendijk for this)
|
| 163 |
+
// see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
|
| 164 |
+
if (options.closeKeepAlive) {
|
| 165 |
+
$.get(options.closeKeepAlive, function() { fileUpload(a); });
|
| 166 |
+
}
|
| 167 |
+
else {
|
| 168 |
+
fileUpload(a);
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
else {
|
| 172 |
+
$.ajax(options);
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
// fire 'notify' event
|
| 176 |
+
this.trigger('form-submit-notify', [this, options]);
|
| 177 |
+
return this;
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
// private function for handling file uploads (hat tip to YAHOO!)
|
| 181 |
+
function fileUpload(a) {
|
| 182 |
+
var form = $form[0], i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle;
|
| 183 |
+
|
| 184 |
+
if (a) {
|
| 185 |
+
// ensure that every serialized input is still enabled
|
| 186 |
+
for (i=0; i < a.length; i++) {
|
| 187 |
+
$(form[a[i].name]).attr('disabled', false);
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
if ($(':input[name=submit],:input[id=submit]', form).length) {
|
| 192 |
+
// if there is an input with a name or id of 'submit' then we won't be
|
| 193 |
+
// able to invoke the submit fn on the form (at least not x-browser)
|
| 194 |
+
alert('Error: Form elements must not have name or id of "submit".');
|
| 195 |
+
return;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
s = $.extend(true, {}, $.ajaxSettings, options);
|
| 199 |
+
s.context = s.context || s;
|
| 200 |
+
id = 'jqFormIO' + (new Date().getTime());
|
| 201 |
+
if (s.iframeTarget) {
|
| 202 |
+
$io = $(s.iframeTarget);
|
| 203 |
+
n = $io.attr('name');
|
| 204 |
+
if (n == null)
|
| 205 |
+
$io.attr('name', id);
|
| 206 |
+
else
|
| 207 |
+
id = n;
|
| 208 |
+
}
|
| 209 |
+
else {
|
| 210 |
+
$io = $('<iframe name="' + id + '" src="'+ s.iframeSrc +'" />');
|
| 211 |
+
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
|
| 212 |
+
}
|
| 213 |
+
io = $io[0];
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
xhr = { // mock object
|
| 217 |
+
aborted: 0,
|
| 218 |
+
responseText: null,
|
| 219 |
+
responseXML: null,
|
| 220 |
+
status: 0,
|
| 221 |
+
statusText: 'n/a',
|
| 222 |
+
getAllResponseHeaders: function() {},
|
| 223 |
+
getResponseHeader: function() {},
|
| 224 |
+
setRequestHeader: function() {},
|
| 225 |
+
abort: function(status) {
|
| 226 |
+
var e = (status === 'timeout' ? 'timeout' : 'aborted');
|
| 227 |
+
log('aborting upload... ' + e);
|
| 228 |
+
this.aborted = 1;
|
| 229 |
+
$io.attr('src', s.iframeSrc); // abort op in progress
|
| 230 |
+
xhr.error = e;
|
| 231 |
+
s.error && s.error.call(s.context, xhr, e, e);
|
| 232 |
+
g && $.event.trigger("ajaxError", [xhr, s, e]);
|
| 233 |
+
s.complete && s.complete.call(s.context, xhr, e);
|
| 234 |
+
}
|
| 235 |
+
};
|
| 236 |
+
|
| 237 |
+
g = s.global;
|
| 238 |
+
// trigger ajax global events so that activity/block indicators work like normal
|
| 239 |
+
if (g && ! $.active++) {
|
| 240 |
+
$.event.trigger("ajaxStart");
|
| 241 |
+
}
|
| 242 |
+
if (g) {
|
| 243 |
+
$.event.trigger("ajaxSend", [xhr, s]);
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
|
| 247 |
+
if (s.global) {
|
| 248 |
+
$.active--;
|
| 249 |
+
}
|
| 250 |
+
return;
|
| 251 |
+
}
|
| 252 |
+
if (xhr.aborted) {
|
| 253 |
+
return;
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
// add submitting element to data if we know it
|
| 257 |
+
sub = form.clk;
|
| 258 |
+
if (sub) {
|
| 259 |
+
n = sub.name;
|
| 260 |
+
if (n && !sub.disabled) {
|
| 261 |
+
s.extraData = s.extraData || {};
|
| 262 |
+
s.extraData[n] = sub.value;
|
| 263 |
+
if (sub.type == "image") {
|
| 264 |
+
s.extraData[n+'.x'] = form.clk_x;
|
| 265 |
+
s.extraData[n+'.y'] = form.clk_y;
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
// take a breath so that pending repaints get some cpu time before the upload starts
|
| 271 |
+
function doSubmit() {
|
| 272 |
+
// make sure form attrs are set
|
| 273 |
+
var t = $form.attr('target'), a = $form.attr('action');
|
| 274 |
+
|
| 275 |
+
// update form attrs in IE friendly way
|
| 276 |
+
form.setAttribute('target',id);
|
| 277 |
+
if (form.getAttribute('method') != 'POST') {
|
| 278 |
+
form.setAttribute('method', 'POST');
|
| 279 |
+
}
|
| 280 |
+
if (form.getAttribute('action') != s.url) {
|
| 281 |
+
form.setAttribute('action', s.url);
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
// ie borks in some cases when setting encoding
|
| 285 |
+
if (! s.skipEncodingOverride) {
|
| 286 |
+
$form.attr({
|
| 287 |
+
encoding: 'multipart/form-data',
|
| 288 |
+
enctype: 'multipart/form-data'
|
| 289 |
+
});
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
// support timout
|
| 293 |
+
if (s.timeout) {
|
| 294 |
+
timeoutHandle = setTimeout(function() { timedOut = true; cb(true); }, s.timeout);
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
// add "extra" data to form if provided in options
|
| 298 |
+
var extraInputs = [];
|
| 299 |
+
try {
|
| 300 |
+
if (s.extraData) {
|
| 301 |
+
for (var n in s.extraData) {
|
| 302 |
+
extraInputs.push(
|
| 303 |
+
$('<input type="hidden" name="'+n+'" value="'+s.extraData[n]+'" />')
|
| 304 |
+
.appendTo(form)[0]);
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
if (!s.iframeTarget) {
|
| 309 |
+
// add iframe to doc and submit the form
|
| 310 |
+
$io.appendTo('body');
|
| 311 |
+
io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
|
| 312 |
+
}
|
| 313 |
+
form.submit();
|
| 314 |
+
}
|
| 315 |
+
finally {
|
| 316 |
+
// reset attrs and remove "extra" input elements
|
| 317 |
+
form.setAttribute('action',a);
|
| 318 |
+
if(t) {
|
| 319 |
+
form.setAttribute('target', t);
|
| 320 |
+
} else {
|
| 321 |
+
$form.removeAttr('target');
|
| 322 |
+
}
|
| 323 |
+
$(extraInputs).remove();
|
| 324 |
+
}
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
if (s.forceSync) {
|
| 328 |
+
doSubmit();
|
| 329 |
+
}
|
| 330 |
+
else {
|
| 331 |
+
setTimeout(doSubmit, 10); // this lets dom updates render
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
var data, doc, domCheckCount = 50, callbackProcessed;
|
| 335 |
+
|
| 336 |
+
function cb(e) {
|
| 337 |
+
if (xhr.aborted || callbackProcessed) {
|
| 338 |
+
return;
|
| 339 |
+
}
|
| 340 |
+
if (e === true && xhr) {
|
| 341 |
+
xhr.abort('timeout');
|
| 342 |
+
return;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
var doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
|
| 346 |
+
if (!doc || doc.location.href == s.iframeSrc) {
|
| 347 |
+
// response not received yet
|
| 348 |
+
if (!timedOut)
|
| 349 |
+
return;
|
| 350 |
+
}
|
| 351 |
+
io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
|
| 352 |
+
|
| 353 |
+
var status = 'success', errMsg;
|
| 354 |
+
try {
|
| 355 |
+
if (timedOut) {
|
| 356 |
+
throw 'timeout';
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
|
| 360 |
+
log('isXml='+isXml);
|
| 361 |
+
if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) {
|
| 362 |
+
if (--domCheckCount) {
|
| 363 |
+
// in some browsers (Opera) the iframe DOM is not always traversable when
|
| 364 |
+
// the onload callback fires, so we loop a bit to accommodate
|
| 365 |
+
log('requeing onLoad callback, DOM not available');
|
| 366 |
+
setTimeout(cb, 250);
|
| 367 |
+
return;
|
| 368 |
+
}
|
| 369 |
+
// let this fall through because server response could be an empty document
|
| 370 |
+
//log('Could not access iframe DOM after mutiple tries.');
|
| 371 |
+
//throw 'DOMException: not available';
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
//log('response detected');
|
| 375 |
+
var docRoot = doc.body ? doc.body : doc.documentElement;
|
| 376 |
+
xhr.responseText = docRoot ? docRoot.innerHTML : null;
|
| 377 |
+
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
|
| 378 |
+
if (isXml)
|
| 379 |
+
s.dataType = 'xml';
|
| 380 |
+
xhr.getResponseHeader = function(header){
|
| 381 |
+
var headers = {'content-type': s.dataType};
|
| 382 |
+
return headers[header];
|
| 383 |
+
};
|
| 384 |
+
// support for XHR 'status' & 'statusText' emulation :
|
| 385 |
+
if (docRoot) {
|
| 386 |
+
xhr.status = Number( docRoot.getAttribute('status') ) || xhr.status;
|
| 387 |
+
xhr.statusText = docRoot.getAttribute('statusText') || xhr.statusText;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
var dt = s.dataType || '';
|
| 391 |
+
var scr = /(json|script|text)/.test(dt.toLowerCase());
|
| 392 |
+
if (scr || s.textarea) {
|
| 393 |
+
// see if user embedded response in textarea
|
| 394 |
+
var ta = doc.getElementsByTagName('textarea')[0];
|
| 395 |
+
if (ta) {
|
| 396 |
+
xhr.responseText = ta.value;
|
| 397 |
+
// support for XHR 'status' & 'statusText' emulation :
|
| 398 |
+
xhr.status = Number( ta.getAttribute('status') ) || xhr.status;
|
| 399 |
+
xhr.statusText = ta.getAttribute('statusText') || xhr.statusText;
|
| 400 |
+
}
|
| 401 |
+
else if (scr) {
|
| 402 |
+
// account for browsers injecting pre around json response
|
| 403 |
+
var pre = doc.getElementsByTagName('pre')[0];
|
| 404 |
+
var b = doc.getElementsByTagName('body')[0];
|
| 405 |
+
if (pre) {
|
| 406 |
+
xhr.responseText = pre.textContent ? pre.textContent : pre.innerHTML;
|
| 407 |
+
}
|
| 408 |
+
else if (b) {
|
| 409 |
+
xhr.responseText = b.innerHTML;
|
| 410 |
+
}
|
| 411 |
+
}
|
| 412 |
+
}
|
| 413 |
+
else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
|
| 414 |
+
xhr.responseXML = toXml(xhr.responseText);
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
try {
|
| 418 |
+
data = httpData(xhr, s.dataType, s);
|
| 419 |
+
}
|
| 420 |
+
catch (e) {
|
| 421 |
+
status = 'parsererror';
|
| 422 |
+
xhr.error = errMsg = (e || status);
|
| 423 |
+
}
|
| 424 |
+
}
|
| 425 |
+
catch (e) {
|
| 426 |
+
log('error caught',e);
|
| 427 |
+
status = 'error';
|
| 428 |
+
xhr.error = errMsg = (e || status);
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
if (xhr.aborted) {
|
| 432 |
+
log('upload aborted');
|
| 433 |
+
status = null;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
if (xhr.status) { // we've set xhr.status
|
| 437 |
+
status = (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) ? 'success' : 'error';
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
|
| 441 |
+
if (status === 'success') {
|
| 442 |
+
s.success && s.success.call(s.context, data, 'success', xhr);
|
| 443 |
+
g && $.event.trigger("ajaxSuccess", [xhr, s]);
|
| 444 |
+
}
|
| 445 |
+
else if (status) {
|
| 446 |
+
if (errMsg == undefined)
|
| 447 |
+
errMsg = xhr.statusText;
|
| 448 |
+
s.error && s.error.call(s.context, xhr, status, errMsg);
|
| 449 |
+
g && $.event.trigger("ajaxError", [xhr, s, errMsg]);
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
g && $.event.trigger("ajaxComplete", [xhr, s]);
|
| 453 |
+
|
| 454 |
+
if (g && ! --$.active) {
|
| 455 |
+
$.event.trigger("ajaxStop");
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
s.complete && s.complete.call(s.context, xhr, status);
|
| 459 |
+
|
| 460 |
+
callbackProcessed = true;
|
| 461 |
+
if (s.timeout)
|
| 462 |
+
clearTimeout(timeoutHandle);
|
| 463 |
+
|
| 464 |
+
// clean up
|
| 465 |
+
setTimeout(function() {
|
| 466 |
+
if (!s.iframeTarget)
|
| 467 |
+
$io.remove();
|
| 468 |
+
xhr.responseXML = null;
|
| 469 |
+
}, 100);
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
|
| 473 |
+
if (window.ActiveXObject) {
|
| 474 |
+
doc = new ActiveXObject('Microsoft.XMLDOM');
|
| 475 |
+
doc.async = 'false';
|
| 476 |
+
doc.loadXML(s);
|
| 477 |
+
}
|
| 478 |
+
else {
|
| 479 |
+
doc = (new DOMParser()).parseFromString(s, 'text/xml');
|
| 480 |
+
}
|
| 481 |
+
return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
|
| 482 |
+
};
|
| 483 |
+
var parseJSON = $.parseJSON || function(s) {
|
| 484 |
+
return window['eval']('(' + s + ')');
|
| 485 |
+
};
|
| 486 |
+
|
| 487 |
+
var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4
|
| 488 |
+
|
| 489 |
+
var ct = xhr.getResponseHeader('content-type') || '',
|
| 490 |
+
xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
|
| 491 |
+
data = xml ? xhr.responseXML : xhr.responseText;
|
| 492 |
+
|
| 493 |
+
if (xml && data.documentElement.nodeName === 'parsererror') {
|
| 494 |
+
$.error && $.error('parsererror');
|
| 495 |
+
}
|
| 496 |
+
if (s && s.dataFilter) {
|
| 497 |
+
data = s.dataFilter(data, type);
|
| 498 |
+
}
|
| 499 |
+
if (typeof data === 'string') {
|
| 500 |
+
if (type === 'json' || !type && ct.indexOf('json') >= 0) {
|
| 501 |
+
data = parseJSON(data);
|
| 502 |
+
} else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
|
| 503 |
+
$.globalEval(data);
|
| 504 |
+
}
|
| 505 |
+
}
|
| 506 |
+
return data;
|
| 507 |
+
};
|
| 508 |
+
}
|
| 509 |
+
};
|
| 510 |
+
|
| 511 |
+
/**
|
| 512 |
+
* ajaxForm() provides a mechanism for fully automating form submission.
|
| 513 |
+
*
|
| 514 |
+
* The advantages of using this method instead of ajaxSubmit() are:
|
| 515 |
+
*
|
| 516 |
+
* 1: This method will include coordinates for <input type="image" /> elements (if the element
|
| 517 |
+
* is used to submit the form).
|
| 518 |
+
* 2. This method will include the submit element's name/value data (for the element that was
|
| 519 |
+
* used to submit the form).
|
| 520 |
+
* 3. This method binds the submit() method to the form for you.
|
| 521 |
+
*
|
| 522 |
+
* The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
|
| 523 |
+
* passes the options argument along after properly binding events for submit elements and
|
| 524 |
+
* the form itself.
|
| 525 |
+
*/
|
| 526 |
+
$.fn.ajaxForm = function(options) {
|
| 527 |
+
// in jQuery 1.3+ we can fix mistakes with the ready state
|
| 528 |
+
if (this.length === 0) {
|
| 529 |
+
var o = { s: this.selector, c: this.context };
|
| 530 |
+
if (!$.isReady && o.s) {
|
| 531 |
+
log('DOM not ready, queuing ajaxForm');
|
| 532 |
+
$(function() {
|
| 533 |
+
$(o.s,o.c).ajaxForm(options);
|
| 534 |
+
});
|
| 535 |
+
return this;
|
| 536 |
+
}
|
| 537 |
+
// is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
|
| 538 |
+
log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
|
| 539 |
+
return this;
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
|
| 543 |
+
if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
|
| 544 |
+
e.preventDefault();
|
| 545 |
+
$(this).ajaxSubmit(options);
|
| 546 |
+
}
|
| 547 |
+
}).bind('click.form-plugin', function(e) {
|
| 548 |
+
var target = e.target;
|
| 549 |
+
var $el = $(target);
|
| 550 |
+
if (!($el.is(":submit,input:image"))) {
|
| 551 |
+
// is this a child element of the submit el? (ex: a span within a button)
|
| 552 |
+
var t = $el.closest(':submit');
|
| 553 |
+
if (t.length == 0) {
|
| 554 |
+
return;
|
| 555 |
+
}
|
| 556 |
+
target = t[0];
|
| 557 |
+
}
|
| 558 |
+
var form = this;
|
| 559 |
+
form.clk = target;
|
| 560 |
+
if (target.type == 'image') {
|
| 561 |
+
if (e.offsetX != undefined) {
|
| 562 |
+
form.clk_x = e.offsetX;
|
| 563 |
+
form.clk_y = e.offsetY;
|
| 564 |
+
} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
|
| 565 |
+
var offset = $el.offset();
|
| 566 |
+
form.clk_x = e.pageX - offset.left;
|
| 567 |
+
form.clk_y = e.pageY - offset.top;
|
| 568 |
+
} else {
|
| 569 |
+
form.clk_x = e.pageX - target.offsetLeft;
|
| 570 |
+
form.clk_y = e.pageY - target.offsetTop;
|
| 571 |
+
}
|
| 572 |
+
}
|
| 573 |
+
// clear form vars
|
| 574 |
+
setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
|
| 575 |
+
});
|
| 576 |
+
};
|
| 577 |
+
|
| 578 |
+
// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
|
| 579 |
+
$.fn.ajaxFormUnbind = function() {
|
| 580 |
+
return this.unbind('submit.form-plugin click.form-plugin');
|
| 581 |
+
};
|
| 582 |
+
|
| 583 |
+
/**
|
| 584 |
+
* formToArray() gathers form element data into an array of objects that can
|
| 585 |
+
* be passed to any of the following ajax functions: $.get, $.post, or load.
|
| 586 |
+
* Each object in the array has both a 'name' and 'value' property. An example of
|
| 587 |
+
* an array for a simple login form might be:
|
| 588 |
+
*
|
| 589 |
+
* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
|
| 590 |
+
*
|
| 591 |
+
* It is this array that is passed to pre-submit callback functions provided to the
|
| 592 |
+
* ajaxSubmit() and ajaxForm() methods.
|
| 593 |
+
*/
|
| 594 |
+
$.fn.formToArray = function(semantic) {
|
| 595 |
+
var a = [];
|
| 596 |
+
if (this.length === 0) {
|
| 597 |
+
return a;
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
var form = this[0];
|
| 601 |
+
var els = semantic ? form.getElementsByTagName('*') : form.elements;
|
| 602 |
+
if (!els) {
|
| 603 |
+
return a;
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
var i,j,n,v,el,max,jmax;
|
| 607 |
+
for(i=0, max=els.length; i < max; i++) {
|
| 608 |
+
el = els[i];
|
| 609 |
+
n = el.name;
|
| 610 |
+
if (!n) {
|
| 611 |
+
continue;
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
if (semantic && form.clk && el.type == "image") {
|
| 615 |
+
// handle image inputs on the fly when semantic == true
|
| 616 |
+
if(!el.disabled && form.clk == el) {
|
| 617 |
+
a.push({name: n, value: $(el).val()});
|
| 618 |
+
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
| 619 |
+
}
|
| 620 |
+
continue;
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
v = $.fieldValue(el, true);
|
| 624 |
+
if (v && v.constructor == Array) {
|
| 625 |
+
for(j=0, jmax=v.length; j < jmax; j++) {
|
| 626 |
+
a.push({name: n, value: v[j]});
|
| 627 |
+
}
|
| 628 |
+
}
|
| 629 |
+
else if (v !== null && typeof v != 'undefined') {
|
| 630 |
+
a.push({name: n, value: v});
|
| 631 |
+
}
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
if (!semantic && form.clk) {
|
| 635 |
+
// input type=='image' are not found in elements array! handle it here
|
| 636 |
+
var $input = $(form.clk), input = $input[0];
|
| 637 |
+
n = input.name;
|
| 638 |
+
if (n && !input.disabled && input.type == 'image') {
|
| 639 |
+
a.push({name: n, value: $input.val()});
|
| 640 |
+
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
| 641 |
+
}
|
| 642 |
+
}
|
| 643 |
+
return a;
|
| 644 |
+
};
|
| 645 |
+
|
| 646 |
+
/**
|
| 647 |
+
* Serializes form data into a 'submittable' string. This method will return a string
|
| 648 |
+
* in the format: name1=value1&name2=value2
|
| 649 |
+
*/
|
| 650 |
+
$.fn.formSerialize = function(semantic) {
|
| 651 |
+
//hand off to jQuery.param for proper encoding
|
| 652 |
+
return $.param(this.formToArray(semantic));
|
| 653 |
+
};
|
| 654 |
+
|
| 655 |
+
/**
|
| 656 |
+
* Serializes all field elements in the jQuery object into a query string.
|
| 657 |
+
* This method will return a string in the format: name1=value1&name2=value2
|
| 658 |
+
*/
|
| 659 |
+
$.fn.fieldSerialize = function(successful) {
|
| 660 |
+
var a = [];
|
| 661 |
+
this.each(function() {
|
| 662 |
+
var n = this.name;
|
| 663 |
+
if (!n) {
|
| 664 |
+
return;
|
| 665 |
+
}
|
| 666 |
+
var v = $.fieldValue(this, successful);
|
| 667 |
+
if (v && v.constructor == Array) {
|
| 668 |
+
for (var i=0,max=v.length; i < max; i++) {
|
| 669 |
+
a.push({name: n, value: v[i]});
|
| 670 |
+
}
|
| 671 |
+
}
|
| 672 |
+
else if (v !== null && typeof v != 'undefined') {
|
| 673 |
+
a.push({name: this.name, value: v});
|
| 674 |
+
}
|
| 675 |
+
});
|
| 676 |
+
//hand off to jQuery.param for proper encoding
|
| 677 |
+
return $.param(a);
|
| 678 |
+
};
|
| 679 |
+
|
| 680 |
+
/**
|
| 681 |
+
* Returns the value(s) of the element in the matched set. For example, consider the following form:
|
| 682 |
+
*
|
| 683 |
+
* <form><fieldset>
|
| 684 |
+
* <input name="A" type="text" />
|
| 685 |
+
* <input name="A" type="text" />
|
| 686 |
+
* <input name="B" type="checkbox" value="B1" />
|
| 687 |
+
* <input name="B" type="checkbox" value="B2"/>
|
| 688 |
+
* <input name="C" type="radio" value="C1" />
|
| 689 |
+
* <input name="C" type="radio" value="C2" />
|
| 690 |
+
* </fieldset></form>
|
| 691 |
+
*
|
| 692 |
+
* var v = $(':text').fieldValue();
|
| 693 |
+
* // if no values are entered into the text inputs
|
| 694 |
+
* v == ['','']
|
| 695 |
+
* // if values entered into the text inputs are 'foo' and 'bar'
|
| 696 |
+
* v == ['foo','bar']
|
| 697 |
+
*
|
| 698 |
+
* var v = $(':checkbox').fieldValue();
|
| 699 |
+
* // if neither checkbox is checked
|
| 700 |
+
* v === undefined
|
| 701 |
+
* // if both checkboxes are checked
|
| 702 |
+
* v == ['B1', 'B2']
|
| 703 |
+
*
|
| 704 |
+
* var v = $(':radio').fieldValue();
|
| 705 |
+
* // if neither radio is checked
|
| 706 |
+
* v === undefined
|
| 707 |
+
* // if first radio is checked
|
| 708 |
+
* v == ['C1']
|
| 709 |
+
*
|
| 710 |
+
* The successful argument controls whether or not the field element must be 'successful'
|
| 711 |
+
* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
|
| 712 |
+
* The default value of the successful argument is true. If this value is false the value(s)
|
| 713 |
+
* for each element is returned.
|
| 714 |
+
*
|
| 715 |
+
* Note: This method *always* returns an array. If no valid value can be determined the
|
| 716 |
+
* array will be empty, otherwise it will contain one or more values.
|
| 717 |
+
*/
|
| 718 |
+
$.fn.fieldValue = function(successful) {
|
| 719 |
+
for (var val=[], i=0, max=this.length; i < max; i++) {
|
| 720 |
+
var el = this[i];
|
| 721 |
+
var v = $.fieldValue(el, successful);
|
| 722 |
+
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
|
| 723 |
+
continue;
|
| 724 |
+
}
|
| 725 |
+
v.constructor == Array ? $.merge(val, v) : val.push(v);
|
| 726 |
+
}
|
| 727 |
+
return val;
|
| 728 |
+
};
|
| 729 |
+
|
| 730 |
+
/**
|
| 731 |
+
* Returns the value of the field element.
|
| 732 |
+
*/
|
| 733 |
+
$.fieldValue = function(el, successful) {
|
| 734 |
+
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
|
| 735 |
+
if (successful === undefined) {
|
| 736 |
+
successful = true;
|
| 737 |
+
}
|
| 738 |
+
|
| 739 |
+
if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
|
| 740 |
+
(t == 'checkbox' || t == 'radio') && !el.checked ||
|
| 741 |
+
(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
|
| 742 |
+
tag == 'select' && el.selectedIndex == -1)) {
|
| 743 |
+
return null;
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
if (tag == 'select') {
|
| 747 |
+
var index = el.selectedIndex;
|
| 748 |
+
if (index < 0) {
|
| 749 |
+
return null;
|
| 750 |
+
}
|
| 751 |
+
var a = [], ops = el.options;
|
| 752 |
+
var one = (t == 'select-one');
|
| 753 |
+
var max = (one ? index+1 : ops.length);
|
| 754 |
+
for(var i=(one ? index : 0); i < max; i++) {
|
| 755 |
+
var op = ops[i];
|
| 756 |
+
if (op.selected) {
|
| 757 |
+
var v = op.value;
|
| 758 |
+
if (!v) { // extra pain for IE...
|
| 759 |
+
v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
|
| 760 |
+
}
|
| 761 |
+
if (one) {
|
| 762 |
+
return v;
|
| 763 |
+
}
|
| 764 |
+
a.push(v);
|
| 765 |
+
}
|
| 766 |
+
}
|
| 767 |
+
return a;
|
| 768 |
+
}
|
| 769 |
+
return $(el).val();
|
| 770 |
+
};
|
| 771 |
+
|
| 772 |
+
/**
|
| 773 |
+
* Clears the form data. Takes the following actions on the form's input fields:
|
| 774 |
+
* - input text fields will have their 'value' property set to the empty string
|
| 775 |
+
* - select elements will have their 'selectedIndex' property set to -1
|
| 776 |
+
* - checkbox and radio inputs will have their 'checked' property set to false
|
| 777 |
+
* - inputs of type submit, button, reset, and hidden will *not* be effected
|
| 778 |
+
* - button elements will *not* be effected
|
| 779 |
+
*/
|
| 780 |
+
$.fn.clearForm = function() {
|
| 781 |
+
return this.each(function() {
|
| 782 |
+
$('input,select,textarea', this).clearFields();
|
| 783 |
+
});
|
| 784 |
+
};
|
| 785 |
+
|
| 786 |
+
/**
|
| 787 |
+
* Clears the selected form elements.
|
| 788 |
+
*/
|
| 789 |
+
$.fn.clearFields = $.fn.clearInputs = function() {
|
| 790 |
+
return this.each(function() {
|
| 791 |
+
var t = this.type, tag = this.tagName.toLowerCase();
|
| 792 |
+
if (t == 'text' || t == 'password' || tag == 'textarea') {
|
| 793 |
+
this.value = '';
|
| 794 |
+
}
|
| 795 |
+
else if (t == 'checkbox' || t == 'radio') {
|
| 796 |
+
this.checked = false;
|
| 797 |
+
}
|
| 798 |
+
else if (tag == 'select') {
|
| 799 |
+
this.selectedIndex = -1;
|
| 800 |
+
}
|
| 801 |
+
});
|
| 802 |
+
};
|
| 803 |
+
|
| 804 |
+
/**
|
| 805 |
+
* Resets the form data. Causes all form elements to be reset to their original value.
|
| 806 |
+
*/
|
| 807 |
+
$.fn.resetForm = function() {
|
| 808 |
+
return this.each(function() {
|
| 809 |
+
// guard against an input with the name of 'reset'
|
| 810 |
+
// note that IE reports the reset function as an 'object'
|
| 811 |
+
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
|
| 812 |
+
this.reset();
|
| 813 |
+
}
|
| 814 |
+
});
|
| 815 |
+
};
|
| 816 |
+
|
| 817 |
+
/**
|
| 818 |
+
* Enables or disables any matching elements.
|
| 819 |
+
*/
|
| 820 |
+
$.fn.enable = function(b) {
|
| 821 |
+
if (b === undefined) {
|
| 822 |
+
b = true;
|
| 823 |
+
}
|
| 824 |
+
return this.each(function() {
|
| 825 |
+
this.disabled = !b;
|
| 826 |
+
});
|
| 827 |
+
};
|
| 828 |
+
|
| 829 |
+
/**
|
| 830 |
+
* Checks/unchecks any matching checkboxes or radio buttons and
|
| 831 |
+
* selects/deselects and matching option elements.
|
| 832 |
+
*/
|
| 833 |
+
$.fn.selected = function(select) {
|
| 834 |
+
if (select === undefined) {
|
| 835 |
+
select = true;
|
| 836 |
+
}
|
| 837 |
+
return this.each(function() {
|
| 838 |
+
var t = this.type;
|
| 839 |
+
if (t == 'checkbox' || t == 'radio') {
|
| 840 |
+
this.checked = select;
|
| 841 |
+
}
|
| 842 |
+
else if (this.tagName.toLowerCase() == 'option') {
|
| 843 |
+
var $sel = $(this).parent('select');
|
| 844 |
+
if (select && $sel[0] && $sel[0].type == 'select-one') {
|
| 845 |
+
// deselect all other options
|
| 846 |
+
$sel.find('option').selected(false);
|
| 847 |
+
}
|
| 848 |
+
this.selected = select;
|
| 849 |
+
}
|
| 850 |
+
});
|
| 851 |
+
};
|
| 852 |
+
|
| 853 |
+
// helper fn for console logging
|
| 854 |
+
function log() {
|
| 855 |
+
var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
|
| 856 |
+
if (window.console && window.console.log) {
|
| 857 |
+
window.console.log(msg);
|
| 858 |
+
}
|
| 859 |
+
else if (window.opera && window.opera.postError) {
|
| 860 |
+
window.opera.postError(msg);
|
| 861 |
+
}
|
| 862 |
+
};
|
| 863 |
+
|
| 864 |
+
})(jQuery);
|
readme.txt
CHANGED
|
@@ -4,7 +4,7 @@ Donate link: http://www.taylorlovett.com
|
|
| 4 |
Tags: contact form, web form, custom contact form, custom forms, captcha form, contact fields, form mailers
|
| 5 |
Requires at least: 2.8.1
|
| 6 |
Tested up to: 3.4.1
|
| 7 |
-
Stable tag: 5.1.0.
|
| 8 |
|
| 9 |
A customizable and intuitive contact form plugin for Wordpress.
|
| 10 |
|
|
@@ -144,6 +144,9 @@ Visit http://www.taylorlovett.com/wordpress-plugins for screenshots. Right now a
|
|
| 144 |
|
| 145 |
== Changelog ==
|
| 146 |
|
|
|
|
|
|
|
|
|
|
| 147 |
= 5.1.0.3 =
|
| 148 |
* custom-contact-forms-front.php - $field_value properly escaped
|
| 149 |
|
| 4 |
Tags: contact form, web form, custom contact form, custom forms, captcha form, contact fields, form mailers
|
| 5 |
Requires at least: 2.8.1
|
| 6 |
Tested up to: 3.4.1
|
| 7 |
+
Stable tag: 5.1.0.4
|
| 8 |
|
| 9 |
A customizable and intuitive contact form plugin for Wordpress.
|
| 10 |
|
| 144 |
|
| 145 |
== Changelog ==
|
| 146 |
|
| 147 |
+
= 5.1.0.4 =
|
| 148 |
+
Security fix
|
| 149 |
+
|
| 150 |
= 5.1.0.3 =
|
| 151 |
* custom-contact-forms-front.php - $field_value properly escaped
|
| 152 |
|
