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