From e75054174c944d8a78a2c2822abe2fe161f7d6ad Mon Sep 17 00:00:00 2001 From: MatmaRex Date: Sat, 1 Sep 2012 16:20:16 +0200 Subject: [PATCH] LivePreview: properly use jquery.form (as dependency) ... instead of just using two outdated functions copied from there god knows when. Change-Id: Ifcc7e7c51cf20b3b93e4b16bd9ba55dfe45b445c --- resources/Resources.php | 5 ++- skins/common/preview.js | 72 +---------------------------------------- 2 files changed, 5 insertions(+), 72 deletions(-) diff --git a/resources/Resources.php b/resources/Resources.php index 82ab718b1b..23f74b1305 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -923,7 +923,10 @@ return array( 'scripts' => 'common/preview.js', 'remoteBasePath' => $GLOBALS['wgStylePath'], 'localBasePath' => $GLOBALS['wgStyleDirectory'], - 'dependencies' => 'mediawiki.legacy.wikibits', + 'dependencies' => array( + 'mediawiki.legacy.wikibits', + 'jquery.form', + ) ), 'mediawiki.legacy.protect' => array( 'scripts' => 'common/protect.js', diff --git a/skins/common/preview.js b/skins/common/preview.js index 0053b5ee4d..e0a3c0059f 100644 --- a/skins/common/preview.js +++ b/skins/common/preview.js @@ -24,7 +24,7 @@ // Jump to where the preview will appear $wikiPreview[0].scrollIntoView(); - var postData = $('#editform').formToArray(); + var postData = $('#editform').formToArray(); // formToArray: from jquery.form postData.push( { 'name' : e.target.name, 'value' : '1' } ); // Hide active diff, used templates, old preview if shown @@ -85,76 +85,6 @@ } ); }; - // Shamelessly stolen from the jQuery form plugin, which is licensed under the GPL. - // http://jquery.malsup.com/form/#download - $.fn.formToArray = function() { - var a = []; - if (this.length == 0) return a; - - var form = this[0]; - var els = form.elements; - if (!els) return a; - for(var i=0, max=els.length; i < max; i++) { - var el = els[i]; - var n = el.name; - if (!n) continue; - - var v = $.fieldValue(el, true); - if (v && v.constructor == Array) { - for(var j=0, jmax=v.length; j < jmax; j++) - a.push({name: n, value: v[j]}); - } - else if (v !== null && typeof v != 'undefined') - a.push({name: n, value: v}); - } - - if (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; - }; - - /** - * Returns the value of the field element. - */ - $.fieldValue = function(el, successful) { - var n = el.name, t = el.type, tag = el.tagName.toLowerCase(); - if (typeof 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.value; - }; - $(document).ready( function() { // construct space for interwiki links if missing // (it is usually not shown when action=edit, but shown if action=submit) -- 2.20.1