Make WordPress Core

Ticket #25999: 25999.2.diff

File 25999.2.diff, 9.8 KB (added by dougwollison, 11 years ago)

Revised declaration of globals.

  • src/wp-admin/js/gallery.js

     
    1 jQuery(document).ready(function($) {
    2         var gallerySortable, gallerySortableInit, w, desc = false;
     1/* global unescape, getUserSetting, setUserSetting */
    32
     3jQuery( document ).ready(function( $ ) {
     4        var gallerySortable, gallerySortableInit, sortIt, clearAll, w, desc = false;
     5
    46        gallerySortableInit = function() {
    5                 gallerySortable = $('#media-items').sortable( {
    6                         items: 'div.media-item',
     7                gallerySortable = $( '#media-items' ).sortable({
     8                        items:       'div.media-item',
    79                        placeholder: 'sorthelper',
    8                         axis: 'y',
    9                         distance: 2,
    10                         handle: 'div.filename',
    11                         stop: function(e, ui) {
     10                        axis:        'y',
     11                        distance:     2,
     12                        handle:      'div.filename',
     13                        stop:        function() {
    1214                                // When an update has occurred, adjust the order for each item
    13                                 var all = $('#media-items').sortable('toArray'), len = all.length;
    14                                 $.each(all, function(i, id) {
    15                                         var order = desc ? (len - i) : (1 + i);
    16                                         $('#' + id + ' .menu_order input').val(order);
     15                                var all = $( '#media-items' ).sortable( 'toArray' ), len = all.length;
     16                                $.each( all, function( i, id ) {
     17                                        var order = desc ? ( len - i ) : ( 1 + i );
     18                                        $( '#' + id + ' .menu_order input' ).val( order );
    1719                                });
    1820                        }
    19                 } );
    20         }
     21                });
     22        };
    2123
    2224        sortIt = function() {
    23                 var all = $('.menu_order_input'), len = all.length;
    24                 all.each(function(i){
    25                         var order = desc ? (len - i) : (1 + i);
    26                         $(this).val(order);
     25                var all = $( '.menu_order_input' ), len = all.length;
     26                all.each(function( i ) {
     27                        var order = desc ? ( len - i ) : ( 1 + i );
     28                        $( this ).val( order );
    2729                });
    28         }
     30        };
    2931
    3032        clearAll = function(c) {
    3133                c = c || 0;
    32                 $('.menu_order_input').each(function(){
    33                         if ( this.value == '0' || c ) this.value = '';
     34                $( '.menu_order_input' ).each( function() {
     35                        if ( this.value === '0' || c ) {
     36                                this.value = '';
     37                        }
    3438                });
    35         }
     39        };
    3640
    37         $('#asc').click(function(){desc = false; sortIt(); return false;});
    38         $('#desc').click(function(){desc = true; sortIt(); return false;});
    39         $('#clear').click(function(){clearAll(1); return false;});
    40         $('#showall').click(function(){
    41                 $('#sort-buttons span a').toggle();
    42                 $('a.describe-toggle-on').hide();
    43                 $('a.describe-toggle-off, table.slidetoggle').show();
    44                 $('img.pinkynail').toggle(false);
     41        $( '#asc').click( function() {
     42                desc = false;
     43                sortIt();
    4544                return false;
    4645        });
    47         $('#hideall').click(function(){
    48                 $('#sort-buttons span a').toggle();
    49                 $('a.describe-toggle-on').show();
    50                 $('a.describe-toggle-off, table.slidetoggle').hide();
    51                 $('img.pinkynail').toggle(true);
     46        $( '#desc').click( function(){
     47                desc = true;
     48                sortIt();
    5249                return false;
    5350        });
     51        $( '#clear').click( function(){
     52                clearAll(1);
     53                return false;
     54        });
     55        $( '#showall').click( function() {
     56                $( '#sort-buttons span a' ).toggle();
     57                $( 'a.describe-toggle-on' ).hide();
     58                $( 'a.describe-toggle-off, table.slidetoggle' ).show();
     59                $( 'img.pinkynail' ).toggle( false );
     60                return false;
     61        });
     62        $( '#hideall' ).click( function() {
     63                $( '#sort-buttons span a' ).toggle();
     64                $( 'a.describe-toggle-on' ).show();
     65                $( 'a.describe-toggle-off, table.slidetoggle' ).hide();
     66                $( 'img.pinkynail' ).toggle( true );
     67                return false;
     68        });
    5469
    5570        // initialize sortable
    5671        gallerySortableInit();
    5772        clearAll();
    5873
    59         if ( $('#media-items>*').length > 1 ) {
     74        if ( $( '#media-items>*' ).length > 1 ) {
    6075                w = wpgallery.getWin();
    6176
    62                 $('#save-all, #gallery-settings').show();
    63                 if ( typeof w.tinyMCE != 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) {
     77                $( '#save-all, #gallery-settings' ).show();
     78                if ( typeof w.tinyMCE !== 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) {
    6479                        wpgallery.mcemode = true;
    6580                        wpgallery.init();
    6681                } else {
    67                         $('#insert-gallery').show();
     82                        $( '#insert-gallery' ).show();
    6883                }
    6984        }
    7085});
    7186
    72 jQuery(window).unload( function () { tinymce = tinyMCE = wpgallery = null; } ); // Cleanup
     87jQuery( window ).unload(function () {
     88        tinymce = tinyMCE = wpgallery = null;
     89}); // Cleanup
    7390
    7491/* gallery settings */
    7592var tinymce = null, tinyMCE, wpgallery;
    7693
    7794wpgallery = {
    78         mcemode : false,
    79         editor : {},
    80         dom : {},
    81         is_update : false,
    82         el : {},
     95        mcemode false,
     96        editor:    {},
     97        dom:      {},
     98        is_update: false,
     99        el:        {},
    83100
    84         I : function(e) {
    85                 return document.getElementById(e);
     101        I: function( e ) {
     102                return document.getElementById( e );
    86103        },
    87104
    88105        init: function() {
    89106                var t = this, li, q, i, it, w = t.getWin();
    90107
    91                 if ( ! t.mcemode ) return;
     108                if ( ! t.mcemode ) {
     109                        return;
     110                }
    92111
    93                 li = ('' + document.location.search).replace(/^\?/, '').split('&');
     112                li = ( '' + document.location.search ).replace( /^\?/, '' ).split( '&' );
    94113                q = {};
    95                 for (i=0; i<li.length; i++) {
    96                         it = li[i].split('=');
    97                         q[unescape(it[0])] = unescape(it[1]);
     114                for ( i = 0; i < li.length; i++ ) {
     115                        it = li[i].split( '=' );
     116                        q[ unescape( it[0] ) ] = unescape( it[1] );
    98117                }
    99118
    100                 if (q.mce_rdomain)
     119                if ( q.mce_rdomain ) {
    101120                        document.domain = q.mce_rdomain;
     121                }
    102122
    103123                // Find window & API
    104124                tinymce = w.tinymce;
     
    108128                t.setup();
    109129        },
    110130
    111         getWin : function() {
     131        getWin: function() {
    112132                return window.dialogArguments || opener || parent || top;
    113133        },
    114134
    115         setup : function() {
     135        setup: function() {
    116136                var t = this, a, ed = t.editor, g, columns, link, order, orderby;
    117                 if ( ! t.mcemode ) return;
     137                if ( ! t.mcemode ) {
     138                        return;
     139                }
    118140
    119141                t.el = ed.selection.getNode();
    120142
    121                 if ( t.el.nodeName != 'IMG' || ! ed.dom.hasClass(t.el, 'wpGallery') ) {
    122                         if ( (g = ed.dom.select('img.wpGallery')) && g[0] ) {
     143                if ( t.el.nodeName !== 'IMG' || ! ed.dom.hasClass( t.el, 'wpGallery') ) {
     144                        if ( ( g = ed.dom.select('img.wpGallery' ) ) && g[0] ) {
    123145                                t.el = g[0];
    124146                        } else {
    125                                 if ( getUserSetting('galfile') == '1' ) t.I('linkto-file').checked = "checked";
    126                                 if ( getUserSetting('galdesc') == '1' ) t.I('order-desc').checked = "checked";
    127                                 if ( getUserSetting('galcols') ) t.I('columns').value = getUserSetting('galcols');
    128                                 if ( getUserSetting('galord') ) t.I('orderby').value = getUserSetting('galord');
    129                                 jQuery('#insert-gallery').show();
     147                                if ( getUserSetting( 'galfile' ) === '1' ) {
     148                                        t.I( 'linkto-file' ).checked = 'checked';
     149                                }
     150                                if ( getUserSetting( 'galdesc' ) === '1' ) {
     151                                        t.I( 'order-desc' ).checked = 'checked';
     152                                }
     153                                if ( getUserSetting( 'galcols' ) ) {
     154                                        t.I( 'columns' ).value = getUserSetting( 'galcols' );
     155                                }
     156                                if ( getUserSetting( 'galord' ) ) {
     157                                        t.I( 'orderby' ).value = getUserSetting( 'galord' );
     158                                }
     159                                jQuery( '#insert-gallery' ).show();
    130160                                return;
    131161                        }
    132162                }
    133163
    134                 a = ed.dom.getAttrib(t.el, 'title');
    135                 a = ed.dom.decode(a);
     164                a = ed.dom.getAttrib( t.el, 'title' );
     165                a = ed.dom.decode( a );
    136166
    137167                if ( a ) {
    138                         jQuery('#update-gallery').show();
     168                        jQuery( '#update-gallery' ).show();
    139169                        t.is_update = true;
    140170
    141                         columns = a.match(/columns=['"]([0-9]+)['"]/);
    142                         link = a.match(/link=['"]([^'"]+)['"]/i);
    143                         order = a.match(/order=['"]([^'"]+)['"]/i);
    144                         orderby = a.match(/orderby=['"]([^'"]+)['"]/i);
     171                        columns = a.match( /columns=['']([0-9]+)['']/ );
     172                        link = a.match( /link=['']([^'']+)['']/i );
     173                        order = a.match( /order=['']([^'']+)['']/i );
     174                        orderby = a.match( /orderby=['']([^'']+)['']/i );
    145175
    146                         if ( link && link[1] ) t.I('linkto-file').checked = "checked";
    147                         if ( order && order[1] ) t.I('order-desc').checked = "checked";
    148                         if ( columns && columns[1] ) t.I('columns').value = ''+columns[1];
    149                         if ( orderby && orderby[1] ) t.I('orderby').value = orderby[1];
     176                        if ( link && link[1] ) {
     177                                t.I( 'linkto-file' ).checked = 'checked';
     178                        }
     179                        if ( order && order[1] ) {
     180                                t.I( 'order-desc' ).checked = 'checked';
     181                        }
     182                        if ( columns && columns[1] ) {
     183                                t.I( 'columns' ).value = ''+columns[1];
     184                        }
     185                        if ( orderby && orderby[1] ) {
     186                                t.I( 'orderby' ).value = orderby[1];
     187                        }
    150188                } else {
    151                         jQuery('#insert-gallery').show();
     189                        jQuery( '#insert-gallery' ).show();
    152190                }
    153191        },
    154192
    155         update : function() {
     193        update: function() {
    156194                var t = this, ed = t.editor, all = '', s;
    157195
    158196                if ( ! t.mcemode || ! t.is_update ) {
    159                         s = '[gallery'+t.getSettings()+']';
     197                        s = '[gallery' + t.getSettings() + ']';
    160198                        t.getWin().send_to_editor(s);
    161199                        return;
    162200                }
    163201
    164                 if (t.el.nodeName != 'IMG') return;
     202                if ( t.el.nodeName !== 'IMG' ) {
     203                        return;
     204                }
    165205
    166                 all = ed.dom.decode(ed.dom.getAttrib(t.el, 'title'));
    167                 all = all.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi, '');
     206                all = ed.dom.decode( ed.dom.getAttrib( t.el, 'title' ) );
     207                all = all.replace( /\s*(order|link|columns|orderby)=['']([^'']+)['']/gi, '' );
    168208                all += t.getSettings();
    169209
    170                 ed.dom.setAttrib(t.el, 'title', all);
     210                ed.dom.setAttrib( t.el, 'title', all );
    171211                t.getWin().tb_remove();
    172212        },
    173213
    174         getSettings : function() {
     214        getSettings: function() {
    175215                var I = this.I, s = '';
    176216
    177                 if ( I('linkto-file').checked ) {
     217                if ( I( 'linkto-file' ).checked ) {
    178218                        s += ' link="file"';
    179                         setUserSetting('galfile', '1');
     219                        setUserSetting( 'galfile', '1' );
    180220                }
    181221
    182                 if ( I('order-desc').checked ) {
     222                if ( I( 'order-desc' ).checked ) {
    183223                        s += ' order="DESC"';
    184                         setUserSetting('galdesc', '1');
     224                        setUserSetting( 'galdesc', '1' );
    185225                }
    186226
    187                 if ( I('columns').value != 3 ) {
    188                         s += ' columns="'+I('columns').value+'"';
    189                         setUserSetting('galcols', I('columns').value);
     227                if ( I( 'columns' ).value !== 3 ) {
     228                        s += ' columns="' + I('columns').value + '"';
     229                        setUserSetting( 'galcols', I( 'columns' ).value );
    190230                }
    191231
    192                 if ( I('orderby').value != 'menu_order' ) {
    193                         s += ' orderby="'+I('orderby').value+'"';
    194                         setUserSetting('galord', I('orderby').value);
     232                if ( I( 'orderby' ).value !== 'menu_order' ) {
     233                        s += ' orderby="' + I( 'orderby' ).value + '"';
     234                        setUserSetting( 'galord', I( 'orderby' ).value );
    195235                }
    196236
    197237                return s;