| 1 |
(function($) { |
| 2 |
var media = wp.media; |
| 3 |
|
| 4 |
// Wrap the render() function to append controls. |
| 5 |
media.view.Settings.Gallery = media.view.Settings.Gallery.extend({ |
| 6 |
render: function() { |
| 7 |
var $el = this.$el; |
| 8 |
|
| 9 |
media.view.Settings.prototype.render.apply( this, arguments ); |
| 10 |
|
| 11 |
if (Photonic_Admin_JS.shortcode !== 'gallery') { |
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
// Append the type template and update the settings. |
| 16 |
$el.append( media.template( 'photonic-editor-default' ) ); |
| 17 |
$el.find('.photonic-form .hint').remove(); |
| 18 |
|
| 19 |
//media.gallery.defaults.type = 'default'; // lil hack that lets media know there's a type attribute. |
| 20 |
//this.update.apply( this, ['type'] ); |
| 21 |
|
| 22 |
if (tinymce !== undefined && tinymce.activeEditor !== undefined && tinymce.activeEditor !== null && tinymce.activeEditor.selection !== undefined) { |
| 23 |
var node = tinymce.activeEditor.selection.getNode(); |
| 24 |
var shortcode = wp.mce.views.getText(node); |
| 25 |
var shortcodeObj = wp.shortcode.next(Photonic_Admin_JS.shortcode, shortcode); |
| 26 |
var attrs = shortcodeObj.shortcode.attrs.named; |
| 27 |
//var attrs = this.model.attributes; |
| 28 |
|
| 29 |
var gallery = this; |
| 30 |
|
| 31 |
$.each(attrs, function(name, value) { |
| 32 |
media.gallery.defaults[name] = ''; |
| 33 |
gallery.update.apply( gallery, [name] ); |
| 34 |
|
| 35 |
var field = $el.find('.photonic-form [name="' + name + '"]'); |
| 36 |
if (field.length > 0) { |
| 37 |
field = field[0]; |
| 38 |
if (field.nodeName === 'INPUT') { |
| 39 |
field.value = value; |
| 40 |
} |
| 41 |
else if (field.nodeName === 'SELECT') { |
| 42 |
var defaultValue = field.value; |
| 43 |
var options = field.children; |
| 44 |
var oneSelected = false; |
| 45 |
$.each(options, function(i, v) { |
| 46 |
options[i].selected = options[i].value === value; |
| 47 |
if (options[i].value === value) { |
| 48 |
oneSelected = true; |
| 49 |
} |
| 50 |
}); |
| 51 |
if (!oneSelected) { |
| 52 |
$.each(options, function(i, v) { |
| 53 |
options[i].selected = options[i].value === defaultValue; |
| 54 |
if (options[i].value === defaultValue) { |
| 55 |
return false; |
| 56 |
} |
| 57 |
}); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
}); |
| 62 |
|
| 63 |
var inputFields = $el.find('.photonic-form input, .photonic-form select'); |
| 64 |
$(inputFields).on('change', function() { |
| 65 |
var insertCode = '[' + Photonic_Admin_JS.shortcode + ' type="default"'; |
| 66 |
//var newCode = e.data; |
| 67 |
$.each(inputFields, function(idx, obj) { |
| 68 |
if (obj.value !== '') { |
| 69 |
insertCode += ' ' + obj.name + "='" + $('<div/>').text(decodeURIComponent(obj.value)).html() + "'"; |
| 70 |
} |
| 71 |
gallery.model.attributes[obj.name] = obj.value; |
| 72 |
}); |
| 73 |
insertCode += ']'; |
| 74 |
$(node).attr('data-wpview-text', encodeURIComponent(insertCode)); |
| 75 |
}); |
| 76 |
} |
| 77 |
return this; |
| 78 |
} |
| 79 |
}); |
| 80 |
})(jQuery); |
| 81 |
|