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