[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/js/ -> gallery.js (source)

   1  /**
   2   * @output wp-admin/js/gallery.js
   3   */
   4  
   5  /* global unescape, getUserSetting, setUserSetting, wpgallery, tinymce */
   6  
   7  jQuery( function($) {
   8      var gallerySortable, gallerySortableInit, sortIt, clearAll, w, desc = false;
   9  
  10      gallerySortableInit = function() {
  11          gallerySortable = $('#media-items').sortable( {
  12              items: 'div.media-item',
  13              placeholder: 'sorthelper',
  14              axis: 'y',
  15              distance: 2,
  16              handle: 'div.filename',
  17              stop: function() {
  18                  // When an update has occurred, adjust the order for each item.
  19                  var all = $('#media-items').sortable('toArray'), len = all.length;
  20                  $.each(all, function(i, id) {
  21                      var order = desc ? (len - i) : (1 + i);
  22                      $('#' + id + ' .menu_order input').val(order);
  23                  });
  24              }
  25          } );
  26      };
  27  
  28      sortIt = function() {
  29          var all = $('.menu_order_input'), len = all.length;
  30          all.each(function(i){
  31              var order = desc ? (len - i) : (1 + i);
  32              $(this).val(order);
  33          });
  34      };
  35  
  36      clearAll = function(c) {
  37          c = c || 0;
  38          $('.menu_order_input').each( function() {
  39              if ( this.value === '0' || c ) {
  40                  this.value = '';
  41              }
  42          });
  43      };
  44  
  45      $('#asc').on( 'click', function( e ) {
  46          e.preventDefault();
  47          desc = false;
  48          sortIt();
  49      });
  50      $('#desc').on( 'click', function( e ) {
  51          e.preventDefault();
  52          desc = true;
  53          sortIt();
  54      });
  55      $('#clear').on( 'click', function( e ) {
  56          e.preventDefault();
  57          clearAll(1);
  58      });
  59      $('#showall').on( 'click', function( e ) {
  60          e.preventDefault();
  61          $('#sort-buttons span a').toggle();
  62          $('a.describe-toggle-on').hide();
  63          $('a.describe-toggle-off, table.slidetoggle').show();
  64          $('img.pinkynail').toggle(false);
  65      });
  66      $('#hideall').on( 'click', function( e ) {
  67          e.preventDefault();
  68          $('#sort-buttons span a').toggle();
  69          $('a.describe-toggle-on').show();
  70          $('a.describe-toggle-off, table.slidetoggle').hide();
  71          $('img.pinkynail').toggle(true);
  72      });
  73  
  74      // Initialize sortable.
  75      gallerySortableInit();
  76      clearAll();
  77  
  78      if ( $('#media-items>*').length > 1 ) {
  79          w = wpgallery.getWin();
  80  
  81          $('#save-all, #gallery-settings').show();
  82          if ( typeof w.tinyMCE !== 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) {
  83              wpgallery.mcemode = true;
  84              wpgallery.init();
  85          } else {
  86              $('#insert-gallery').show();
  87          }
  88      }
  89  });
  90  
  91  jQuery(window).on( 'unload', function () { window.tinymce = window.tinyMCE = window.wpgallery = null; } ); // Cleanup.
  92  
  93  /* gallery settings */
  94  window.tinymce = null;
  95  
  96  window.wpgallery = {
  97      mcemode : false,
  98      editor : {},
  99      dom : {},
 100      is_update : false,
 101      el : {},
 102  
 103      I : function(e) {
 104          return document.getElementById(e);
 105      },
 106  
 107      init: function() {
 108          var t = this, li, q, i, it, w = t.getWin();
 109  
 110          if ( ! t.mcemode ) {
 111              return;
 112          }
 113  
 114          li = ('' + document.location.search).replace(/^\?/, '').split('&');
 115          q = {};
 116          for (i=0; i<li.length; i++) {
 117              it = li[i].split('=');
 118              q[unescape(it[0])] = unescape(it[1]);
 119          }
 120  
 121          if ( q.mce_rdomain ) {
 122              document.domain = q.mce_rdomain;
 123          }
 124  
 125          // Find window & API.
 126          window.tinymce = w.tinymce;
 127          window.tinyMCE = w.tinyMCE;
 128          t.editor = tinymce.EditorManager.activeEditor;
 129  
 130          t.setup();
 131      },
 132  
 133      getWin : function() {
 134          return window.dialogArguments || opener || parent || top;
 135      },
 136  
 137      setup : function() {
 138          var t = this, a, ed = t.editor, g, columns, link, order, orderby;
 139          if ( ! t.mcemode ) {
 140              return;
 141          }
 142  
 143          t.el = ed.selection.getNode();
 144  
 145          if ( t.el.nodeName !== 'IMG' || ! ed.dom.hasClass(t.el, 'wpGallery') ) {
 146              if ( ( g = ed.dom.select('img.wpGallery') ) && g[0] ) {
 147                  t.el = g[0];
 148              } else {
 149                  if ( getUserSetting('galfile') === '1' ) {
 150                      t.I('linkto-file').checked = 'checked';
 151                  }
 152                  if ( getUserSetting('galdesc') === '1' ) {
 153                      t.I('order-desc').checked = 'checked';
 154                  }
 155                  if ( getUserSetting('galcols') ) {
 156                      t.I('columns').value = getUserSetting('galcols');
 157                  }
 158                  if ( getUserSetting('galord') ) {
 159                      t.I('orderby').value = getUserSetting('galord');
 160                  }
 161                  jQuery('#insert-gallery').show();
 162                  return;
 163              }
 164          }
 165  
 166          a = ed.dom.getAttrib(t.el, 'title');
 167          a = ed.dom.decode(a);
 168  
 169          if ( a ) {
 170              jQuery('#update-gallery').show();
 171              t.is_update = true;
 172  
 173              columns = a.match(/columns=['"]([0-9]+)['"]/);
 174              link = a.match(/link=['"]([^'"]+)['"]/i);
 175              order = a.match(/order=['"]([^'"]+)['"]/i);
 176              orderby = a.match(/orderby=['"]([^'"]+)['"]/i);
 177  
 178              if ( link && link[1] ) {
 179                  t.I('linkto-file').checked = 'checked';
 180              }
 181              if ( order && order[1] ) {
 182                  t.I('order-desc').checked = 'checked';
 183              }
 184              if ( columns && columns[1] ) {
 185                  t.I('columns').value = '' + columns[1];
 186              }
 187              if ( orderby && orderby[1] ) {
 188                  t.I('orderby').value = orderby[1];
 189              }
 190          } else {
 191              jQuery('#insert-gallery').show();
 192          }
 193      },
 194  
 195      update : function() {
 196          var t = this, ed = t.editor, all = '', s;
 197  
 198          if ( ! t.mcemode || ! t.is_update ) {
 199              s = '[gallery' + t.getSettings() + ']';
 200              t.getWin().send_to_editor(s);
 201              return;
 202          }
 203  
 204          if ( t.el.nodeName !== 'IMG' ) {
 205              return;
 206          }
 207  
 208          all = ed.dom.decode( ed.dom.getAttrib( t.el, 'title' ) );
 209          all = all.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi, '');
 210          all += t.getSettings();
 211  
 212          ed.dom.setAttrib(t.el, 'title', all);
 213          t.getWin().tb_remove();
 214      },
 215  
 216      getSettings : function() {
 217          var I = this.I, s = '';
 218  
 219          if ( I('linkto-file').checked ) {
 220              s += ' link="file"';
 221              setUserSetting('galfile', '1');
 222          }
 223  
 224          if ( I('order-desc').checked ) {
 225              s += ' order="DESC"';
 226              setUserSetting('galdesc', '1');
 227          }
 228  
 229          if ( I('columns').value !== 3 ) {
 230              s += ' columns="' + I('columns').value + '"';
 231              setUserSetting('galcols', I('columns').value);
 232          }
 233  
 234          if ( I('orderby').value !== 'menu_order' ) {
 235              s += ' orderby="' + I('orderby').value + '"';
 236              setUserSetting('galord', I('orderby').value);
 237          }
 238  
 239          return s;
 240      }
 241  };


Generated: Sat Nov 23 01:00:02 2024 Cross-referenced by PHPXref 0.7.1