X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Flib%2Foojs-ui%2Foojs-ui.js;h=b4dc48c8e7184a0781d52d9f6a8909d5af996479;hb=ce9c1264b42eef9e89d1fdef11208b7fb2699b64;hp=aeff69e0fad2aea76380d9896c004a6b9812c080;hpb=568284cf57d38fa9d515aabd28731bd0509df9a8;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/lib/oojs-ui/oojs-ui.js b/resources/lib/oojs-ui/oojs-ui.js index aeff69e0fa..b4dc48c8e7 100644 --- a/resources/lib/oojs-ui/oojs-ui.js +++ b/resources/lib/oojs-ui/oojs-ui.js @@ -1,12 +1,12 @@ /*! - * OOjs UI v0.12.12 + * OOjs UI v0.13.1 * https://www.mediawiki.org/wiki/OOjs_UI * * Copyright 2011–2015 OOjs UI Team and other contributors. * Released under the MIT license * http://oojs.mit-license.org * - * Date: 2015-10-13T20:38:18Z + * Date: 2015-11-03T21:42:20Z */ ( function ( OO ) { @@ -1289,17 +1289,25 @@ OO.ui.Element.static.unsafeInfuse = function ( idOrNode, domPromise ) { } } } ); - // jscs:disable requireCapitalizedConstructors - obj = new cls( data ); // rebuild widget + // allow widgets to reuse parts of the DOM + data = cls.static.reusePreInfuseDOM( $elem[ 0 ], data ); // pick up dynamic state, like focus, value of form inputs, scroll position, etc. - state = obj.gatherPreInfuseState( $elem ); + state = cls.static.gatherPreInfuseState( $elem[ 0 ], data ); + // rebuild widget + // jscs:disable requireCapitalizedConstructors + obj = new cls( data ); + // jscs:enable requireCapitalizedConstructors // now replace old DOM with this new DOM. if ( top ) { - $elem.replaceWith( obj.$element ); - // This element is now gone from the DOM, but if anyone is holding a reference to it, - // let's allow them to OO.ui.infuse() it and do what they expect (T105828). - // Do not use jQuery.data(), as using it on detached nodes leaks memory in 1.x line by design. - $elem[ 0 ].oouiInfused = obj; + // An efficient constructor might be able to reuse the entire DOM tree of the original element, + // so only mutate the DOM if we need to. + if ( $elem[ 0 ] !== obj.$element[ 0 ] ) { + $elem.replaceWith( obj.$element ); + // This element is now gone from the DOM, but if anyone is holding a reference to it, + // let's allow them to OO.ui.infuse() it and do what they expect (T105828). + // Do not use jQuery.data(), as using it on detached nodes leaks memory in 1.x line by design. + $elem[ 0 ].oouiInfused = obj; + } top.resolve(); } obj.$element.data( 'ooui-infused', obj ); @@ -1310,6 +1318,40 @@ OO.ui.Element.static.unsafeInfuse = function ( idOrNode, domPromise ) { return obj; }; +/** + * Pick out parts of `node`'s DOM to be reused when infusing a widget. + * + * This method **must not** make any changes to the DOM, only find interesting pieces and add them + * to `config` (which should then be returned). Actual DOM juggling should then be done by the + * constructor, which will be given the enhanced config. + * + * @protected + * @param {HTMLElement} node + * @param {Object} config + * @return {Object} + */ +OO.ui.Element.static.reusePreInfuseDOM = function ( node, config ) { + return config; +}; + +/** + * Gather the dynamic state (focus, value of form inputs, scroll position, etc.) of a HTML DOM node + * (and its children) that represent an Element of the same class and the given configuration, + * generated by the PHP implementation. + * + * This method is called just before `node` is detached from the DOM. The return value of this + * function will be passed to #restorePreInfuseState after the newly created widget's #$element + * is inserted into DOM to replace `node`. + * + * @protected + * @param {HTMLElement} node + * @param {Object} config + * @return {Object} + */ +OO.ui.Element.static.gatherPreInfuseState = function () { + return {}; +}; + /** * Get a jQuery function within a specific document. * @@ -1888,23 +1930,6 @@ OO.ui.Element.prototype.scrollElementIntoView = function ( config ) { return OO.ui.Element.static.scrollIntoView( this.$element[ 0 ], config ); }; -/** - * Gather the dynamic state (focus, value of form inputs, scroll position, etc.) of a HTML DOM node - * (and its children) that represent an Element of the same type and configuration as the current - * one, generated by the PHP implementation. - * - * This method is called just before `node` is detached from the DOM. The return value of this - * function will be passed to #restorePreInfuseState after this widget's #$element is inserted into - * DOM to replace `node`. - * - * @protected - * @param {HTMLElement} node - * @return {Object} - */ -OO.ui.Element.prototype.gatherPreInfuseState = function () { - return {}; -}; - /** * Restore the pre-infusion dynamic state for this widget. * @@ -9020,7 +9045,7 @@ OO.ui.ProcessDialog.prototype.getTeardownProcess = function ( data ) { * @throws {Error} An error is thrown if no widget is specified */ OO.ui.FieldLayout = function OoUiFieldLayout( fieldWidget, config ) { - var hasInputWidget, div, i; + var hasInputWidget, div; // Allow passing positional parameters inside the config object if ( OO.isPlainObject( fieldWidget ) && config === undefined ) { @@ -9047,8 +9072,8 @@ OO.ui.FieldLayout = function OoUiFieldLayout( fieldWidget, config ) { // Properties this.fieldWidget = fieldWidget; - this.errors = config.errors || []; - this.notices = config.notices || []; + this.errors = []; + this.notices = []; this.$field = $( '
' ); this.$messages = $( '