X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Flib%2Foojs-ui%2Foojs-ui.js;h=d42139e8921e742c2818603160012b9d740a38d6;hb=0b8f48c5353bb12faef3546c80a76aea6d3956ea;hp=94ae50e0cd6c2243292e1f13e9306adb4e20d0bd;hpb=eae1f41e72a9a0b67bfda9c7c6f58e6887e023bb;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/lib/oojs-ui/oojs-ui.js b/resources/lib/oojs-ui/oojs-ui.js index 94ae50e0cd..d42139e892 100644 --- a/resources/lib/oojs-ui/oojs-ui.js +++ b/resources/lib/oojs-ui/oojs-ui.js @@ -1,12 +1,12 @@ /*! - * OOjs UI v0.1.0-pre (1829141230) + * OOjs UI v0.2.3 * https://www.mediawiki.org/wiki/OOjs_UI * * Copyright 2011â2014 OOjs Team and other contributors. * Released under the MIT license * http://oojs.mit-license.org * - * Date: 2014-10-15T22:49:59Z + * Date: 2014-11-26T23:37:00Z */ ( function ( OO ) { @@ -93,6 +93,30 @@ OO.ui.getLocalValue = function ( obj, lang, fallback ) { return undefined; }; +/** + * Check if a node is contained within another node + * + * Similar to jQuery#contains except a list of containers can be supplied + * and a boolean argument allows you to include the container in the match list + * + * @param {HTMLElement|HTMLElement[]} containers Container node(s) to search in + * @param {HTMLElement} contained Node to find + * @param {boolean} [matchContainers] Include the container(s) in the list of nodes to match, otherwise only match descendants + * @return {boolean} The node is in the list of target nodes + */ +OO.ui.contains = function ( containers, contained, matchContainers ) { + var i; + if ( !Array.isArray( containers ) ) { + containers = [ containers ]; + } + for ( i = containers.length - 1; i >= 0; i-- ) { + if ( ( matchContainers && contained === containers[i] ) || $.contains( containers[i], contained ) ) { + return true; + } + } + return false; +}; + ( function () { /** * Message store for the default implementation of OO.ui.msg @@ -111,6 +135,10 @@ OO.ui.getLocalValue = function ( obj, lang, fallback ) { 'ooui-outline-control-remove': 'Remove item', // Label for the toolbar group that contains a list of all other available tools 'ooui-toolbar-more': 'More', + // Label for the fake tool that expands the full list of tools in a toolbar group + 'ooui-toolgroup-expand': 'More', + // Label for the fake tool that collapses the full list of tools in a toolbar group + 'ooui-toolgroup-collapse': 'Fewer', // Default label for the accept button of a confirmation dialog 'ooui-dialog-message-accept': 'OK', // Default label for the reject button of a confirmation dialog @@ -119,8 +147,10 @@ OO.ui.getLocalValue = function ( obj, lang, fallback ) { 'ooui-dialog-process-error': 'Something went wrong', // Label for process dialog dismiss error button, visible when describing errors 'ooui-dialog-process-dismiss': 'Dismiss', - // Label for process dialog retry action button, visible when describing recoverable errors - 'ooui-dialog-process-retry': 'Try again' + // Label for process dialog retry action button, visible when describing only recoverable errors + 'ooui-dialog-process-retry': 'Try again', + // Label for process dialog retry action button, visible when describing only warnings + 'ooui-dialog-process-continue': 'Continue' }; /** @@ -196,9 +226,10 @@ OO.ui.getLocalValue = function ( obj, lang, fallback ) { * * @constructor * @param {Object} [config] Configuration options + * @cfg {jQuery} [$pending] Element to mark as pending, defaults to this.$element */ OO.ui.PendingElement = function OoUiPendingElement( config ) { - // Config initialisation + // Configuration initialization config = config || {}; // Properties @@ -283,7 +314,7 @@ OO.ui.PendingElement.prototype.popPending = function () { * @param {Object} [config] Configuration options */ OO.ui.ActionSet = function OoUiActionSet( config ) { - // Configuration intialization + // Configuration initialization config = config || {}; // Mixin constructors @@ -625,7 +656,7 @@ OO.ui.ActionSet.prototype.clear = function () { /** * Organize actions. * - * This is called whenver organized information is requested. It will only reorganize the actions + * This is called whenever organized information is requested. It will only reorganize the actions * if something has changed since the last time it ran. * * @private @@ -642,7 +673,7 @@ OO.ui.ActionSet.prototype.organize = function () { for ( i = 0, iLen = this.list.length; i < iLen; i++ ) { action = this.list[i]; if ( action.isVisible() ) { - // Populate catgeories + // Populate categories for ( category in this.categories ) { if ( !this.categorized[category] ) { this.categorized[category] = {}; @@ -689,9 +720,10 @@ OO.ui.ActionSet.prototype.organize = function () { * @constructor * @param {Object} [config] Configuration options * @cfg {Function} [$] jQuery for the frame the widget is in - * @cfg {string[]} [classes] CSS class names + * @cfg {string[]} [classes] CSS class names to add * @cfg {string} [text] Text to insert * @cfg {jQuery} [$content] Content elements to append (after text) + * @cfg {Mixed} [data] Element data */ OO.ui.Element = function OoUiElement( config ) { // Configuration initialization @@ -699,11 +731,10 @@ OO.ui.Element = function OoUiElement( config ) { // Properties this.$ = config.$ || OO.ui.Element.getJQuery( document ); + this.data = config.data; this.$element = this.$( this.$.context.createElement( this.getTagName() ) ); this.elementGroup = null; - this.debouncedUpdateThemeClassesHandler = OO.ui.bind( - this.debouncedUpdateThemeClasses, this - ); + this.debouncedUpdateThemeClassesHandler = this.debouncedUpdateThemeClasses.bind( this ); this.updateThemeClassesPending = false; // Initialization @@ -727,7 +758,7 @@ OO.initClass( OO.ui.Element ); /** * HTML tag name. * - * This may be ignored if getTagName is overridden. + * This may be ignored if #getTagName is overridden. * * @static * @inheritable @@ -798,7 +829,7 @@ OO.ui.Element.getWindow = function ( obj ) { * * @static * @param {jQuery|HTMLElement|HTMLDocument|Window} obj Context to get the direction for - * @return {string} Text direction, either `ltr` or `rtl` + * @return {string} Text direction, either 'ltr' or 'rtl' */ OO.ui.Element.getDir = function ( obj ) { var isDoc, isWin; @@ -865,15 +896,35 @@ OO.ui.Element.getFrameOffset = function ( from, to, offset ) { /** * Get the offset between two elements. * + * The two elements may be in a different frame, but in that case the frame $element is in must + * be contained in the frame $anchor is in. + * * @static - * @param {jQuery} $from - * @param {jQuery} $to + * @param {jQuery} $element Element whose position to get + * @param {jQuery} $anchor Element to get $element's position relative to * @return {Object} Translated position coordinates, containing top and left properties */ -OO.ui.Element.getRelativePosition = function ( $from, $to ) { - var from = $from.offset(), - to = $to.offset(); - return { top: Math.round( from.top - to.top ), left: Math.round( from.left - to.left ) }; +OO.ui.Element.getRelativePosition = function ( $element, $anchor ) { + var iframe, iframePos, + pos = $element.offset(), + anchorPos = $anchor.offset(), + elementDocument = this.getDocument( $element ), + anchorDocument = this.getDocument( $anchor ); + + // If $element isn't in the same document as $anchor, traverse up + while ( elementDocument !== anchorDocument ) { + iframe = elementDocument.defaultView.frameElement; + if ( !iframe ) { + throw new Error( '$element frame is not contained in $anchor frame' ); + } + iframePos = $( iframe ).offset(); + pos.left += iframePos.left; + pos.top += iframePos.top; + elementDocument = iframe.ownerDocument; + } + pos.left -= anchorPos.left; + pos.top -= anchorPos.top; + return pos; }; /** @@ -989,7 +1040,7 @@ OO.ui.Element.getClosestScrollableContainer = function ( el, dimension ) { * * @static * @param {HTMLElement} el Element to scroll into view - * @param {Object} [config={}] Configuration config + * @param {Object} [config] Configuration options * @param {string} [config.duration] jQuery animation duration value * @param {string} [config.direction] Scroll in only one direction, e.g. 'x' or 'y', omit * to scroll in both directions @@ -1086,10 +1137,50 @@ OO.ui.Element.offDOMEvent = function ( el, event, callback ) { /* Methods */ +/** + * Get element data. + * + * @return {Mixed} Element data + */ +OO.ui.Element.prototype.getData = function () { + return this.data; +}; + +/** + * Set element data. + * + * @param {Mixed} Element data + * @chainable + */ +OO.ui.Element.prototype.setData = function ( data ) { + this.data = data; + return this; +}; + +/** + * Check if element supports one or more methods. + * + * @param {string|string[]} methods Method or list of methods to check + * @return {boolean} All methods are supported + */ +OO.ui.Element.prototype.supports = function ( methods ) { + var i, len, + support = 0; + + methods = $.isArray( methods ) ? methods : [ methods ]; + for ( i = 0, len = methods.length; i < len; i++ ) { + if ( $.isFunction( this[methods[i]] ) ) { + support++; + } + } + + return methods.length === support; +}; + /** * Update the theme-provided classes. * - * @localdoc This is called in element mixins and widget classes anytime state changes. + * @localdoc This is called in element mixins and widget classes any time state changes. * Updating is debounced, minimizing overhead of changing multiple attributes and * guaranteeing that theme updates do not occur within an element's constructor */ @@ -1175,7 +1266,7 @@ OO.ui.Element.prototype.setElementGroup = function ( group ) { /** * Scroll element into view. * - * @param {Object} [config={}] + * @param {Object} [config] Configuration options */ OO.ui.Element.prototype.scrollElementIntoView = function ( config ) { return OO.ui.Element.scrollIntoView( this.$element[0], config ); @@ -1215,7 +1306,7 @@ OO.ui.Element.prototype.offDOMEvent = function ( event, callback ) { * @param {Object} [config] Configuration options */ OO.ui.Layout = function OoUiLayout( config ) { - // Initialize config + // Configuration initialization config = config || {}; // Parent constructor @@ -1287,7 +1378,7 @@ OO.mixinClass( OO.ui.Widget, OO.EventEmitter ); /** * Check if the widget is disabled. * - * @param {boolean} Button is disabled + * @return {boolean} Button is disabled */ OO.ui.Widget.prototype.isDisabled = function () { return this.disabled; @@ -1382,8 +1473,8 @@ OO.ui.Widget.prototype.updateDisabled = function () { * * Each process (setup, ready, hold and teardown) can be extended in subclasses by overriding * {@link #getSetupProcess}, {@link #getReadyProcess}, {@link #getHoldProcess} and - * {@link #getTeardownProcess} respectively. Each process is executed in series, so asynchonous - * processing can complete. Always assume window processes are executed asychronously. See + * {@link #getTeardownProcess} respectively. Each process is executed in series, so asynchronous + * processing can complete. Always assume window processes are executed asynchronously. See * OO.ui.Process for more details about how to work with processes. Some events, as well as the * #open and #close methods, provide promises which are resolved when the window enters a new state. * @@ -1394,7 +1485,6 @@ OO.ui.Widget.prototype.updateDisabled = function () { * @param {Object} [config] Configuration options * @cfg {string} [size] Symbolic name of dialog size, `small`, `medium`, `large` or `full`; omit to * use #static-size - * @fires initialize */ OO.ui.Window = function OoUiWindow( config ) { // Configuration initialization @@ -1426,7 +1516,7 @@ OO.ui.Window = function OoUiWindow( config ) { this.$frame.addClass( 'oo-ui-window-frame' ); this.$overlay.addClass( 'oo-ui-window-overlay' ); - // NOTE: Additional intitialization will occur when #setManager is called + // NOTE: Additional initialization will occur when #setManager is called }; /* Setup */ @@ -1666,11 +1756,20 @@ OO.ui.Window.prototype.getSize = function () { * @return {number} Content height */ OO.ui.Window.prototype.getContentHeight = function () { - // Temporarily resize the frame so getBodyHeight() can use scrollHeight measurements - var bodyHeight, oldHeight = this.$frame[0].style.height; - this.$frame[0].style.height = '1px'; + // Temporarily resize the frame so getBodyHeight() can use scrollHeight measurements. + // Disable transitions first, otherwise we'll get values from when the window was animating. + var bodyHeight, oldHeight, oldTransition, + styleObj = this.$frame[0].style; + oldTransition = styleObj.transition || styleObj.OTransition || styleObj.MsTransition || + styleObj.MozTransition || styleObj.WebkitTransition; + styleObj.transition = styleObj.OTransition = styleObj.MsTransition = + styleObj.MozTransition = styleObj.WebkitTransition = 'none'; + oldHeight = styleObj.height; + styleObj.height = '1px'; bodyHeight = this.getBodyHeight(); - this.$frame[0].style.height = oldHeight; + styleObj.height = oldHeight; + styleObj.transition = styleObj.OTransition = styleObj.MsTransition = + styleObj.MozTransition = styleObj.WebkitTransition = oldTransition; return Math.round( // Add buffer for border @@ -1772,11 +1871,11 @@ OO.ui.Window.prototype.getTeardownProcess = function () { /** * Toggle visibility of window. * - * If the window is isolated and hasn't fully loaded yet, the visiblity property will be used + * If the window is isolated and hasn't fully loaded yet, the visibility property will be used * instead of display. * * @param {boolean} [show] Make window visible, omit to toggle visibility - * @fires visible + * @fires toggle * @chainable */ OO.ui.Window.prototype.toggle = function ( show ) { @@ -1903,7 +2002,7 @@ OO.ui.Window.prototype.initialize = function () { this.$innerOverlay = this.$( '