diff --git a/.editorconfig b/.editorconfig index c94db9a8ef..1ba4f5faac 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,3 +9,8 @@ end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true + +[external/**] +trim_trailing_whitespace = false +insert_final_newline = varies +end_of_line = varies diff --git a/.jshintrc b/.jshintrc index 99161bd4e3..d6966c51d9 100644 --- a/.jshintrc +++ b/.jshintrc @@ -3,10 +3,10 @@ "eqnull": true, "eqeqeq": true, "expr": true, - "latedef": true, "noarg": true, + "node": true, "onevar": true, - "smarttabs": true, "trailing": true, - "undef": true + "undef": true, + "unused": true } diff --git a/build/.jshintrc b/build/.jshintrc deleted file mode 100644 index 9e6abf31d7..0000000000 --- a/build/.jshintrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "curly": true, - "eqnull": true, - "eqeqeq": true, - "expr": true, - "noarg": true, - "node": true, - "onevar": true, - "smarttabs": true, - "strict": false, - "trailing": true, - "undef": true -} diff --git a/build/release/changelog-shell b/build/release/changelog-shell index 9c9df93508..9f0f9b4360 100644 --- a/build/release/changelog-shell +++ b/build/release/changelog-shell @@ -24,54 +24,86 @@ DELETE EVERYTHING ABOVE THE FOLLOWING LINE ## Build + ## Core & Utilities ### UI Core + ### Mouse + ### Widget Factory + ### Position + ## Interactions ### Draggable + ### Droppable + ### Resizable + ### Selectable + ### Sortable + ## Widgets ### Accordion + ### Autocomplete + ### Button + ### Datepicker + ### Dialog + +### Menu + + ### Progressbar + ### Slider + +### Spinner + + ### Tabs + +### Tooltip + + ## Effects + ### Individual effects + ## CSS Framework + ## Demos + ## Website + ### Download Builder diff --git a/build/release/release.js b/build/release/release.js index 77430d8d16..0e41702e97 100644 --- a/build/release/release.js +++ b/build/release/release.js @@ -1,5 +1,7 @@ #!/usr/bin/env node -/*global cat:true cd:true cp:true echo:true exec:true exit:true ls:true*/ +/*global cat:true cd:true echo:true exec:true exit:true*/ + +"use strict"; var baseDir, repoDir, prevVersion, newVersion, nextVersion, tagTime, fs = require( "fs" ), @@ -41,9 +43,6 @@ walk([ section( "gathering contributors" ), gatherContributors, - section( "generating quick download" ), - generateQuickDownload, - section( "updating trac" ), updateTrac, confirm @@ -261,34 +260,6 @@ function gatherContributors() { echo( "Stored contributors in " + contributorsPath.cyan + "." ); } -function generateQuickDownload() { - var config, - downloadDir = repoDir + "/node_modules/download.jqueryui.com", - filename = "jquery-ui-" + newVersion + ".custom.zip", - destination = baseDir + "/" + filename; - - cd( downloadDir ); - - // Update jQuery UI version for download builder - config = JSON.parse( cat( "config.json" ) ); - config.jqueryUi = newVersion; - JSON.stringify( config ).to( "config.json" ); - - // Generate quick download - // TODO: Find a way to avoid having to clone jquery-ui inside download builder - if ( exec( "grunt prepare build" ).code !== 0 ) { - abort( "Error generating quick download." ); - } - cp( downloadDir + "/release/" + filename, destination ); - // cp() doesn't have error handling, so check for the file - if ( ls( destination ).length !== 1 ) { - abort( "Error copying quick download." ); - } - - // Go back to repo directory for consistency - cd( repoDir ); -} - function updateTrac() { echo( newVersion.cyan + " was tagged at " + tagTime.cyan + "." ); echo( "Close the " + newVersion.cyan + " Milestone with the above date and time." ); @@ -423,7 +394,7 @@ function abort( msg ) { function walk( methods ) { var method = methods.shift(); - function next( error ) { + function next() { if ( methods.length ) { walk( methods ); } diff --git a/build/tasks/build.js b/build/tasks/build.js index 3f3dd31c55..18e427a565 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -1,6 +1,9 @@ module.exports = function( grunt ) { -var path = require( "path" ); +"use strict"; + +var path = require( "path" ), + fs = require( "fs" ); grunt.registerTask( "manifest", "Generate jquery.json manifest files", function() { var pkg = grunt.config( "pkg" ), @@ -143,7 +146,7 @@ grunt.registerMultiTask( "zip", "Create a zip file for release", function() { opts: { cwd: 'dist' } - }, function( err, result ) { + }, function( err ) { if ( err ) { grunt.log.error( err ); done(); diff --git a/build/tasks/testswarm.js b/build/tasks/testswarm.js index 34c17d4f6b..f76c5570d4 100644 --- a/build/tasks/testswarm.js +++ b/build/tasks/testswarm.js @@ -1,6 +1,7 @@ -/*jshint node: true */ module.exports = function( grunt ) { +"use strict"; + var versions = { "git": "git", "1.8": "1.8.0 1.8.1 1.8.2", @@ -9,26 +10,23 @@ var versions = { }, tests = { "Accordion": "accordion/accordion.html", - "Accordion_deprecated": "accordion/accordion_deprecated.html", "Autocomplete": "autocomplete/autocomplete.html", "Button": "button/button.html", "Core": "core/core.html", - //"datepicker/datepicker.html", - //"dialog/dialog.html", - //"draggable/draggable.html", - //"droppable/droppable.html", + "Datepicker": "datepicker/datepicker.html", + "Dialog": "dialog/dialog.html", + "Draggable": "draggable/draggable.html", + "Droppable": "droppable/droppable.html", "Effects": "effects/effects.html", "Menu": "menu/menu.html", "Position": "position/position.html", - "Position_deprecated": "position/position_deprecated.html", "Progressbar": "progressbar/progressbar.html", - //"resizable/resizable.html", - //"selectable/selectable.html", - //"slider/slider.html", - //"sortable/sortable.html", + "Resizable": "resizable/resizable.html", + "Selectable": "selectable/selectable.html", + "Slider": "slider/slider.html", + "Sortable": "sortable/sortable.html", "Spinner": "spinner/spinner.html", "Tabs": "tabs/tabs.html", - "Tabs_deprecated": "tabs/tabs_deprecated.html", "Tooltip": "tooltip/tooltip.html", "Widget": "widget/widget.html" }; @@ -53,9 +51,9 @@ function submit( commit, tests, configFile, version, done ) { authToken: config.authToken, jobName: 'jQuery UI ' + version + '#' + commit.substr( 0, 10 ) + '', runMax: config.runMax, - "runNames[]": Object.keys(tests), + "runNames[]": Object.keys( tests ), "runUrls[]": testUrls, - "browserSets[]": ["popular"] + "browserSets[]": [ "popular-no-ie6" ] }); } diff --git a/demos/autocomplete/combobox.html b/demos/autocomplete/combobox.html index cc43f45277..c8270c2d81 100644 --- a/demos/autocomplete/combobox.html +++ b/demos/autocomplete/combobox.html @@ -111,7 +111,6 @@ input.data( "autocomplete" )._renderItem = function( ul, item ) { return $( "
  • " ) - .data( "item.autocomplete", item ) .append( "" + item.label + "" ) .appendTo( ul ); }; diff --git a/demos/autocomplete/custom-data.html b/demos/autocomplete/custom-data.html index 1e64df047a..df191b8993 100644 --- a/demos/autocomplete/custom-data.html +++ b/demos/autocomplete/custom-data.html @@ -68,7 +68,6 @@ }) .data( "autocomplete" )._renderItem = function( ul, item ) { return $( "
  • " ) - .data( "item.autocomplete", item ) .append( "" + item.label + "
    " + item.desc + "
    " ) .appendTo( ul ); }; diff --git a/demos/button/icons.html b/demos/button/icons.html index 8c4bf5a30f..78f01d707d 100644 --- a/demos/button/icons.html +++ b/demos/button/icons.html @@ -43,7 +43,7 @@
    -

    Some buttons with various combinations of text and icons, here specified via metadata.

    +

    Some buttons with various combinations of text and icons.

    diff --git a/demos/datepicker/localization.html b/demos/datepicker/localization.html index 4fd7a1c461..f6d00631a8 100644 --- a/demos/datepicker/localization.html +++ b/demos/datepicker/localization.html @@ -46,6 +46,7 @@ + @@ -134,6 +135,7 @@ + diff --git a/demos/dialog/animated.html b/demos/dialog/animated.html index 8a27150de0..92d7b642db 100644 --- a/demos/dialog/animated.html +++ b/demos/dialog/animated.html @@ -5,7 +5,6 @@ jQuery UI Dialog - Animation - @@ -18,18 +17,21 @@ diff --git a/demos/dialog/default.html b/demos/dialog/default.html index 5dcb1a05c6..19cf912e29 100644 --- a/demos/dialog/default.html +++ b/demos/dialog/default.html @@ -5,7 +5,6 @@ jQuery UI Dialog - Default functionality - diff --git a/demos/dialog/modal-confirmation.html b/demos/dialog/modal-confirmation.html index cca3b296dd..b9bf6396ff 100644 --- a/demos/dialog/modal-confirmation.html +++ b/demos/dialog/modal-confirmation.html @@ -5,7 +5,6 @@ jQuery UI Dialog - Modal confirmation - diff --git a/demos/dialog/modal-form.html b/demos/dialog/modal-form.html index 48452f8629..1c0cd6fc3b 100644 --- a/demos/dialog/modal-form.html +++ b/demos/dialog/modal-form.html @@ -5,7 +5,6 @@ jQuery UI Dialog - Modal form - diff --git a/demos/dialog/modal-message.html b/demos/dialog/modal-message.html index d443310177..3c877b26e8 100644 --- a/demos/dialog/modal-message.html +++ b/demos/dialog/modal-message.html @@ -5,7 +5,6 @@ jQuery UI Dialog - Modal message - diff --git a/demos/dialog/modal.html b/demos/dialog/modal.html index 2b1ac25745..9bb6d95b24 100644 --- a/demos/dialog/modal.html +++ b/demos/dialog/modal.html @@ -5,7 +5,6 @@ jQuery UI Dialog - Basic modal - diff --git a/demos/droppable/photo-manager.html b/demos/droppable/photo-manager.html index 315473761f..7da5f53702 100644 --- a/demos/droppable/photo-manager.html +++ b/demos/droppable/photo-manager.html @@ -15,7 +15,7 @@
    -

    A menu with the default configuration. A list is transformed, adding theming, mouse and keyboard navigation support. Try to tab to the menu then use the cursor keys to navigate.

    +

    A menu with the default configuration, disabled items and nested menus. A list is transformed, adding theming, mouse and keyboard navigation support. Try to tab to the menu then use the cursor keys to navigate.

    diff --git a/demos/menu/icons.html b/demos/menu/icons.html new file mode 100644 index 0000000000..56cf242f33 --- /dev/null +++ b/demos/menu/icons.html @@ -0,0 +1,44 @@ + + + + + jQuery UI Menu - Icons + + + + + + + + + + + + + + +
    +

    A menu with the default configuration, showing how to use a menu with icons.

    +
    + + diff --git a/demos/menu/index.html b/demos/menu/index.html index 07556c6ec1..40e9e0b54e 100644 --- a/demos/menu/index.html +++ b/demos/menu/index.html @@ -8,8 +8,7 @@ diff --git a/demos/menu/navigationmenu.html b/demos/menu/navigationmenu.html deleted file mode 100644 index c2bb307bab..0000000000 --- a/demos/menu/navigationmenu.html +++ /dev/null @@ -1,74 +0,0 @@ - - - - - jQuery UI Menu - Navigation Menu - - - - - - - - - - - - - - -
    -

    A navigation menu. A list is transformed, adding theming, mouse and keyboard navigation support. Try to tab to the menu then use the cursor keys to navigate.

    -
    - - diff --git a/demos/menu/topalignmenu.html b/demos/menu/topalignmenu.html deleted file mode 100644 index 4f34b98c2a..0000000000 --- a/demos/menu/topalignmenu.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - - Menu Demo: Top-aligned Menu - - - - - - - - - - - - - - -
    -

    Menus can use custom positioning. There is a delay before activing an item on hover and a delay before closing a menu on mouse out to allow for moving to a submenu that is not touching its parent item.

    -
    - - diff --git a/demos/position/cycler.html b/demos/position/cycler.html index 2c421211f8..dc9c8a0bd3 100644 --- a/demos/position/cycler.html +++ b/demos/position/cycler.html @@ -10,6 +10,9 @@ diff --git a/external/jquery.bgiframe-2.1.2.js b/external/jquery.bgiframe-2.1.2.js deleted file mode 100644 index 5cd38bb1d1..0000000000 --- a/external/jquery.bgiframe-2.1.2.js +++ /dev/null @@ -1,39 +0,0 @@ -/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net) - * Licensed under the MIT License (LICENSE.txt). - * - * Version 2.1.2 - */ - -(function($){ - -$.fn.bgiframe = ($.browser.msie && /msie 6\.0/i.test(navigator.userAgent) ? function(s) { - s = $.extend({ - top : 'auto', // auto == .currentStyle.borderTopWidth - left : 'auto', // auto == .currentStyle.borderLeftWidth - width : 'auto', // auto == offsetWidth - height : 'auto', // auto == offsetHeight - opacity : true, - src : 'javascript:false;' - }, s); - var html = '' : ''); + html += buttonPanel; inst._keyEvent = false; return html; }, @@ -1647,8 +1647,8 @@ $.extend(Datepicker.prototype, { var years = this._get(inst, 'yearRange').split(':'); var thisYear = new Date().getFullYear(); var determineYear = function(value) { - var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) : - (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) : + var year = (value.match(/c[+\-].*/) ? drawYear + parseInt(value.substring(1), 10) : + (value.match(/[+\-].*/) ? thisYear + parseInt(value, 10) : parseInt(value, 10))); return (isNaN(year) ? thisYear : year); }; @@ -1663,7 +1663,7 @@ $.extend(Datepicker.prototype, { '>' + year + ''; } inst.yearshtml += ''; - + html += inst.yearshtml; inst.yearshtml = null; } @@ -1774,7 +1774,7 @@ $.extend(Datepicker.prototype, { * Bind hover events for datepicker elements. * Done via delegate so the binding only occurs once in the lifetime of the parent div. * Global instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker. - */ + */ function bindHover(dpDiv) { var selector = 'button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a'; return dpDiv.delegate(selector, 'mouseout', function() { @@ -1796,22 +1796,22 @@ function bindHover(dpDiv) { function extendRemove(target, props) { $.extend(target, props); for (var name in props) - if (props[name] == null || props[name] == undefined) + if (props[name] == null) target[name] = props[name]; return target; -}; +} /* Invoke the datepicker functionality. @param options string - a command, optionally followed by additional parameters or - Object - settings for attaching new datepicker functionality + Object - settings for attaching new datepicker functionality @return jQuery object */ $.fn.datepicker = function(options){ - + /* Verify an empty collection wasn't passed - Fixes #6976 */ if ( !this.length ) { return this; } - + /* Initialise the date picker. */ if (!$.datepicker.initialized) { $(document).mousedown($.datepicker._checkExternalClick). diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 8593fff854..07c5c7cb6a 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -19,7 +19,7 @@ */ (function( $, undefined ) { -var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ", +var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ", sizeRelatedOptions = { buttons: true, height: true, @@ -67,10 +67,8 @@ $.widget("ui.dialog", { }, resizable: true, show: null, - stack: true, title: "", - width: 300, - zIndex: 1000 + width: 300 }, _create: function() { @@ -88,14 +86,15 @@ $.widget("ui.dialog", { options = this.options, title = options.title || " ", + uiDialog, + uiDialogTitlebar, + uiDialogTitlebarClose, + uiDialogTitle, + uiDialogButtonPane; uiDialog = ( this.uiDialog = $( "
    " ) ) .addClass( uiDialogClasses + options.dialogClass ) - .css({ - display: "none", - outline: 0, // TODO: move to stylesheet - zIndex: options.zIndex - }) + .hide() // setting tabIndex makes the div focusable .attr( "tabIndex", -1) .keydown(function( event ) { @@ -106,20 +105,24 @@ $.widget("ui.dialog", { } }) .mousedown(function( event ) { - that.moveToTop( false, event ); + that.moveToTop( event ); }) - .appendTo( "body" ), + .appendTo( this.document[ 0 ].body ); - uiDialogContent = this.element + this.element .show() .removeAttr( "title" ) .addClass( "ui-dialog-content ui-widget-content" ) - .appendTo( uiDialog ), + .appendTo( uiDialog ); uiDialogTitlebar = ( this.uiDialogTitlebar = $( "
    " ) ) .addClass( "ui-dialog-titlebar ui-widget-header " + "ui-corner-all ui-helper-clearfix" ) - .prependTo( uiDialog ), + .bind( "mousedown", function() { + // Dialog isn't getting focus when dragging (#8063) + uiDialog.focus(); + }) + .prependTo( uiDialog ); uiDialogTitlebarClose = $( "" ) .addClass( "ui-dialog-titlebar-close ui-corner-all" ) @@ -128,23 +131,23 @@ $.widget("ui.dialog", { event.preventDefault(); that.close( event ); }) - .appendTo( uiDialogTitlebar ), + .appendTo( uiDialogTitlebar ); - uiDialogTitlebarCloseText = ( this.uiDialogTitlebarCloseText = $( "" ) ) + ( this.uiDialogTitlebarCloseText = $( "" ) ) .addClass( "ui-icon ui-icon-closethick" ) .text( options.closeText ) - .appendTo( uiDialogTitlebarClose ), + .appendTo( uiDialogTitlebarClose ); uiDialogTitle = $( "" ) .uniqueId() .addClass( "ui-dialog-title" ) .html( title ) - .prependTo( uiDialogTitlebar ), + .prependTo( uiDialogTitlebar ); uiDialogButtonPane = ( this.uiDialogButtonPane = $( "
    " ) ) - .addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ), + .addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ); - uiButtonSet = ( this.uiButtonSet = $( "
    " ) ) + ( this.uiButtonSet = $( "
    " ) ) .addClass( "ui-dialog-buttonset" ) .appendTo( uiDialogButtonPane ); @@ -167,13 +170,9 @@ $.widget("ui.dialog", { this._createButtons( options.buttons ); this._isOpen = false; - if ( $.fn.bgiframe ) { - uiDialog.bgiframe(); - } - - // prevent tabbing out of modal dialogs + // prevent tabbing out of dialogs this._on( uiDialog, { keydown: function( event ) { - if ( !options.modal || event.keyCode !== $.ui.keyCode.TAB ) { + if ( event.keyCode !== $.ui.keyCode.TAB ) { return; } @@ -181,10 +180,10 @@ $.widget("ui.dialog", { first = tabbables.filter( ":first" ), last = tabbables.filter( ":last" ); - if ( event.target === last[0] && !event.shiftKey ) { + if ( ( event.target === last[ 0 ] || event.target === uiDialog[ 0 ] ) && !event.shiftKey ) { first.focus( 1 ); return false; - } else if ( event.target === first[0] && event.shiftKey ) { + } else if ( ( event.target === first[ 0 ] || event.target === uiDialog[ 0 ] ) && event.shiftKey ) { last.focus( 1 ); return false; } @@ -229,8 +228,7 @@ $.widget("ui.dialog", { }, close: function( event ) { - var that = this, - maxZ, thisZ; + var that = this; if ( !this._isOpen ) { return; @@ -246,71 +244,27 @@ $.widget("ui.dialog", { this.overlay.destroy(); } - if ( this.options.hide ) { - this.uiDialog.hide( this.options.hide, function() { - that._trigger( "close", event ); - }); - } else { - this.uiDialog.hide(); - this._trigger( "close", event ); + if ( !this.opener.filter( ":focusable" ).focus().length ) { + // Hiding a focused element doesn't trigger blur in WebKit + // so in case we have nothing to focus on, explicitly blur the active element + // https://bugs.webkit.org/show_bug.cgi?id=47182 + $( this.document[ 0 ].activeElement ).blur(); } - $.ui.dialog.overlay.resize(); - - // adjust the maxZ to allow other modal dialogs to continue to work (see #4309) - if ( this.options.modal ) { - maxZ = 0; - $( ".ui-dialog" ).each(function() { - if ( this !== that.uiDialog[0] ) { - thisZ = $( this ).css( "z-index" ); - if ( !isNaN( thisZ ) ) { - maxZ = Math.max( maxZ, thisZ ); - } - } - }); - $.ui.dialog.maxZ = maxZ; - } - - return this; + this._hide( this.uiDialog, this.options.hide, function() { + that._trigger( "close", event ); + }); }, isOpen: function() { return this._isOpen; }, - // the force parameter allows us to move modal dialogs to their correct - // position on open - moveToTop: function( force, event ) { - var options = this.options, - saveScroll; - - if ( ( options.modal && !force ) || - ( !options.stack && !options.modal ) ) { - return this._trigger( "focus", event ); + moveToTop: function( event, silent ) { + var moved = this.uiDialog.nextAll( ":visible" ).insertBefore( this.uiDialog ); + if ( !silent && moved.length ) { + this._trigger( "focus", event ); } - - if ( options.zIndex > $.ui.dialog.maxZ ) { - $.ui.dialog.maxZ = options.zIndex; - } - if ( this.overlay ) { - $.ui.dialog.maxZ += 1; - $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ; - this.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ ); - } - - // Save and then restore scroll - // Opera 9.5+ resets when parent z-index is changed. - // http://bugs.jqueryui.com/ticket/3193 - saveScroll = { - scrollTop: this.element.scrollTop(), - scrollLeft: this.element.scrollLeft() - }; - $.ui.dialog.maxZ += 1; - this.uiDialog.css( "z-index", $.ui.dialog.maxZ ); - this.element.attr( saveScroll ); - this._trigger( "focus", event ); - - return this; }, open: function() { @@ -322,11 +276,13 @@ $.widget("ui.dialog", { options = this.options, uiDialog = this.uiDialog; + this.opener = $( this.document[ 0 ].activeElement ); + this._size(); this._position( options.position ); - uiDialog.show( options.show ); this.overlay = options.modal ? new $.ui.dialog.overlay( this ) : null; - this.moveToTop( true ); + this.moveToTop( null, true ); + this._show( uiDialog, options.show ); // set focus to the first tabbable element in the content area or the first button // if there are no tabbable elements, set focus on the dialog itself @@ -341,13 +297,30 @@ $.widget("ui.dialog", { this._isOpen = true; this._trigger( "open" ); + this._trigger( "focus" ); return this; }, + _keepFocus: function( event ) { + function checkFocus() { + var activeElement = this.document[ 0 ].activeElement, + isActive = this.uiDialog[ 0 ] === activeElement || + $.contains( this.uiDialog[ 0 ], activeElement ); + if ( !isActive ) { + this.uiDialog.focus(); + } + } + event.preventDefault(); + checkFocus.call( this ); + // support: IE + // IE <= 8 doesn't prevent moving focus even with event.preventDefault() + // so we check again later + this._delay( checkFocus ); + }, + _createButtons: function( buttons ) { - var uiDialogButtonPane, uiButtonSet, - that = this, + var that = this, hasButtons = false; // if we already have a button pane, remove it @@ -361,15 +334,18 @@ $.widget("ui.dialog", { } if ( hasButtons ) { $.each( buttons, function( name, props ) { + var button, click; props = $.isFunction( props ) ? { click: props, text: name } : props; - var button = $( "" ) - .attr( props, true ) - .unbind( "click" ) - .click(function() { - props.click.apply( that.element[0], arguments ); - }) + // Default to a non-submitting button + props = $.extend( { type: "button" }, props ); + // Change the context for the click callback to be the main element + click = props.click; + props.click = function() { + click.apply( that.element[0], arguments ); + }; + button = $( "", props ) .appendTo( that.uiButtonSet ); if ( $.fn.button ) { button.button(); @@ -413,7 +389,6 @@ $.widget("ui.dialog", { $( this ) .removeClass( "ui-dialog-dragging" ); that._trigger( "dragStop", event, filteredUi( ui ) ); - $.ui.dialog.overlay.resize(); } }); }, @@ -459,7 +434,6 @@ $.widget("ui.dialog", { options.height = $( this ).height(); options.width = $( this ).width(); that._trigger( "resizeStop", event, filteredUi( ui ) ); - $.ui.dialog.overlay.resize(); } }) .css( "position", position ) @@ -501,9 +475,9 @@ $.widget("ui.dialog", { }); position = { - my: myAt.join( " " ), - at: myAt.join( " " ), - offset: offset.join( " " ) + my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " + + myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]), + at: myAt.join( " " ) }; } @@ -542,7 +516,7 @@ $.widget("ui.dialog", { if ( resize ) { this._size(); } - if ( this.uiDialog.is( ":data(resizable)" ) ) { + if ( this.uiDialog.is( ":data(ui-resizable)" ) ) { this.uiDialog.resizable( "option", resizableOptions ); } }, @@ -572,7 +546,7 @@ $.widget("ui.dialog", { } break; case "draggable": - isDraggable = uiDialog.is( ":data(draggable)" ); + isDraggable = uiDialog.is( ":data(ui-draggable)" ); if ( isDraggable && !value ) { uiDialog.draggable( "destroy" ); } @@ -586,7 +560,7 @@ $.widget("ui.dialog", { break; case "resizable": // currently resizable, becoming non-resizable - isResizable = uiDialog.is( ":data(resizable)" ); + isResizable = uiDialog.is( ":data(ui-resizable)" ); if ( isResizable && !value ) { uiDialog.resizable( "destroy" ); } @@ -612,12 +586,11 @@ $.widget("ui.dialog", { }, _size: function() { - /* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content - * divs will both have width and height set, so we need to reset them - */ - var nonContentHeight, minContentHeight, autoHeight, - options = this.options, - isVisible = this.uiDialog.is( ":visible" ); + + // If the user has resized the dialog, the .ui-dialog and .ui-dialog-content + // divs will both have width and height set, so we need to reset them + var nonContentHeight, minContentHeight, + options = this.options; // reset content sizing this.element.show().css({ @@ -640,25 +613,15 @@ $.widget("ui.dialog", { minContentHeight = Math.max( 0, options.minHeight - nonContentHeight ); if ( options.height === "auto" ) { - // only needed for IE6 support - if ( $.support.minHeight ) { - this.element.css({ - minHeight: minContentHeight, - height: "auto" - }); - } else { - this.uiDialog.show(); - autoHeight = this.element.css( "height", "auto" ).height(); - if ( !isVisible ) { - this.uiDialog.hide(); - } - this.element.height( Math.max( autoHeight, minContentHeight ) ); - } + this.element.css({ + minHeight: minContentHeight, + height: "auto" + }); } else { this.element.height( Math.max( options.height - nonContentHeight, 0 ) ); } - if (this.uiDialog.is( ":data(resizable)" ) ) { + if (this.uiDialog.is( ":data(ui-resizable)" ) ) { this.uiDialog.resizable( "option", "minHeight", this._minHeight() ); } } @@ -666,7 +629,6 @@ $.widget("ui.dialog", { $.extend($.ui.dialog, { uuid: 0, - maxZ: 0, getTitleId: function($el) { var id = $el.attr( "id" ); @@ -686,66 +648,22 @@ $.extend( $.ui.dialog.overlay, { instances: [], // reuse old instances due to IE memory leak with alpha transparency (see #5185) oldInstances: [], - maxZ: 0, - events: $.map( - "focus,mousedown,mouseup,keydown,keypress,click".split( "," ), - function( event ) { - return event + ".dialog-overlay"; - } - ).join( " " ), create: function( dialog ) { - if ( this.instances.length === 0 ) { - // prevent use of anchors and inputs - // we use a setTimeout in case the overlay is created from an - // event that we're going to be cancelling (see #2804) - setTimeout(function() { - // handle $(el).dialog().dialog('close') (see #4065) - if ( $.ui.dialog.overlay.instances.length ) { - $( document ).bind( $.ui.dialog.overlay.events, function( event ) { - // stop events if the z-index of the target is < the z-index of the overlay - // we cannot return true when we don't want to cancel the event (#3523) - if ( $( event.target ).zIndex() < $.ui.dialog.overlay.maxZ ) { - return false; - } - }); - } - }, 1 ); - // handle window resize - $( window ).bind( "resize.dialog-overlay", $.ui.dialog.overlay.resize ); - } + var $el = ( this.oldInstances.pop() || $( "
    " ).addClass( "ui-widget-overlay ui-front" ) ); - var $el = ( this.oldInstances.pop() || $( "
    " ).addClass( "ui-widget-overlay" ) ); + $el.appendTo( document.body ); - // allow closing by pressing the escape key - $( document ).bind( "keydown.dialog-overlay", function( event ) { - var instances = $.ui.dialog.overlay.instances; - // only react to the event if we're the top overlay - if ( instances.length !== 0 && instances[ instances.length - 1 ] === $el && - dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode && - event.keyCode === $.ui.keyCode.ESCAPE ) { - - dialog.close( event ); - event.preventDefault(); - } + $el.bind( "mousedown", function( event ) { + dialog._keepFocus( event ); }); - $el.appendTo( document.body ).css({ - width: this.width(), - height: this.height() - }); - - if ( $.fn.bgiframe ) { - $el.bgiframe(); - } - this.instances.push( $el ); return $el; }, destroy: function( $el ) { - var indexOf = $.inArray( $el, this.instances ), - maxZ = 0; + var indexOf = $.inArray( $el, this.instances ); if ( indexOf !== -1 ) { this.oldInstances.push( this.instances.splice( indexOf, 1 )[ 0 ] ); @@ -755,86 +673,7 @@ $.extend( $.ui.dialog.overlay, { $( [ document, window ] ).unbind( ".dialog-overlay" ); } - $el.height( 0 ).width( 0 ).remove(); - - // adjust the maxZ to allow other modal dialogs to continue to work (see #4309) - $.each( this.instances, function() { - maxZ = Math.max( maxZ, this.css( "z-index" ) ); - }); - this.maxZ = maxZ; - }, - - height: function() { - var scrollHeight, - offsetHeight; - // handle IE - if ( $.ui.ie ) { - scrollHeight = Math.max( - document.documentElement.scrollHeight, - document.body.scrollHeight - ); - offsetHeight = Math.max( - document.documentElement.offsetHeight, - document.body.offsetHeight - ); - - if ( scrollHeight < offsetHeight ) { - return $( window ).height() + "px"; - } else { - return scrollHeight + "px"; - } - // handle "good" browsers - } else { - return $( document ).height() + "px"; - } - }, - - width: function() { - var scrollWidth, - offsetWidth; - // handle IE - if ( $.ui.ie ) { - scrollWidth = Math.max( - document.documentElement.scrollWidth, - document.body.scrollWidth - ); - offsetWidth = Math.max( - document.documentElement.offsetWidth, - document.body.offsetWidth - ); - - if ( scrollWidth < offsetWidth ) { - return $( window ).width() + "px"; - } else { - return scrollWidth + "px"; - } - // handle "good" browsers - } else { - return $( document ).width() + "px"; - } - }, - - resize: function() { - /* If the dialog is draggable and the user drags it past the - * right edge of the window, the document becomes wider so we - * need to stretch the overlay. If the user then drags the - * dialog back to the left, the document will become narrower, - * so we need to shrink the overlay to the appropriate size. - * This is handled by shrinking the overlay before setting it - * to the full document size. - */ - var $overlays = $( [] ); - $.each( $.ui.dialog.overlay.instances, function() { - $overlays = $overlays.add( this ); - }); - - $overlays.css({ - width: 0, - height: 0 - }).css({ - width: $.ui.dialog.overlay.width(), - height: $.ui.dialog.overlay.height() - }); + $el.remove(); } }); diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js index 5d91a3d948..1f3c8d52cc 100644 --- a/ui/jquery.ui.draggable.js +++ b/ui/jquery.ui.draggable.js @@ -15,6 +15,7 @@ */ (function( $, undefined ) { +/*jshint onevar: false, curly: false, eqeqeq: false, laxbreak: true, shadow: true, funcscope: true */ $.widget("ui.draggable", $.ui.mouse, { version: "@VERSION", widgetEventPrefix: "drag", @@ -73,7 +74,7 @@ $.widget("ui.draggable", $.ui.mouse, { this.handle = this._getHandle(event); if (!this.handle) return false; - + $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() { $('
    ') .css({ @@ -157,12 +158,12 @@ $.widget("ui.draggable", $.ui.mouse, { if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, event); - + this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position - + //If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003) if ( $.ui.ddmanager ) $.ui.ddmanager.dragStart(this, event); - + return true; }, @@ -201,7 +202,7 @@ $.widget("ui.draggable", $.ui.mouse, { dropped = this.dropped; this.dropped = false; } - + //if the original element is no longer in the DOM don't bother to continue (see #8269) var element = this.element[0], elementInDom = false; while ( element && (element = element.parentNode) ) { @@ -227,29 +228,29 @@ $.widget("ui.draggable", $.ui.mouse, { return false; }, - + _mouseUp: function(event) { //Remove frame helpers - $("div.ui-draggable-iframeFix").each(function() { - this.parentNode.removeChild(this); + $("div.ui-draggable-iframeFix").each(function() { + this.parentNode.removeChild(this); }); - + //If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003) if( $.ui.ddmanager ) $.ui.ddmanager.dragStop(this, event); - + return $.ui.mouse.prototype._mouseUp.call(this, event); }, - + cancel: function() { - + if(this.helper.is(".ui-draggable-dragging")) { this._mouseUp({}); } else { this._clear(); } - + return this; - + }, _getHandle: function(event) { @@ -372,7 +373,6 @@ $.widget("ui.draggable", $.ui.mouse, { if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor != Array) { var c = $(o.containment); var ce = c[0]; if(!ce) return; - var co = c.offset(); var over = ($(ce).css("overflow") != 'hidden'); this.containment = [ @@ -393,7 +393,7 @@ $.widget("ui.draggable", $.ui.mouse, { if(!pos) pos = this.position; var mod = d == "absolute" ? 1 : -1; - var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); + var scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); return { top: ( @@ -446,10 +446,10 @@ $.widget("ui.draggable", $.ui.mouse, { if(o.grid) { //Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950) var top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY; - pageY = containment ? (!(top - this.offset.click.top < containment[1] || top - this.offset.click.top > containment[3]) ? top : (!(top - this.offset.click.top < containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; + pageY = containment ? ((top - this.offset.click.top >= containment[1] || top - this.offset.click.top > containment[3]) ? top : ((top - this.offset.click.top >= containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; var left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX; - pageX = containment ? (!(left - this.offset.click.left < containment[0] || left - this.offset.click.left > containment[2]) ? left : (!(left - this.offset.click.left < containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; + pageX = containment ? ((left - this.offset.click.left >= containment[0] || left - this.offset.click.left > containment[2]) ? left : ((left - this.offset.click.left >= containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; } } @@ -492,7 +492,7 @@ $.widget("ui.draggable", $.ui.mouse, { plugins: {}, - _uiHash: function(event) { + _uiHash: function() { return { helper: this.helper, position: this.position, @@ -506,11 +506,11 @@ $.widget("ui.draggable", $.ui.mouse, { $.ui.plugin.add("draggable", "connectToSortable", { start: function(event, ui) { - var inst = $(this).data("draggable"), o = inst.options, + var inst = $(this).data("ui-draggable"), o = inst.options, uiSortable = $.extend({}, ui, { item: inst.element }); inst.sortables = []; $(o.connectToSortable).each(function() { - var sortable = $.data(this, 'sortable'); + var sortable = $.data(this, 'ui-sortable'); if (sortable && !sortable.options.disabled) { inst.sortables.push({ instance: sortable, @@ -525,7 +525,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { stop: function(event, ui) { //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper - var inst = $(this).data("draggable"), + var inst = $(this).data("ui-draggable"), uiSortable = $.extend({}, ui, { item: inst.element }); $.each(inst.sortables, function() { @@ -558,26 +558,17 @@ $.ui.plugin.add("draggable", "connectToSortable", { }, drag: function(event, ui) { - var inst = $(this).data("draggable"), that = this; + var inst = $(this).data("ui-draggable"), that = this; - var checkPos = function(o) { - var dyClick = this.offset.click.top, dxClick = this.offset.click.left; - var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left; - var itemHeight = o.height, itemWidth = o.width; - var itemTop = o.top, itemLeft = o.left; + $.each(inst.sortables, function() { - return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth); - }; - - $.each(inst.sortables, function(i) { - var innermostIntersecting = false; var thisSortable = this; //Copy over some variables to allow calling the sortable's native _intersectsWith this.instance.positionAbs = inst.positionAbs; this.instance.helperProportions = inst.helperProportions; this.instance.offset.click = inst.offset.click; - + if(this.instance._intersectsWith(this.instance.containerCache)) { innermostIntersecting = true; $.each(inst.sortables, function () { @@ -601,7 +592,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { //Now we fake the start of dragging for the sortable instance, //by cloning the list group item, appending it to the sortable and using it as inst.currentItem //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one) - this.instance.currentItem = $(that).clone().removeAttr('id').appendTo(this.instance.element).data("sortable-item", true); + this.instance.currentItem = $(that).clone().removeAttr('id').appendTo(this.instance.element).data("ui-sortable-item", true); this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it this.instance.options.helper = function() { return ui.helper[0]; }; @@ -634,13 +625,13 @@ $.ui.plugin.add("draggable", "connectToSortable", { this.instance.isOver = 0; this.instance.cancelHelperRemoval = true; - + //Prevent reverting on this forced stop this.instance.options.revert = false; - + // The out event needs to be triggered independently this.instance._trigger('out', event, this.instance._uiHash(this.instance)); - + this.instance._mouseStop(event, true); this.instance.options.helper = this.instance.options._helper; @@ -652,7 +643,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { inst.dropped = false; //draggable revert needs that } - }; + } }); @@ -660,37 +651,37 @@ $.ui.plugin.add("draggable", "connectToSortable", { }); $.ui.plugin.add("draggable", "cursor", { - start: function(event, ui) { - var t = $('body'), o = $(this).data('draggable').options; + start: function() { + var t = $('body'), o = $(this).data('ui-draggable').options; if (t.css("cursor")) o._cursor = t.css("cursor"); t.css("cursor", o.cursor); }, - stop: function(event, ui) { - var o = $(this).data('draggable').options; + stop: function() { + var o = $(this).data('ui-draggable').options; if (o._cursor) $('body').css("cursor", o._cursor); } }); $.ui.plugin.add("draggable", "opacity", { start: function(event, ui) { - var t = $(ui.helper), o = $(this).data('draggable').options; + var t = $(ui.helper), o = $(this).data('ui-draggable').options; if(t.css("opacity")) o._opacity = t.css("opacity"); t.css('opacity', o.opacity); }, stop: function(event, ui) { - var o = $(this).data('draggable').options; + var o = $(this).data('ui-draggable').options; if(o._opacity) $(ui.helper).css('opacity', o._opacity); } }); $.ui.plugin.add("draggable", "scroll", { - start: function(event, ui) { - var i = $(this).data("draggable"); + start: function() { + var i = $(this).data("ui-draggable"); if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset(); }, - drag: function(event, ui) { + drag: function( event ) { - var i = $(this).data("draggable"), o = i.options, scrolled = false; + var i = $(this).data("ui-draggable"), o = i.options, scrolled = false; if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') { @@ -733,12 +724,12 @@ $.ui.plugin.add("draggable", "scroll", { }); $.ui.plugin.add("draggable", "snap", { - start: function(event, ui) { + start: function() { - var i = $(this).data("draggable"), o = i.options; + var i = $(this).data("ui-draggable"), o = i.options; i.snapElements = []; - $(o.snap.constructor != String ? ( o.snap.items || ':data(draggable)' ) : o.snap).each(function() { + $(o.snap.constructor != String ? ( o.snap.items || ':data(ui-draggable)' ) : o.snap).each(function() { var $t = $(this); var $o = $t.offset(); if(this != i.element[0]) i.snapElements.push({ item: this, @@ -750,7 +741,7 @@ $.ui.plugin.add("draggable", "snap", { }, drag: function(event, ui) { - var inst = $(this).data("draggable"), o = inst.options; + var inst = $(this).data("ui-draggable"), o = inst.options; var d = o.snapTolerance; var x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width, @@ -796,22 +787,22 @@ $.ui.plugin.add("draggable", "snap", { (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item }))); inst.snapElements[i].snapping = (ts || bs || ls || rs || first); - }; + } } }); $.ui.plugin.add("draggable", "stack", { - start: function(event, ui) { + start: function() { - var o = $(this).data("draggable").options; + var o = $(this).data("ui-draggable").options; var group = $.makeArray($(o.stack)).sort(function(a,b) { return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0); }); if (!group.length) { return; } - - var min = parseInt(group[0].style.zIndex) || 0; + + var min = parseInt(group[0].style.zIndex, 10) || 0; $(group).each(function(i) { this.style.zIndex = min + i; }); @@ -823,12 +814,12 @@ $.ui.plugin.add("draggable", "stack", { $.ui.plugin.add("draggable", "zIndex", { start: function(event, ui) { - var t = $(ui.helper), o = $(this).data("draggable").options; + var t = $(ui.helper), o = $(this).data("ui-draggable").options; if(t.css("zIndex")) o._zIndex = t.css("zIndex"); t.css('zIndex', o.zIndex); }, stop: function(event, ui) { - var o = $(this).data("draggable").options; + var o = $(this).data("ui-draggable").options; if(o._zIndex) $(ui.helper).css('zIndex', o._zIndex); } }); diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js index 93e74d2114..f27d56b85d 100644 --- a/ui/jquery.ui.droppable.js +++ b/ui/jquery.ui.droppable.js @@ -16,6 +16,7 @@ */ (function( $, undefined ) { +/*jshint onevar: false, curly: false, eqeqeq: false, laxbreak: true */ $.widget("ui.droppable", { version: "@VERSION", widgetEventPrefix: "drop", @@ -109,8 +110,8 @@ $.widget("ui.droppable", { if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element var childrenIntersection = false; - this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() { - var inst = $.data(this, 'droppable'); + this.element.find(":data(ui-droppable)").not(".ui-draggable-dragging").each(function() { + var inst = $.data(this, 'ui-droppable'); if( inst.options.greedy && !inst.options.disabled @@ -156,33 +157,28 @@ $.ui.intersect = function(draggable, droppable, toleranceMode) { case 'fit': return (l <= x1 && x2 <= r && t <= y1 && y2 <= b); - break; case 'intersect': return (l < x1 + (draggable.helperProportions.width / 2) // Right Half && x2 - (draggable.helperProportions.width / 2) < r // Left Half && t < y1 + (draggable.helperProportions.height / 2) // Bottom Half && y2 - (draggable.helperProportions.height / 2) < b ); // Top Half - break; case 'pointer': var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left), draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top), isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width); return isOver; - break; case 'touch': return ( - (y1 >= t && y1 <= b) || // Top edge touching - (y2 >= t && y2 <= b) || // Bottom edge touching - (y1 < t && y2 > b) // Surrounded vertically - ) && ( - (x1 >= l && x1 <= r) || // Left edge touching - (x2 >= l && x2 <= r) || // Right edge touching - (x1 < l && x2 > r) // Surrounded horizontally - ); - break; + (y1 >= t && y1 <= b) || // Top edge touching + (y2 >= t && y2 <= b) || // Bottom edge touching + (y1 < t && y2 > b) // Surrounded vertically + ) && ( + (x1 >= l && x1 <= r) || // Left edge touching + (x2 >= l && x2 <= r) || // Right edge touching + (x1 < l && x2 > r) // Surrounded horizontally + ); default: return false; - break; } }; @@ -197,13 +193,19 @@ $.ui.ddmanager = { var m = $.ui.ddmanager.droppables[t.options.scope] || []; var type = event ? event.type : null; // workaround for #2317 - var list = (t.currentItem || t.element).find(":data(droppable)").andSelf(); + var list = (t.currentItem || t.element).find(":data(ui-droppable)").andSelf(); droppablesLoop: for (var i = 0; i < m.length; i++) { if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) continue; //No disabled and non-accepted - for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item - m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue + // Filter out elements in the current dragged item + for (var j=0; j < list.length; j++) { + if(list[j] == m[i].element[0]) { + m[i].proportions.height = 0; + continue droppablesLoop; + } + } + m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables @@ -248,27 +250,27 @@ $.ui.ddmanager = { if(this.options.disabled || this.greedyChild || !this.visible) return; var intersects = $.ui.intersect(draggable, this, this.options.tolerance); - var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null); + var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover === 0 ? 'isover' : null); if(!c) return; var parentInstance; if (this.options.greedy) { // find droppable parents with same scope var scope = this.options.scope; - var parent = this.element.parents(':data(droppable)').filter(function () { - return $.data(this, 'droppable').options.scope === scope; + var parent = this.element.parents(':data(ui-droppable)').filter(function () { + return $.data(this, 'ui-droppable').options.scope === scope; }); if (parent.length) { - parentInstance = $.data(parent[0], 'droppable'); + parentInstance = $.data(parent[0], 'ui-droppable'); parentInstance.greedyChild = (c == 'isover' ? 1 : 0); } } // we just moved into a greedy child if (parentInstance && c == 'isover') { - parentInstance['isover'] = 0; - parentInstance['isout'] = 1; + parentInstance.isover = 0; + parentInstance.isout = 1; parentInstance._out.call(parentInstance, event); } @@ -277,8 +279,8 @@ $.ui.ddmanager = { // we just moved out of a greedy child if (parentInstance && c == 'isout') { - parentInstance['isout'] = 0; - parentInstance['isover'] = 1; + parentInstance.isout = 0; + parentInstance.isover = 1; parentInstance._over.call(parentInstance, event); } }); diff --git a/ui/jquery.ui.effect-highlight.js b/ui/jquery.ui.effect-highlight.js index 0b0dbd9888..99c41de2f3 100644 --- a/ui/jquery.ui.effect-highlight.js +++ b/ui/jquery.ui.effect-highlight.js @@ -26,7 +26,7 @@ $.effects.effect.highlight = function( o, done ) { } $.effects.save( elem, props ); - + elem .show() .css({ diff --git a/ui/jquery.ui.effect-scale.js b/ui/jquery.ui.effect-scale.js index 933530a673..7fa04bed66 100644 --- a/ui/jquery.ui.effect-scale.js +++ b/ui/jquery.ui.effect-scale.js @@ -102,8 +102,9 @@ $.effects.effect.scale = function( o, done ) { $.effects.effect.size = function( o, done ) { // Create element - var el = $( this ), - props = [ "position", "top", "bottom", "left", "right", "width", "height", "overflow", "opacity" ], + var original, baseline, factor, + el = $( this ), + props0 = [ "position", "top", "bottom", "left", "right", "width", "height", "overflow", "opacity" ], // Always restore props1 = [ "position", "top", "bottom", "left", "right", "overflow", "opacity" ], @@ -119,8 +120,12 @@ $.effects.effect.size = function( o, done ) { restore = o.restore || mode !== "effect", scale = o.scale || "both", origin = o.origin || [ "middle", "center" ], - original, baseline, factor, - position = el.css( "position" ); + position = el.css( "position" ), + props = restore ? props0 : props1, + zero = { + height: 0, + width: 0 + }; if ( mode === "show" ) { el.show(); @@ -132,8 +137,13 @@ $.effects.effect.size = function( o, done ) { outerWidth: el.outerWidth() }; - el.from = o.from || original; - el.to = o.to || original; + if ( o.mode === "toggle" && mode === "show" ) { + el.from = o.to || zero; + el.to = o.from || original; + } else { + el.from = o.from || ( mode === "show" ? zero : original ); + el.to = o.to || ( mode === "hide" ? zero : original ); + } // Set scaling factor factor = { @@ -170,13 +180,13 @@ $.effects.effect.size = function( o, done ) { // Vertical props scaling if ( factor.from.y !== factor.to.y ) { - props = props.concat( cProps ); + props = props.concat( cProps ).concat( props2 ); el.from = $.effects.setTransition( el, cProps, factor.from.y, el.from ); el.to = $.effects.setTransition( el, cProps, factor.to.y, el.to ); } } - $.effects.save( el, restore ? props : props1 ); + $.effects.save( el, props ); el.show(); $.effects.createWrapper( el ); el.css( "overflow", "hidden" ).css( el.from ); @@ -197,7 +207,7 @@ $.effects.effect.size = function( o, done ) { // Add margins/font-size vProps = vProps.concat([ "marginTop", "marginBottom" ]).concat(cProps); hProps = hProps.concat([ "marginLeft", "marginRight" ]); - props2 = props.concat(vProps).concat(hProps); + props2 = props0.concat(vProps).concat(hProps); el.find( "*[width]" ).each( function(){ var child = $( this ), @@ -254,7 +264,7 @@ $.effects.effect.size = function( o, done ) { if( mode === "hide" ) { el.hide(); } - $.effects.restore( el, restore ? props : props1 ); + $.effects.restore( el, props ); if ( !restore ) { // we need to calculate our new positioning based on the scaling diff --git a/ui/jquery.ui.effect.js b/ui/jquery.ui.effect.js index d5d3067838..fee3359bfe 100644 --- a/ui/jquery.ui.effect.js +++ b/ui/jquery.ui.effect.js @@ -10,9 +10,7 @@ */ ;(jQuery.effects || (function($, undefined) { -var backCompat = $.uiBackCompat !== false, - // prefix used for storing data on .data() - dataSpace = "ui-effects-"; +var dataSpace = "ui-effects-"; $.effects = { effect: {} @@ -245,8 +243,7 @@ color.fn = jQuery.extend( color.prototype, { var inst = this, type = jQuery.type( red ), - rgba = this._rgba = [], - source; + rgba = this._rgba = []; // more than 1 argument specified - assume ( red, green, blue, alpha ) if ( green !== undefined ) { @@ -427,7 +424,7 @@ color.fn = jQuery.extend( color.prototype, { rgba.push( ~~( alpha * 255 ) ); } - return "#" + jQuery.map( rgba, function( v, i ) { + return "#" + jQuery.map( rgba, function( v ) { // default to 0 when nulls exist v = ( v || 0 ).toString( 16 ); @@ -501,8 +498,7 @@ spaces.hsla.from = function ( hsla ) { l = hsla[ 2 ], a = hsla[ 3 ], q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s, - p = 2 * l - q, - r, g, b; + p = 2 * l - q; return [ Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ), @@ -619,7 +615,7 @@ each( stepHooks, function( i, hook ) { } try { elem.style[ hook ] = value; - } catch( value ) { + } catch( error ) { // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit' } } @@ -704,33 +700,31 @@ $.each([ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopS }; }); -function getElementStyles() { - var style = this.ownerDocument.defaultView ? - this.ownerDocument.defaultView.getComputedStyle( this, null ) : - this.currentStyle, - newStyle = {}, - key, - camelCase, - len; +function getElementStyles( elem ) { + var key, len, + style = elem.ownerDocument.defaultView ? + elem.ownerDocument.defaultView.getComputedStyle( elem, null ) : + elem.currentStyle, + styles = {}; - // webkit enumerates style porperties if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) { len = style.length; while ( len-- ) { key = style[ len ]; if ( typeof style[ key ] === "string" ) { - newStyle[ $.camelCase( key ) ] = style[ key ]; + styles[ $.camelCase( key ) ] = style[ key ]; } } + // support: Opera, IE <9 } else { for ( key in style ) { if ( typeof style[ key ] === "string" ) { - newStyle[ key ] = style[ key ]; + styles[ key ] = style[ key ]; } } } - return newStyle; + return styles; } @@ -766,7 +760,7 @@ $.effects.animateClass = function( value, duration, easing, callback ) { var el = $( this ); return { el: el, - start: getElementStyles.call( this ) + start: getElementStyles( this ) }; }); @@ -782,7 +776,7 @@ $.effects.animateClass = function( value, duration, easing, callback ) { // map all animated objects again - calculate new styles and diff allAnimations = allAnimations.map(function() { - this.end = getElementStyles.call( this.el[ 0 ] ); + this.end = getElementStyles( this.el[ 0 ] ); this.diff = styleDifference( this.start, this.end ); return this; }); @@ -1045,7 +1039,7 @@ $.extend( $.effects, { // return an effect options object for the given parameters: function _normalizeArguments( effect, options, speed, callback ) { - // allow passing all optinos as the first parameter + // allow passing all options as the first parameter if ( $.isPlainObject( effect ) ) { options = effect; effect = effect.effect; @@ -1054,8 +1048,8 @@ function _normalizeArguments( effect, options, speed, callback ) { // convert to an object effect = { effect: effect }; - // catch (effect) - if ( options === undefined ) { + // catch (effect, null, ...) + if ( options == null ) { options = {}; } @@ -1102,28 +1096,17 @@ function standardSpeed( speed ) { } // invalid strings - treat as "normal" speed - if ( typeof speed === "string" && !$.effects.effect[ speed ] ) { - // TODO: remove in 2.0 (#7115) - if ( backCompat && $.effects[ speed ] ) { - return false; - } - return true; - } - - return false; + return typeof speed === "string" && !$.effects.effect[ speed ]; } $.fn.extend({ - effect: function( effect, options, speed, callback ) { + effect: function( /* effect, options, speed, callback */ ) { var args = _normalizeArguments.apply( this, arguments ), mode = args.mode, queue = args.queue, - effectMethod = $.effects.effect[ args.effect ], + effectMethod = $.effects.effect[ args.effect ]; - // DEPRECATED: remove in 2.0 (#7115) - oldEffectMethod = !effectMethod && backCompat && $.effects[ args.effect ]; - - if ( $.fx.off || !( effectMethod || oldEffectMethod ) ) { + if ( $.fx.off || !effectMethod ) { // delegate to the original method (e.g., .show()) if possible if ( mode ) { return this[ mode ]( args.duration, args.complete ); @@ -1159,18 +1142,7 @@ $.fn.extend({ } } - // TODO: remove this check in 2.0, effectMethod will always be true - if ( effectMethod ) { - return queue === false ? this.each( run ) : this.queue( queue || "fx", run ); - } else { - // DEPRECATED: remove in 2.0 (#7115) - return oldEffectMethod.call(this, { - options: args, - duration: args.duration, - callback: args.complete, - mode: args.mode - }); - } + return queue === false ? this.each( run ) : this.queue( queue || "fx", run ); }, _show: $.fn.show, diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index 5d401da535..45c1ec2e4b 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -277,21 +277,35 @@ $.widget( "ui.menu", { }, refresh: function() { - // Initialize nested menus var menus, icon = this.options.icons.submenu, - submenus = this.element.find( this.options.menus + ":not(.ui-menu)" ) - .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" ) - .hide() - .attr({ - role: this.options.role, - "aria-hidden": "true", - "aria-expanded": "false" - }); + submenus = this.element.find( this.options.menus ); + + // Initialize nested menus + submenus.filter( ":not(.ui-menu)" ) + .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" ) + .hide() + .attr({ + role: this.options.role, + "aria-hidden": "true", + "aria-expanded": "false" + }) + .each(function() { + var menu = $( this ), + item = menu.prev( "a" ), + submenuCarat = $( "" ) + .addClass( "ui-menu-icon ui-icon " + icon ) + .data( "ui-menu-submenu-carat", true ); + + item + .attr( "aria-haspopup", "true" ) + .prepend( submenuCarat ); + menu.attr( "aria-labelledby", item.attr( "id" ) ); + }); - // Don't refresh list items that are already adapted menus = submenus.add( this.element ); + // Don't refresh list items that are already adapted menus.children( ":not(.ui-menu-item):has(a)" ) .addClass( "ui-menu-item" ) .attr( "role", "presentation" ) @@ -315,19 +329,6 @@ $.widget( "ui.menu", { // Add aria-disabled attribute to any disabled menu item menus.children( ".ui-state-disabled" ).attr( "aria-disabled", "true" ); - submenus.each(function() { - var menu = $( this ), - item = menu.prev( "a" ), - submenuCarat = $( "" ) - .addClass( "ui-menu-icon ui-icon " + icon ) - .data( "ui-menu-submenu-carat", true ); - - item - .attr( "aria-haspopup", "true" ) - .prepend( submenuCarat ); - menu.attr( "aria-labelledby", item.attr( "id" ) ); - }); - // If the active item has been removed, blur the menu if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) { this.blur(); diff --git a/ui/jquery.ui.mouse.js b/ui/jquery.ui.mouse.js index f5069d00c4..6abd5ceaf6 100644 --- a/ui/jquery.ui.mouse.js +++ b/ui/jquery.ui.mouse.js @@ -14,7 +14,7 @@ (function( $, undefined ) { var mouseHandled = false; -$( document ).mouseup( function( e ) { +$( document ).mouseup( function() { mouseHandled = false; }); @@ -104,14 +104,14 @@ $.widget("ui.mouse", { .bind('mouseup.'+this.widgetName, this._mouseUpDelegate); event.preventDefault(); - + mouseHandled = true; return true; }, _mouseMove: function(event) { // IE mouseup check - mouseup happened when mouse was out of window - if ($.ui.ie && !(document.documentMode >= 9) && !event.button) { + if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) { return this._mouseUp(event); } @@ -155,15 +155,15 @@ $.widget("ui.mouse", { ); }, - _mouseDelayMet: function(event) { + _mouseDelayMet: function(/* event */) { return this.mouseDelayMet; }, // These are placeholder methods, to be overriden by extending plugin - _mouseStart: function(event) {}, - _mouseDrag: function(event) {}, - _mouseStop: function(event) {}, - _mouseCapture: function(event) { return true; } + _mouseStart: function(/* event */) {}, + _mouseDrag: function(/* event */) {}, + _mouseStop: function(/* event */) {}, + _mouseCapture: function(/* event */) { return true; } }); })(jQuery); diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index 5b595a8c0d..a5dc318343 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -230,10 +230,6 @@ $.fn.position = function( options ) { } }); - if ( $.fn.bgiframe ) { - elem.bgiframe(); - } - if ( options.using ) { // adds feedback as second argument to using callback, if present using = function( props ) { @@ -478,40 +474,4 @@ $.ui.position = { testElementParent.removeChild( testElement ); })(); -// DEPRECATED -if ( $.uiBackCompat !== false ) { - // offset option - (function( $ ) { - var _position = $.fn.position; - $.fn.position = function( options ) { - if ( !options || !options.offset ) { - return _position.call( this, options ); - } - var offset = options.offset.split( " " ), - at = options.at.split( " " ); - if ( offset.length === 1 ) { - offset[ 1 ] = offset[ 0 ]; - } - if ( /^\d/.test( offset[ 0 ] ) ) { - offset[ 0 ] = "+" + offset[ 0 ]; - } - if ( /^\d/.test( offset[ 1 ] ) ) { - offset[ 1 ] = "+" + offset[ 1 ]; - } - if ( at.length === 1 ) { - if ( /left|center|right/.test( at[ 0 ] ) ) { - at[ 1 ] = "center"; - } else { - at[ 1 ] = at[ 0 ]; - at[ 0 ] = "center"; - } - } - return _position.call( this, $.extend( options, { - at: at[ 0 ] + offset[ 0 ] + " " + at[ 1 ] + offset[ 1 ], - offset: undefined - } ) ); - }; - }( jQuery ) ); -} - }( jQuery ) ); diff --git a/ui/jquery.ui.progressbar.js b/ui/jquery.ui.progressbar.js index cb561ebc6b..5a7fd87d37 100644 --- a/ui/jquery.ui.progressbar.js +++ b/ui/jquery.ui.progressbar.js @@ -24,19 +24,22 @@ $.widget( "ui.progressbar", { min: 0, _create: function() { + // Constrain initial value + this.options.value = this._constrainedValue(); + this.element .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) .attr({ role: "progressbar", "aria-valuemin": this.min, "aria-valuemax": this.options.max, - "aria-valuenow": this._value() + "aria-valuenow": this.options.value }); this.valueDiv = $( "
    " ) .appendTo( this.element ); - this.oldValue = this._value(); + this.oldValue = this.options.value; this._refreshValue(); }, @@ -53,52 +56,82 @@ $.widget( "ui.progressbar", { value: function( newValue ) { if ( newValue === undefined ) { - return this._value(); + return this.options.value; } - this._setOption( "value", newValue ); + this._setOption( "value", this._constrainedValue( newValue ) ); return this; }, - _setOption: function( key, value ) { - if ( key === "value" ) { - this.options.value = value; - this._refreshValue(); - if ( this._value() === this.options.max ) { - this._trigger( "complete" ); - } + _constrainedValue: function( newValue ) { + var val; + if ( newValue === undefined ) { + val = this.options.value; + } else { + val = newValue; } - this._super( key, value ); - }, - - _value: function() { - var val = this.options.value; - // normalize invalid value + // sanitize value if ( typeof val !== "number" ) { val = 0; } return Math.min( this.options.max, Math.max( this.min, val ) ); }, + _setOptions: function( options ) { + var key, val; + + for ( key in options ) { + if ( key === "value" ) { + // Store value to update last in case max is being updated at the same time + val = options[ key ]; + } else { + this._setOption( key, options[ key ] ); + } + } + + if ( val !== undefined ) { + this._setOption( "value", val ); + } + }, + + _setOption: function( key, value ) { + if ( key === "max" ) { + // Don't allow a max less than min + this.options.max = Math.max( this.min, value ); + this.options.value = this._constrainedValue(); + } + if ( key === "value" ) { + this.options.value = this._constrainedValue( value ); + } + else { + this._super( key, value ); + } + + this._refreshValue(); + }, + _percentage: function() { - return 100 * this._value() / this.options.max; + return 100 * this.options.value / this.options.max; }, _refreshValue: function() { - var value = this.value(), - percentage = this._percentage(); + var percentage = this._percentage(); - if ( this.oldValue !== value ) { - this.oldValue = value; + if ( this.oldValue !== this.options.value ) { + this.oldValue = this.options.value; this._trigger( "change" ); } + if ( this.options.value === this.options.max ) { + this._trigger( "complete" ); + } this.valueDiv - .toggle( value > this.min ) - .toggleClass( "ui-corner-right", value === this.options.max ) + .toggle( this.options.value > this.min ) + .toggleClass( "ui-corner-right", this.options.value === this.options.max ) .width( percentage.toFixed(0) + "%" ); - this.element.attr( "aria-valuenow", value ); + this.element.attr( "aria-valuemax", this.options.max ); + this.element.attr( "aria-valuenow", this.options.value ); } }); diff --git a/ui/jquery.ui.resizable.js b/ui/jquery.ui.resizable.js index cc82b8b927..fba9216e13 100644 --- a/ui/jquery.ui.resizable.js +++ b/ui/jquery.ui.resizable.js @@ -15,6 +15,16 @@ */ (function( $, undefined ) { +/*jshint onevar: false, curly: false, eqeqeq: false, funcscope: true, loopfunc: true */ + +function num(v) { + return parseInt(v, 10) || 0; +} + +function isNumber(value) { + return !isNaN(parseInt(value, 10)); +} + $.widget("ui.resizable", $.ui.mouse, { version: "@VERSION", widgetEventPrefix: "resize", @@ -65,7 +75,7 @@ $.widget("ui.resizable", $.ui.mouse, { //Overwrite the original this.element this.element = this.element.parent().data( - "resizable", this.element.data('resizable') + "ui-resizable", this.element.data('ui-resizable') ); this.elementIsWrapper = true; @@ -106,7 +116,7 @@ $.widget("ui.resizable", $.ui.mouse, { //TODO : What's going on here? if ('se' == handle) { axis.addClass('ui-icon ui-icon-gripsmall-diagonal-se'); - }; + } //Insert into internal handles object and append to element this.handles[handle] = '.ui-resizable-'+handle; @@ -204,15 +214,14 @@ $.widget("ui.resizable", $.ui.mouse, { if (this.elementIsWrapper) { _destroy(this.element); var wrapper = this.element; - wrapper.after( - this.originalElement.css({ - position: wrapper.css('position'), - width: wrapper.outerWidth(), - height: wrapper.outerHeight(), - top: wrapper.css('top'), - left: wrapper.css('left') - }) - ).remove(); + this.originalElement.css({ + position: wrapper.css('position'), + width: wrapper.outerWidth(), + height: wrapper.outerHeight(), + top: wrapper.css('top'), + left: wrapper.css('left') + }).insertAfter( wrapper ); + wrapper.remove(); } this.originalElement.css('resize', this.originalResizeStyle); @@ -222,14 +231,15 @@ $.widget("ui.resizable", $.ui.mouse, { }, _mouseCapture: function(event) { - var handle = false; + var capture = false; for (var i in this.handles) { - if ($(this.handles[i])[0] == event.target) { - handle = true; + var handle = $(this.handles[i])[0]; + if (handle == event.target || $.contains(handle, event.target)) { + capture = true; } } - return !this.options.disabled && handle; + return !this.options.disabled && capture; }, _mouseStart: function(event) { @@ -276,8 +286,8 @@ $.widget("ui.resizable", $.ui.mouse, { _mouseDrag: function(event) { //Increase performance, avoid regex - var el = this.helper, o = this.options, props = {}, - that = this, smp = this.originalMousePosition, a = this.axis; + var el = this.helper, + smp = this.originalMousePosition, a = this.axis; var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0; var trigger = this._change[a]; @@ -373,7 +383,6 @@ $.widget("ui.resizable", $.ui.mouse, { }, _updateCache: function(data) { - var o = this.options; this.offset = this.helper.offset(); if (isNumber(data.left)) this.position.left = data.left; if (isNumber(data.top)) this.position.top = data.top; @@ -381,9 +390,9 @@ $.widget("ui.resizable", $.ui.mouse, { if (isNumber(data.width)) this.size.width = data.width; }, - _updateRatio: function(data, event) { + _updateRatio: function( data ) { - var o = this.options, cpos = this.position, csize = this.size, a = this.axis; + var cpos = this.position, csize = this.size, a = this.axis; if (isNumber(data.height)) data.width = (data.height * this.aspectRatio); else if (isNumber(data.width)) data.height = (data.width / this.aspectRatio); @@ -400,11 +409,11 @@ $.widget("ui.resizable", $.ui.mouse, { return data; }, - _respectSize: function(data, event) { + _respectSize: function( data ) { - var el = this.helper, o = this._vBoundaries, pRatio = this._aspectRatio || event.shiftKey, a = this.axis, - ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height), - isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height); + var o = this._vBoundaries, a = this.axis, + ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height), + isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height); if (isminw) data.width = o.minWidth; if (isminh) data.height = o.minHeight; @@ -429,7 +438,6 @@ $.widget("ui.resizable", $.ui.mouse, { _proportionallyResize: function() { - var o = this.options; if (!this._proportionallyResizeElements.length) return; var element = this.helper || this.element; @@ -452,7 +460,7 @@ $.widget("ui.resizable", $.ui.mouse, { width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0 }); - }; + } }, @@ -465,16 +473,12 @@ $.widget("ui.resizable", $.ui.mouse, { this.helper = this.helper || $('
    '); - // fix ie6 offset TODO: This seems broken - var ie6offset = ($.ui.ie6 ? 1 : 0), - pxyoffset = ( $.ui.ie6 ? 2 : -1 ); - this.helper.addClass(this._helper).css({ - width: this.element.outerWidth() + pxyoffset, - height: this.element.outerHeight() + pxyoffset, + width: this.element.outerWidth() - 1, + height: this.element.outerHeight() - 1, position: 'absolute', - left: this.elementOffset.left - ie6offset +'px', - top: this.elementOffset.top - ie6offset +'px', + left: this.elementOffset.left +'px', + top: this.elementOffset.top +'px', zIndex: ++o.zIndex //TODO: Don't modify option }); @@ -489,15 +493,15 @@ $.widget("ui.resizable", $.ui.mouse, { }, _change: { - e: function(event, dx, dy) { + e: function(event, dx) { return { width: this.originalSize.width + dx }; }, - w: function(event, dx, dy) { - var o = this.options, cs = this.originalSize, sp = this.originalPosition; + w: function(event, dx) { + var cs = this.originalSize, sp = this.originalPosition; return { left: sp.left + dx, width: cs.width - dx }; }, n: function(event, dx, dy) { - var o = this.options, cs = this.originalSize, sp = this.originalPosition; + var cs = this.originalSize, sp = this.originalPosition; return { top: sp.top + dy, height: cs.height - dy }; }, s: function(event, dx, dy) { @@ -544,13 +548,13 @@ $.widget("ui.resizable", $.ui.mouse, { $.ui.plugin.add("resizable", "alsoResize", { - start: function (event, ui) { - var that = $(this).data("resizable"), o = that.options; + start: function () { + var that = $(this).data("ui-resizable"), o = that.options; var _store = function (exp) { $(exp).each(function() { var el = $(this); - el.data("resizable-alsoresize", { + el.data("ui-resizable-alsoresize", { width: parseInt(el.width(), 10), height: parseInt(el.height(), 10), left: parseInt(el.css('left'), 10), top: parseInt(el.css('top'), 10) }); @@ -566,7 +570,7 @@ $.ui.plugin.add("resizable", "alsoResize", { }, resize: function (event, ui) { - var that = $(this).data("resizable"), o = that.options, os = that.originalSize, op = that.originalPosition; + var that = $(this).data("ui-resizable"), o = that.options, os = that.originalSize, op = that.originalPosition; var delta = { height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0, @@ -575,7 +579,7 @@ $.ui.plugin.add("resizable", "alsoResize", { _alsoResize = function (exp, c) { $(exp).each(function() { - var el = $(this), start = $(this).data("resizable-alsoresize"), style = {}, + var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {}, css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width', 'height'] : ['width', 'height', 'top', 'left']; $.each(css, function (i, prop) { @@ -595,15 +599,15 @@ $.ui.plugin.add("resizable", "alsoResize", { } }, - stop: function (event, ui) { + stop: function () { $(this).removeData("resizable-alsoresize"); } }); $.ui.plugin.add("resizable", "animate", { - stop: function(event, ui) { - var that = $(this).data("resizable"), o = that.options; + stop: function( event ) { + var that = $(this).data("ui-resizable"), o = that.options; var pr = that._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName), soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height, @@ -641,8 +645,8 @@ $.ui.plugin.add("resizable", "animate", { $.ui.plugin.add("resizable", "containment", { - start: function(event, ui) { - var that = $(this).data("resizable"), o = that.options, el = that.element; + start: function() { + var that = $(this).data("ui-resizable"), o = that.options, el = that.element; var oc = o.containment, ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc; if (!ce) return; @@ -676,10 +680,10 @@ $.ui.plugin.add("resizable", "containment", { } }, - resize: function(event, ui) { - var that = $(this).data("resizable"), o = that.options, - ps = that.containerSize, co = that.containerOffset, cs = that.size, cp = that.position, - pRatio = that._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = that.containerElement; + resize: function( event ) { + var that = $(this).data("ui-resizable"), o = that.options, + co = that.containerOffset, cp = that.position, + pRatio = that._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = that.containerElement; if (ce[0] != document && (/static/).test(ce.css('position'))) cop = co; @@ -717,8 +721,8 @@ $.ui.plugin.add("resizable", "containment", { } }, - stop: function(event, ui){ - var that = $(this).data("resizable"), o = that.options, cp = that.position, + stop: function(){ + var that = $(this).data("ui-resizable"), o = that.options, co = that.containerOffset, cop = that.containerPosition, ce = that.containerElement; var helper = $(that.helper), ho = helper.offset(), w = helper.outerWidth() - that.sizeDiff.width, h = helper.outerHeight() - that.sizeDiff.height; @@ -734,13 +738,13 @@ $.ui.plugin.add("resizable", "containment", { $.ui.plugin.add("resizable", "ghost", { - start: function(event, ui) { + start: function() { - var that = $(this).data("resizable"), o = that.options, cs = that.size; + var that = $(this).data("ui-resizable"), o = that.options, cs = that.size; that.ghost = that.originalElement.clone(); that.ghost - .css({ opacity: .25, display: 'block', position: 'relative', height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 }) + .css({ opacity: 0.25, display: 'block', position: 'relative', height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 }) .addClass('ui-resizable-ghost') .addClass(typeof o.ghost == 'string' ? o.ghost : ''); @@ -748,13 +752,13 @@ $.ui.plugin.add("resizable", "ghost", { }, - resize: function(event, ui){ - var that = $(this).data("resizable"), o = that.options; + resize: function(){ + var that = $(this).data("ui-resizable"); if (that.ghost) that.ghost.css({ position: 'relative', height: that.size.height, width: that.size.width }); }, - stop: function(event, ui){ - var that = $(this).data("resizable"), o = that.options; + stop: function() { + var that = $(this).data("ui-resizable"); if (that.ghost && that.helper) that.helper.get(0).removeChild(that.ghost.get(0)); } @@ -762,28 +766,42 @@ $.ui.plugin.add("resizable", "ghost", { $.ui.plugin.add("resizable", "grid", { - resize: function(event, ui) { - var that = $(this).data("resizable"), o = that.options, cs = that.size, os = that.originalSize, op = that.originalPosition, a = that.axis, ratio = o._aspectRatio || event.shiftKey; + resize: function() { + var that = $(this).data("ui-resizable"), o = that.options, cs = that.size, os = that.originalSize, op = that.originalPosition, a = that.axis; o.grid = typeof o.grid == "number" ? [o.grid, o.grid] : o.grid; - var ox = Math.round((cs.width - os.width) / (o.grid[0]||1)) * (o.grid[0]||1), oy = Math.round((cs.height - os.height) / (o.grid[1]||1)) * (o.grid[1]||1); + var gridX = (o.grid[0]||1), gridY = (o.grid[1]||1), + ox = Math.round((cs.width - os.width) / gridX) * gridX, oy = Math.round((cs.height - os.height) / gridY) * gridY, + newWidth = os.width + ox, newHeight = os.height + oy, + isMaxWidth = o.maxWidth && (o.maxWidth < newWidth), isMaxHeight = o.maxHeight && (o.maxHeight < newHeight), + isMinWidth = o.minWidth && (o.minWidth > newWidth), isMinHeight = o.minHeight && (o.minHeight > newHeight); + + if (isMinWidth) { + newWidth = newWidth + gridX; + } + if (isMinHeight) { + newHeight = newHeight + gridY; + } + if (isMaxWidth) { + newWidth = newWidth - gridX; + } + if (isMaxHeight) { + newHeight = newHeight - gridY; + } if (/^(se|s|e)$/.test(a)) { - that.size.width = os.width + ox; - that.size.height = os.height + oy; - } - else if (/^(ne)$/.test(a)) { - that.size.width = os.width + ox; - that.size.height = os.height + oy; + that.size.width = newWidth; + that.size.height = newHeight; + } else if (/^(ne)$/.test(a)) { + that.size.width = newWidth; + that.size.height = newHeight; that.position.top = op.top - oy; - } - else if (/^(sw)$/.test(a)) { - that.size.width = os.width + ox; - that.size.height = os.height + oy; + } else if (/^(sw)$/.test(a)) { + that.size.width = newWidth; + that.size.height = newHeight; that.position.left = op.left - ox; - } - else { - that.size.width = os.width + ox; - that.size.height = os.height + oy; + } else { + that.size.width = newWidth; + that.size.height = newHeight; that.position.top = op.top - oy; that.position.left = op.left - ox; } @@ -791,12 +809,4 @@ $.ui.plugin.add("resizable", "grid", { }); -var num = function(v) { - return parseInt(v, 10) || 0; -}; - -var isNumber = function(value) { - return !isNaN(parseInt(value, 10)); -}; - })(jQuery); diff --git a/ui/jquery.ui.selectable.js b/ui/jquery.ui.selectable.js index 80e32ca7a5..a9b15b20b7 100644 --- a/ui/jquery.ui.selectable.js +++ b/ui/jquery.ui.selectable.js @@ -25,20 +25,20 @@ $.widget("ui.selectable", $.ui.mouse, { tolerance: 'touch' }, _create: function() { - var that = this; + var selectees, + that = this; this.element.addClass("ui-selectable"); this.dragged = false; // cache selectee children based on filter - var selectees; this.refresh = function() { selectees = $(that.options.filter, that.element[0]); selectees.addClass("ui-selectee"); selectees.each(function() { - var $this = $(this); - var pos = $this.offset(); + var $this = $(this), + pos = $this.offset(); $.data(this, "selectable-item", { element: this, $element: $this, @@ -72,14 +72,14 @@ $.widget("ui.selectable", $.ui.mouse, { }, _mouseStart: function(event) { - var that = this; + var that = this, + options = this.options; this.opos = [event.pageX, event.pageY]; - if (this.options.disabled) + if (this.options.disabled) { return; - - var options = this.options; + } this.selectees = $(options.filter, this.element[0]); @@ -114,9 +114,10 @@ $.widget("ui.selectable", $.ui.mouse, { }); $(event.target).parents().andSelf().each(function() { - var selectee = $.data(this, "selectable-item"); + var doSelect, + selectee = $.data(this, "selectable-item"); if (selectee) { - var doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass('ui-selected'); + doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass('ui-selected'); selectee.$element .removeClass(doSelect ? "ui-unselecting" : "ui-selected") .addClass(doSelect ? "ui-selecting" : "ui-unselecting"); @@ -140,28 +141,37 @@ $.widget("ui.selectable", $.ui.mouse, { }, _mouseDrag: function(event) { - var that = this; + this.dragged = true; - if (this.options.disabled) + if (this.options.disabled) { return; + } - var options = this.options; + var tmp, + that = this, + options = this.options, + x1 = this.opos[0], + y1 = this.opos[1], + x2 = event.pageX, + y2 = event.pageY; - var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY; - if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; } - if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; } + if (x1 > x2) { tmp = x2; x2 = x1; x1 = tmp; } + if (y1 > y2) { tmp = y2; y2 = y1; y1 = tmp; } this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1}); this.selectees.each(function() { - var selectee = $.data(this, "selectable-item"); + var selectee = $.data(this, "selectable-item"), + hit = false; + //prevent helper from being selected if appendTo: selectable - if (!selectee || selectee.element == that.element[0]) + if (!selectee || selectee.element === that.element[0]) { return; - var hit = false; - if (options.tolerance == 'touch') { + } + + if (options.tolerance === 'touch') { hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) ); - } else if (options.tolerance == 'fit') { + } else if (options.tolerance === 'fit') { hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2); } @@ -228,8 +238,6 @@ $.widget("ui.selectable", $.ui.mouse, { this.dragged = false; - var options = this.options; - $('.ui-unselecting', this.element[0]).each(function() { var selectee = $.data(this, "selectable-item"); selectee.$element.removeClass('ui-unselecting'); diff --git a/ui/jquery.ui.slider.js b/ui/jquery.ui.slider.js index f24982878d..18f7113d40 100644 --- a/ui/jquery.ui.slider.js +++ b/ui/jquery.ui.slider.js @@ -36,11 +36,10 @@ $.widget( "ui.slider", $.ui.mouse, { }, _create: function() { - var i, + var i, handleCount, o = this.options, existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ), handle = "", - handleCount = ( o.values && o.values.length ) || 1, handles = []; this._keySliding = false; @@ -79,6 +78,8 @@ $.widget( "ui.slider", $.ui.mouse, { ( ( o.range === "min" || o.range === "max" ) ? " ui-slider-range-" + o.range : "" ) ); } + handleCount = ( o.values && o.values.length ) || 1; + for ( i = existingHandles.length; i < handleCount; i++ ) { handles.push( handle ); } @@ -277,7 +278,7 @@ $.widget( "ui.slider", $.ui.mouse, { return true; }, - _mouseStart: function( event ) { + _mouseStart: function() { return true; }, @@ -509,6 +510,12 @@ $.widget( "ui.slider", $.ui.mouse, { } this._animateOff = false; break; + case "min": + case "max": + this._animateOff = true; + this._refreshValue(); + this._animateOff = false; + break; } }, @@ -584,7 +591,7 @@ $.widget( "ui.slider", $.ui.mouse, { _set = {}; if ( this.options.values && this.options.values.length ) { - this.handles.each(function( i, j ) { + this.handles.each(function( i ) { valPercent = ( that.values(i) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100; _set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%"; $( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate ); diff --git a/ui/jquery.ui.sortable.js b/ui/jquery.ui.sortable.js index a2132a9bdc..a98e466321 100644 --- a/ui/jquery.ui.sortable.js +++ b/ui/jquery.ui.sortable.js @@ -15,6 +15,7 @@ */ (function( $, undefined ) { +/*jshint onevar: false, curly: false, eqeqeq: false, laxbreak: true, shadow: true, loopfunc: true */ $.widget("ui.sortable", $.ui.mouse, { version: "@VERSION", widgetEventPrefix: "sort", @@ -62,7 +63,7 @@ $.widget("ui.sortable", $.ui.mouse, { this._mouseInit(); //We're ready to go - this.ready = true + this.ready = true; }, @@ -101,7 +102,9 @@ $.widget("ui.sortable", $.ui.mouse, { this._refreshItems(event); //Find out if the clicked node (or one of its parents) is a actual item in this.items - var currentItem = null, nodes = $(event.target).parents().each(function() { + var currentItem = null; + + $(event.target).parents().each(function() { if($.data(this, that.widgetName + '-item') == that) { currentItem = $(this); return false; @@ -221,7 +224,7 @@ $.widget("ui.sortable", $.ui.mouse, { //Post 'activate' events to possible containers if(!noActivation) { - for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, this._uiHash(this)); } + for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, this._uiHash(this)); } } //Prepare possible droppables @@ -418,7 +421,7 @@ $.widget("ui.sortable", $.ui.mouse, { var str = []; o = o || {}; $(items).each(function() { - var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/)); + var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[\-=_](.+)/)); if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2])); }); @@ -458,7 +461,7 @@ $.widget("ui.sortable", $.ui.mouse, { var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r; - if( this.options.tolerance == "pointer" + if (this.options.tolerance == "pointer" || this.options.forcePointerForContainers || (this.options.tolerance != "pointer" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height']) ) { @@ -507,12 +510,12 @@ $.widget("ui.sortable", $.ui.mouse, { _getDragVerticalDirection: function() { var delta = this.positionAbs.top - this.lastPositionAbs.top; - return delta != 0 && (delta > 0 ? "down" : "up"); + return delta !== 0 && (delta > 0 ? "down" : "up"); }, _getDragHorizontalDirection: function() { var delta = this.positionAbs.left - this.lastPositionAbs.left; - return delta != 0 && (delta > 0 ? "right" : "left"); + return delta !== 0 && (delta > 0 ? "right" : "left"); }, refresh: function(event) { @@ -538,12 +541,12 @@ $.widget("ui.sortable", $.ui.mouse, { for (var i = connectWith.length - 1; i >= 0; i--){ var cur = $(connectWith[i]); for (var j = cur.length - 1; j >= 0; j--){ - var inst = $.data(cur[j], this.widgetName); + var inst = $.data(cur[j], this.widgetFullName); if(inst && inst != this && !inst.options.disabled) { queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), inst]); } - }; - }; + } + } } queries.push([$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), this]); @@ -552,7 +555,7 @@ $.widget("ui.sortable", $.ui.mouse, { queries[i][0].each(function() { items.push(this); }); - }; + } return $(items); @@ -566,7 +569,7 @@ $.widget("ui.sortable", $.ui.mouse, { for (var j=0; j < list.length; j++) { if(list[j] == item.item[0]) return false; - }; + } return true; }); @@ -584,13 +587,13 @@ $.widget("ui.sortable", $.ui.mouse, { for (var i = connectWith.length - 1; i >= 0; i--){ var cur = $(connectWith[i]); for (var j = cur.length - 1; j >= 0; j--){ - var inst = $.data(cur[j], this.widgetName); + var inst = $.data(cur[j], this.widgetFullName); if(inst && inst != this && !inst.options.disabled) { queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]); this.containers.push(inst); } - }; - }; + } + } } for (var i = queries.length - 1; i >= 0; i--) { @@ -608,8 +611,8 @@ $.widget("ui.sortable", $.ui.mouse, { width: 0, height: 0, left: 0, top: 0 }); - }; - }; + } + } }, @@ -637,7 +640,7 @@ $.widget("ui.sortable", $.ui.mouse, { var p = t.offset(); item.left = p.left; item.top = p.top; - }; + } if(this.options.custom && this.options.custom.refreshContainers) { this.options.custom.refreshContainers.call(this); @@ -648,7 +651,7 @@ $.widget("ui.sortable", $.ui.mouse, { this.containers[i].containerCache.top = p.top; this.containers[i].containerCache.width = this.containers[i].element.outerWidth(); this.containers[i].containerCache.height = this.containers[i].element.outerHeight(); - }; + } } return this; @@ -679,8 +682,8 @@ $.widget("ui.sortable", $.ui.mouse, { if(className && !o.forcePlaceholderSize) return; //If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item - if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css('paddingTop')||0, 10) - parseInt(that.currentItem.css('paddingBottom')||0, 10)); }; - if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css('paddingLeft')||0, 10) - parseInt(that.currentItem.css('paddingRight')||0, 10)); }; + if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css('paddingTop')||0, 10) - parseInt(that.currentItem.css('paddingBottom')||0, 10)); } + if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css('paddingLeft')||0, 10) - parseInt(that.currentItem.css('paddingRight')||0, 10)); } } }; } @@ -786,8 +789,8 @@ $.widget("ui.sortable", $.ui.mouse, { if(helper[0] == this.currentItem[0]) this._storedCSS = { width: this.currentItem[0].style.width, height: this.currentItem[0].style.height, position: this.currentItem.css("position"), top: this.currentItem.css("top"), left: this.currentItem.css("left") }; - if(helper[0].style.width == '' || o.forceHelperSize) helper.width(this.currentItem.width()); - if(helper[0].style.height == '' || o.forceHelperSize) helper.height(this.currentItem.height()); + if(!helper[0].style.width || o.forceHelperSize) helper.width(this.currentItem.width()); + if(!helper[0].style.height || o.forceHelperSize) helper.height(this.currentItem.height()); return helper; @@ -899,7 +902,7 @@ $.widget("ui.sortable", $.ui.mouse, { if(!pos) pos = this.position; var mod = d == "absolute" ? 1 : -1; - var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); + var scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); return { top: ( @@ -949,10 +952,10 @@ $.widget("ui.sortable", $.ui.mouse, { if(o.grid) { var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1]; - pageY = this.containment ? (!(top - this.offset.click.top < this.containment[1] || top - this.offset.click.top > this.containment[3]) ? top : (!(top - this.offset.click.top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; + pageY = this.containment ? ( (top - this.offset.click.top >= this.containment[1] && top - this.offset.click.top <= this.containment[3]) ? top : ((top - this.offset.click.top >= this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0]; - pageX = this.containment ? (!(left - this.offset.click.left < this.containment[0] || left - this.offset.click.left > this.containment[2]) ? left : (!(left - this.offset.click.left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; + pageX = this.containment ? ( (left - this.offset.click.left >= this.containment[0] && left - this.offset.click.left <= this.containment[2]) ? left : ((left - this.offset.click.left >= this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; } } @@ -1047,7 +1050,9 @@ $.widget("ui.sortable", $.ui.mouse, { if(this.cancelHelperRemoval) { if(!noPropagation) { this._trigger("beforeStop", event, this._uiHash()); - for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events + for (var i=0; i < delayedTriggers.length; i++) { + delayedTriggers[i].call(this, event); + } //Trigger all delayed events this._trigger("stop", event, this._uiHash()); } @@ -1063,7 +1068,9 @@ $.widget("ui.sortable", $.ui.mouse, { if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null; if(!noPropagation) { - for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events + for (var i=0; i < delayedTriggers.length; i++) { + delayedTriggers[i].call(this, event); + } //Trigger all delayed events this._trigger("stop", event, this._uiHash()); } diff --git a/ui/jquery.ui.spinner.js b/ui/jquery.ui.spinner.js index 23cce18efb..406eefb915 100644 --- a/ui/jquery.ui.spinner.js +++ b/ui/jquery.ui.spinner.js @@ -94,7 +94,6 @@ $.widget( "ui.spinner", { }, keyup: "_stop", focus: function() { - this.uiSpinner.addClass( "ui-state-active" ); this.previous = this.element.val(); }, blur: function( event ) { @@ -104,7 +103,6 @@ $.widget( "ui.spinner", { } this._refresh(); - this.uiSpinner.removeClass( "ui-state-active" ); if ( this.previous !== this.element.val() ) { this._trigger( "change", event ); } @@ -196,7 +194,6 @@ $.widget( "ui.spinner", { .parent() // add buttons .append( this._buttonHtml() ); - this._hoverable( uiSpinner ); this.element.attr( "role", "spinbutton" ); @@ -242,7 +239,7 @@ $.widget( "ui.spinner", { }, _uiSpinnerHtml: function() { - return ""; + return ""; }, _buttonHtml: function() { diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 7d38fb46ea..5b52271285 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -22,11 +22,13 @@ function getNextTabId() { } function isLocal( anchor ) { - // clone the node to work around IE 6 not normalizing the href property - // if it's manually set, i.e., a.href = "#foo" kills the normalization - anchor = anchor.cloneNode( false ); return anchor.hash.length > 1 && - anchor.href.replace( rhash, "" ) === location.href.replace( rhash, "" ); + anchor.href.replace( rhash, "" ) === + location.href.replace( rhash, "" ) + // support: Safari 5.1 + // Safari 5.1 doesn't encode spaces in window.location + // but it does encode spaces from anchors (#8777) + .replace( /\s/g, "%20" ); } $.widget( "ui.tabs", { @@ -48,8 +50,7 @@ $.widget( "ui.tabs", { }, _create: function() { - var panel, - that = this, + var that = this, options = this.options, active = options.active, locationHash = location.hash.substring( 1 ); @@ -298,8 +299,7 @@ $.widget( "ui.tabs", { }, refresh: function() { - var next, - options = this.options, + var options = this.options, lis = this.tablist.children( ":has(a[href])" ); // get disabled tabs from class attribute from HTML @@ -492,18 +492,10 @@ $.widget( "ui.tabs", { }, _setupHeightStyle: function( heightStyle ) { - var maxHeight, overflow, + var maxHeight, parent = this.element.parent(); if ( heightStyle === "fill" ) { - // IE 6 treats height like minHeight, so we need to turn off overflow - // in order to get a reliable height - // we use the minHeight support test because we assume that only - // browsers that don't support minHeight will treat height as minHeight - if ( !$.support.minHeight ) { - overflow = parent.css( "overflow" ); - parent.css( "overflow", "hidden"); - } maxHeight = parent.height(); this.element.siblings( ":visible" ).each(function() { var elem = $( this ), @@ -514,9 +506,6 @@ $.widget( "ui.tabs", { } maxHeight -= elem.outerHeight( true ); }); - if ( overflow ) { - parent.css( "overflow", overflow ); - } this.element.children().not( this.panels ).each(function() { maxHeight -= $( this ).outerHeight( true ); @@ -727,6 +716,8 @@ $.widget( "ui.tabs", { } }); + this.panels.show(); + if ( this.options.heightStyle !== "content" ) { this.panels.css( "height", "" ); } @@ -830,7 +821,6 @@ $.widget( "ui.tabs", { } }, - // TODO: Remove this function in 1.10 when ajaxOptions is removed _ajaxSettings: function( anchor, event, eventData ) { var that = this; return { @@ -848,512 +838,4 @@ $.widget( "ui.tabs", { } }); -// DEPRECATED -if ( $.uiBackCompat !== false ) { - - // helper method for a lot of the back compat extensions - $.ui.tabs.prototype._ui = function( tab, panel ) { - return { - tab: tab, - panel: panel, - index: this.anchors.index( tab ) - }; - }; - - // url method - $.widget( "ui.tabs", $.ui.tabs, { - url: function( index, url ) { - this.anchors.eq( index ).attr( "href", url ); - } - }); - - // TODO: Remove _ajaxSettings() method when removing this extension - // ajaxOptions and cache options - $.widget( "ui.tabs", $.ui.tabs, { - options: { - ajaxOptions: null, - cache: false - }, - - _create: function() { - this._super(); - - var that = this; - - this._on({ tabsbeforeload: function( event, ui ) { - // tab is already cached - if ( $.data( ui.tab[ 0 ], "cache.tabs" ) ) { - event.preventDefault(); - return; - } - - ui.jqXHR.success(function() { - if ( that.options.cache ) { - $.data( ui.tab[ 0 ], "cache.tabs", true ); - } - }); - }}); - }, - - _ajaxSettings: function( anchor, event, ui ) { - var ajaxOptions = this.options.ajaxOptions; - return $.extend( {}, ajaxOptions, { - error: function( xhr, s, e ) { - try { - // Passing index avoid a race condition when this method is - // called after the user has selected another tab. - // Pass the anchor that initiated this request allows - // loadError to manipulate the tab content panel via $(a.hash) - ajaxOptions.error( - xhr, s, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] ); - } - catch ( e ) {} - } - }, this._superApply( arguments ) ); - }, - - _setOption: function( key, value ) { - // reset cache if switching from cached to not cached - if ( key === "cache" && value === false ) { - this.anchors.removeData( "cache.tabs" ); - } - this._super( key, value ); - }, - - _destroy: function() { - this.anchors.removeData( "cache.tabs" ); - this._super(); - }, - - url: function( index, url ){ - this.anchors.eq( index ).removeData( "cache.tabs" ); - this._superApply( arguments ); - } - }); - - // abort method - $.widget( "ui.tabs", $.ui.tabs, { - abort: function() { - if ( this.xhr ) { - this.xhr.abort(); - } - } - }); - - // spinner - $.widget( "ui.tabs", $.ui.tabs, { - options: { - spinner: "Loading…" - }, - _create: function() { - this._super(); - this._on({ - tabsbeforeload: function( event, ui ) { - // Don't react to nested tabs or tabs that don't use a spinner - if ( event.target !== this.element[ 0 ] || - !this.options.spinner ) { - return; - } - - var span = ui.tab.find( "span" ), - html = span.html(); - span.html( this.options.spinner ); - ui.jqXHR.complete(function() { - span.html( html ); - }); - } - }); - } - }); - - // enable/disable events - $.widget( "ui.tabs", $.ui.tabs, { - options: { - enable: null, - disable: null - }, - - enable: function( index ) { - var options = this.options, - trigger; - - if ( index && options.disabled === true || - ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) !== -1 ) ) { - trigger = true; - } - - this._superApply( arguments ); - - if ( trigger ) { - this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) ); - } - }, - - disable: function( index ) { - var options = this.options, - trigger; - - if ( index && options.disabled === false || - ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) === -1 ) ) { - trigger = true; - } - - this._superApply( arguments ); - - if ( trigger ) { - this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) ); - } - } - }); - - // add/remove methods and events - $.widget( "ui.tabs", $.ui.tabs, { - options: { - add: null, - remove: null, - tabTemplate: "
  • #{label}
  • " - }, - - add: function( url, label, index ) { - if ( index === undefined ) { - index = this.anchors.length; - } - - var doInsertAfter, panel, - options = this.options, - li = $( options.tabTemplate - .replace( /#\{href\}/g, url ) - .replace( /#\{label\}/g, label ) ), - id = !url.indexOf( "#" ) ? - url.replace( "#", "" ) : - this._tabId( li ); - - li.addClass( "ui-state-default ui-corner-top" ).data( "ui-tabs-destroy", true ); - li.attr( "aria-controls", id ); - - doInsertAfter = index >= this.tabs.length; - - // try to find an existing element before creating a new one - panel = this.element.find( "#" + id ); - if ( !panel.length ) { - panel = this._createPanel( id ); - if ( doInsertAfter ) { - if ( index > 0 ) { - panel.insertAfter( this.panels.eq( -1 ) ); - } else { - panel.appendTo( this.element ); - } - } else { - panel.insertBefore( this.panels[ index ] ); - } - } - panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ).hide(); - - if ( doInsertAfter ) { - li.appendTo( this.tablist ); - } else { - li.insertBefore( this.tabs[ index ] ); - } - - options.disabled = $.map( options.disabled, function( n ) { - return n >= index ? ++n : n; - }); - - this.refresh(); - if ( this.tabs.length === 1 && options.active === false ) { - this.option( "active", 0 ); - } - - this._trigger( "add", null, this._ui( this.anchors[ index ], this.panels[ index ] ) ); - return this; - }, - - remove: function( index ) { - index = this._getIndex( index ); - var options = this.options, - tab = this.tabs.eq( index ).remove(), - panel = this._getPanelForTab( tab ).remove(); - - // If selected tab was removed focus tab to the right or - // in case the last tab was removed the tab to the left. - // We check for more than 2 tabs, because if there are only 2, - // then when we remove this tab, there will only be one tab left - // so we don't need to detect which tab to activate. - if ( tab.hasClass( "ui-tabs-active" ) && this.anchors.length > 2 ) { - this._activate( index + ( index + 1 < this.anchors.length ? 1 : -1 ) ); - } - - options.disabled = $.map( - $.grep( options.disabled, function( n ) { - return n !== index; - }), - function( n ) { - return n >= index ? --n : n; - }); - - this.refresh(); - - this._trigger( "remove", null, this._ui( tab.find( "a" )[ 0 ], panel[ 0 ] ) ); - return this; - } - }); - - // length method - $.widget( "ui.tabs", $.ui.tabs, { - length: function() { - return this.anchors.length; - } - }); - - // panel ids (idPrefix option + title attribute) - $.widget( "ui.tabs", $.ui.tabs, { - options: { - idPrefix: "ui-tabs-" - }, - - _tabId: function( tab ) { - var a = tab.is( "li" ) ? tab.find( "a[href]" ) : tab; - a = a[0]; - return $( a ).closest( "li" ).attr( "aria-controls" ) || - a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF\-]/g, "" ) || - this.options.idPrefix + getNextTabId(); - } - }); - - // _createPanel method - $.widget( "ui.tabs", $.ui.tabs, { - options: { - panelTemplate: "
    " - }, - - _createPanel: function( id ) { - return $( this.options.panelTemplate ) - .attr( "id", id ) - .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ) - .data( "ui-tabs-destroy", true ); - } - }); - - // selected option - $.widget( "ui.tabs", $.ui.tabs, { - _create: function() { - var options = this.options; - if ( options.active === null && options.selected !== undefined ) { - options.active = options.selected === -1 ? false : options.selected; - } - this._super(); - options.selected = options.active; - if ( options.selected === false ) { - options.selected = -1; - } - }, - - _setOption: function( key, value ) { - if ( key !== "selected" ) { - return this._super( key, value ); - } - - var options = this.options; - this._super( "active", value === -1 ? false : value ); - options.selected = options.active; - if ( options.selected === false ) { - options.selected = -1; - } - }, - - _eventHandler: function( event ) { - this._superApply( arguments ); - this.options.selected = this.options.active; - if ( this.options.selected === false ) { - this.options.selected = -1; - } - } - }); - - // show and select event - $.widget( "ui.tabs", $.ui.tabs, { - options: { - show: null, - select: null - }, - _create: function() { - this._super(); - if ( this.options.active !== false ) { - this._trigger( "show", null, this._ui( - this.active.find( ".ui-tabs-anchor" )[ 0 ], - this._getPanelForTab( this.active )[ 0 ] ) ); - } - }, - _trigger: function( type, event, data ) { - var ret = this._superApply( arguments ); - if ( !ret ) { - return false; - } - if ( type === "beforeActivate" && data.newTab.length ) { - ret = this._super( "select", event, { - tab: data.newTab.find( ".ui-tabs-anchor" )[ 0], - panel: data.newPanel[ 0 ], - index: data.newTab.closest( "li" ).index() - }); - } else if ( type === "activate" && data.newTab.length ) { - ret = this._super( "show", event, { - tab: data.newTab.find( ".ui-tabs-anchor" )[ 0 ], - panel: data.newPanel[ 0 ], - index: data.newTab.closest( "li" ).index() - }); - } - return ret; - } - }); - - // select method - $.widget( "ui.tabs", $.ui.tabs, { - select: function( index ) { - index = this._getIndex( index ); - if ( index === -1 ) { - if ( this.options.collapsible && this.options.selected !== -1 ) { - index = this.options.selected; - } else { - return; - } - } - this.anchors.eq( index ).trigger( this.options.event + this.eventNamespace ); - } - }); - - // cookie option - (function() { - - var listId = 0; - - $.widget( "ui.tabs", $.ui.tabs, { - options: { - cookie: null // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true } - }, - _create: function() { - var options = this.options, - active; - if ( options.active == null && options.cookie ) { - active = parseInt( this._cookie(), 10 ); - if ( active === -1 ) { - active = false; - } - options.active = active; - } - this._super(); - }, - _cookie: function( active ) { - var cookie = [ this.cookie || - ( this.cookie = this.options.cookie.name || "ui-tabs-" + (++listId) ) ]; - if ( arguments.length ) { - cookie.push( active === false ? -1 : active ); - cookie.push( this.options.cookie ); - } - return $.cookie.apply( null, cookie ); - }, - _refresh: function() { - this._super(); - if ( this.options.cookie ) { - this._cookie( this.options.active, this.options.cookie ); - } - }, - _eventHandler: function( event ) { - this._superApply( arguments ); - if ( this.options.cookie ) { - this._cookie( this.options.active, this.options.cookie ); - } - }, - _destroy: function() { - this._super(); - if ( this.options.cookie ) { - this._cookie( null, this.options.cookie ); - } - } - }); - - })(); - - // load event - $.widget( "ui.tabs", $.ui.tabs, { - _trigger: function( type, event, data ) { - var _data = $.extend( {}, data ); - if ( type === "load" ) { - _data.panel = _data.panel[ 0 ]; - _data.tab = _data.tab.find( ".ui-tabs-anchor" )[ 0 ]; - } - return this._super( type, event, _data ); - } - }); - - // fx option - // The new animation options (show, hide) conflict with the old show callback. - // The old fx option wins over show/hide anyway (always favor back-compat). - // If a user wants to use the new animation API, they must give up the old API. - $.widget( "ui.tabs", $.ui.tabs, { - options: { - fx: null // e.g. { height: "toggle", opacity: "toggle", duration: 200 } - }, - - _getFx: function() { - var hide, show, - fx = this.options.fx; - - if ( fx ) { - if ( $.isArray( fx ) ) { - hide = fx[ 0 ]; - show = fx[ 1 ]; - } else { - hide = show = fx; - } - } - - return fx ? { show: show, hide: hide } : null; - }, - - _toggle: function( event, eventData ) { - var that = this, - toShow = eventData.newPanel, - toHide = eventData.oldPanel, - fx = this._getFx(); - - if ( !fx ) { - return this._super( event, eventData ); - } - - that.running = true; - - function complete() { - that.running = false; - that._trigger( "activate", event, eventData ); - } - - function show() { - eventData.newTab.closest( "li" ).addClass( "ui-tabs-active ui-state-active" ); - - if ( toShow.length && fx.show ) { - toShow - .animate( fx.show, fx.show.duration, function() { - complete(); - }); - } else { - toShow.show(); - complete(); - } - } - - // start out by hiding, then showing, then completing - if ( toHide.length && fx.hide ) { - toHide.animate( fx.hide, fx.hide.duration, function() { - eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" ); - show(); - }); - } else { - eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" ); - toHide.hide(); - show(); - } - } - }); -} - })( jQuery ); diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js index 980b43868e..e5b496beeb 100644 --- a/ui/jquery.ui.tooltip.js +++ b/ui/jquery.ui.tooltip.js @@ -49,11 +49,12 @@ $.widget( "ui.tooltip", { return $( this ).attr( "title" ); }, hide: true, - items: "[title]", + // Disabled elements have inconsistent behavior across browsers (#8661) + items: "[title]:not([disabled])", position: { - my: "left+15 center", - at: "right center", - collision: "flipfit flipfit" + my: "left top+15", + at: "left bottom", + collision: "flipfit flip" }, show: true, tooltipClass: null, @@ -72,6 +73,12 @@ $.widget( "ui.tooltip", { // IDs of generated tooltips, needed for destroy this.tooltips = {}; + // IDs of parent tooltips where we removed the title attribute + this.parents = {}; + + if ( this.options.disabled ) { + this._disable(); + } }, _setOption: function( key, value ) { @@ -125,7 +132,10 @@ $.widget( "ui.tooltip", { }, open: function( event ) { - var target = $( event ? event.target : this.element ) + var that = this, + target = $( event ? event.target : this.element ) + // we need closest here due to mouseover bubbling, + // but always pointing at the same event target .closest( this.options.items ); // No element to show a tooltip for @@ -149,7 +159,28 @@ $.widget( "ui.tooltip", { target.data( "ui-tooltip-title", target.attr( "title" ) ); } - target.data( "tooltip-open", true ); + target.data( "ui-tooltip-open", true ); + + // kill parent tooltips, custom or native, for hover + if ( event && event.type === "mouseover" ) { + target.parents().each(function() { + var parent = $( this ), + blurEvent; + if ( parent.data( "ui-tooltip-open" ) ) { + blurEvent = $.Event( "blur" ); + blurEvent.target = blurEvent.currentTarget = this; + that.close( blurEvent, true ); + } + if ( parent.attr( "title" ) ) { + parent.uniqueId(); + that.parents[ this.id ] = { + element: this, + title: parent.attr( "title" ) + }; + parent.attr( "title", "" ); + } + }); + } this._updateContent( target, event ); }, @@ -165,7 +196,7 @@ $.widget( "ui.tooltip", { content = contentOption.call( target[0], function( response ) { // ignore async response if tooltip was closed already - if ( !target.data( "tooltip-open" ) ) { + if ( !target.data( "ui-tooltip-open" ) ) { return; } // IE may instantly serve a cached response for ajax requests @@ -180,7 +211,9 @@ $.widget( "ui.tooltip", { }, _open: function( event, target, content ) { - var tooltip, positionOption; + var tooltip, events, delayedShow, + positionOption = $.extend( {}, this.options.position ); + if ( !content ) { return; } @@ -214,10 +247,12 @@ $.widget( "ui.tooltip", { function position( event ) { positionOption.of = event; + if ( tooltip.is( ":hidden" ) ) { + return; + } tooltip.position( positionOption ); } - if ( this.options.track && event && /^mouse/.test( event.originalEvent.type ) ) { - positionOption = $.extend( {}, this.options.position ); + if ( this.options.track && event && /^mouse/.test( event.type ) ) { this._on( this.document, { mousemove: position }); @@ -232,23 +267,42 @@ $.widget( "ui.tooltip", { tooltip.hide(); this._show( tooltip, this.options.show ); + // Handle tracking tooltips that are shown with a delay (#8644). As soon + // as the tooltip is visible, position the tooltip using the most recent + // event. + if ( this.options.show && this.options.show.delay ) { + delayedShow = setInterval(function() { + if ( tooltip.is( ":visible" ) ) { + position( positionOption.of ); + clearInterval( delayedShow ); + } + }, $.fx.interval ); + } this._trigger( "open", event, { tooltip: tooltip } ); - this._on( target, { - mouseleave: "close", - focusout: "close", + events = { keyup: function( event ) { if ( event.keyCode === $.ui.keyCode.ESCAPE ) { var fakeEvent = $.Event(event); fakeEvent.currentTarget = target[0]; this.close( fakeEvent, true ); } + }, + remove: function() { + this._removeTooltip( tooltip ); } - }); + }; + if ( !event || event.type === "mouseover" ) { + events.mouseleave = "close"; + } + if ( !event || event.type === "focusin" ) { + events.focusout = "close"; + } + this._on( true, target, events ); }, - close: function( event, force ) { + close: function( event ) { var that = this, target = $( event ? event.currentTarget : this.element ), tooltip = this._find( target ); @@ -259,16 +313,6 @@ $.widget( "ui.tooltip", { return; } - // don't close if the element has focus - // this prevents the tooltip from closing if you hover while focused - // - // we have to check the event type because tabbing out of the document - // may leave the element as the activeElement - if ( !force && event && event.type !== "focusout" && - this.document[0].activeElement === target[0] ) { - return; - } - // only set title if we had one before (see comment in _open()) if ( target.data( "ui-tooltip-title" ) ) { target.attr( "title", target.data( "ui-tooltip-title" ) ); @@ -278,14 +322,24 @@ $.widget( "ui.tooltip", { tooltip.stop( true ); this._hide( tooltip, this.options.hide, function() { - $( this ).remove(); - delete that.tooltips[ this.id ]; + that._removeTooltip( $( this ) ); }); - target.removeData( "tooltip-open" ); + target.removeData( "ui-tooltip-open" ); this._off( target, "mouseleave focusout keyup" ); + // Remove 'remove' binding only on delegated targets + if ( target[0] !== this.element[0] ) { + this._off( target, "remove" ); + } this._off( this.document, "mousemove" ); + if ( event && event.type === "mouseleave" ) { + $.each( this.parents, function( id, parent ) { + $( parent.element ).attr( "title", parent.title ); + delete that.parents[ id ]; + }); + } + this.closing = true; this._trigger( "close", event, { tooltip: tooltip } ); this.closing = false; @@ -304,9 +358,6 @@ $.widget( "ui.tooltip", { .addClass( "ui-tooltip-content" ) .appendTo( tooltip ); tooltip.appendTo( this.document[0].body ); - if ( $.fn.bgiframe ) { - tooltip.bgiframe(); - } this.tooltips[ id ] = element; return tooltip; }, @@ -316,6 +367,11 @@ $.widget( "ui.tooltip", { return id ? $( "#" + id ) : $(); }, + _removeTooltip: function( tooltip ) { + tooltip.remove(); + delete this.tooltips[ tooltip.attr( "id" ) ]; + }, + _destroy: function() { var that = this; diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index a125dd5ac9..06f25576af 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -101,13 +101,11 @@ $.widget = function( name, base, prototype ) { // TODO: remove support for widgetEventPrefix // always use the name + a colon as the prefix, e.g., draggable:start // don't prefix for widgets that aren't DOM-based - widgetEventPrefix: name + widgetEventPrefix: existingConstructor ? basePrototype.widgetEventPrefix : name }, prototype, { constructor: constructor, namespace: namespace, widgetName: name, - // TODO remove widgetBaseClass, see #8155 - widgetBaseClass: fullName, widgetFullName: fullName }); @@ -142,8 +140,17 @@ $.widget.extend = function( target ) { for ( ; inputIndex < inputLength; inputIndex++ ) { for ( key in input[ inputIndex ] ) { value = input[ inputIndex ][ key ]; - if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) { - target[ key ] = $.isPlainObject( value ) ? $.widget.extend( {}, target[ key ], value ) : value; + if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) { + // Clone objects + if ( $.isPlainObject( value ) ) { + target[ key ] = $.isPlainObject( target[ key ] ) ? + $.widget.extend( {}, target[ key ], value ) : + // Don't extend strings, arrays, etc. with objects + $.widget.extend( {}, value ); + // Copy everything else by reference + } else { + target[ key ] = value; + } } } } @@ -151,7 +158,7 @@ $.widget.extend = function( target ) { }; $.widget.bridge = function( name, object ) { - var fullName = object.prototype.widgetFullName; + var fullName = object.prototype.widgetFullName || name; $.fn[ name ] = function( options ) { var isMethodCall = typeof options === "string", args = slice.call( arguments, 1 ), @@ -187,7 +194,7 @@ $.widget.bridge = function( name, object ) { if ( instance ) { instance.option( options || {} )._init(); } else { - new object( options, this ); + $.data( this, fullName, new object( options, this ) ); } }); } @@ -196,7 +203,7 @@ $.widget.bridge = function( name, object ) { }; }; -$.Widget = function( options, element ) {}; +$.Widget = function( /* options, element */ ) {}; $.Widget._childConstructors = []; $.Widget.prototype = { @@ -224,11 +231,14 @@ $.Widget.prototype = { this.focusable = $(); if ( element !== this ) { - // 1.9 BC for #7810 - // TODO remove dual storage - $.data( element, this.widgetName, this ); $.data( element, this.widgetFullName, this ); - this._on({ remove: "destroy" }); + this._on( true, this.element, { + remove: function( event ) { + if ( event.target === element ) { + this.destroy(); + } + } + }); this.document = $( element.style ? // element within the document element.ownerDocument : @@ -346,25 +356,36 @@ $.Widget.prototype = { return this._setOption( "disabled", true ); }, - _on: function( element, handlers ) { + _on: function( suppressDisabledCheck, element, handlers ) { + var delegateElement, + instance = this; + + // no suppressDisabledCheck flag, shuffle arguments + if ( typeof suppressDisabledCheck !== "boolean" ) { + handlers = element; + element = suppressDisabledCheck; + suppressDisabledCheck = false; + } + // no element argument, shuffle and use this.element if ( !handlers ) { handlers = element; element = this.element; + delegateElement = this.widget(); } else { // accept selectors, DOM elements - element = $( element ); + element = delegateElement = $( element ); this.bindings = this.bindings.add( element ); } - var instance = this; $.each( handlers, function( event, handler ) { function handlerProxy() { // allow widgets to customize the disabled handling // - disabled as an array instead of boolean // - disabled class as method for disabling individual parts - if ( instance.options.disabled === true || - $( this ).hasClass( "ui-state-disabled" ) ) { + if ( !suppressDisabledCheck && + ( instance.options.disabled === true || + $( this ).hasClass( "ui-state-disabled" ) ) ) { return; } return ( typeof handler === "string" ? instance[ handler ] : handler ) @@ -381,7 +402,7 @@ $.Widget.prototype = { eventName = match[1] + instance.eventNamespace, selector = match[2]; if ( selector ) { - instance.widget().delegate( selector, eventName, handlerProxy ); + delegateElement.delegate( selector, eventName, handlerProxy ); } else { element.bind( eventName, handlerProxy ); } @@ -476,7 +497,7 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) { if ( options.delay ) { element.delay( options.delay ); } - if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) { + if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) { element[ method ]( options ); } else if ( effectName !== method && element[ effectName ] ) { element[ effectName ]( options.duration, options.easing, callback ); @@ -492,11 +513,4 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) { }; }); -// DEPRECATED -if ( $.uiBackCompat !== false ) { - $.Widget.prototype._getCreateOptions = function() { - return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ]; - }; -} - })( jQuery );