(.*)<\/p>\[\/caption\]$/);
+ if (caption[1]) {
+ f.caption.value = caption[1];
+ }
+
+ // Extract the alignment.
+ var align = tag.match(/^\[caption align=\"(.*)\"\].*\[\/caption\]$/);
+ if (align[1]) {
+ f.align.value = align[1];
+ }
+ }
+ },
+
+ insert : function() {
+ var ed = tinyMCEPopup.editor;
+ var node = ed.selection.getNode();
+ var p = ed.dom.getParents(node, 'DIV');
+ var align = document.forms[0].align.value;
+ var caption = document.forms[0].caption.value;
+ var image;
+ var tag;
+ var replace = false;
+ // If we're inside an existing caption...
+ if (p[0] && ed.dom.hasClass(p[0], 'caption-inner')
+ && p[1] && ed.dom.hasClass(p[1], 'caption')) {
+ replace = true;
+ // Recall the original [caption] tag.
+ tag = Drupal.captionFilter.toTag(p[1].outerHTML);
+ // Select the outer DIV so we can replace the entire thing.
+ ed.selection.select(p[1]);
+ // If we're in an existing caption, parse it from the [caption] tag.
+ var parse = tag.match(/^\[caption.*\](\)(.*)<\/p>\[\/caption\]$/);
+ if (parse[1]) {
+ image = parse[1];
+ }
+ }
+ // Get the image HTML.
+ else if (node.nodeName === 'IMG') {
+ // If we're on the image, just use it.
+ image = node.outerHTML;
+ }
+ var newtag = '[caption';
+ if (align == 'right' || align == 'left') {
+ newtag += ' align="' + align + '"';
+ }
+ newtag += ']' + image + '
' + caption + '
' + '[/caption]';
+
+ // Create the new [caption] tag.
+
+ if (replace === true){
+ ed.dom.remove(p[1], false);
+ ed.execCommand('mceReplaceContent', false, newtag);
+
+ } else {
+ ed.execCommand('mceReplaceContent', false, newtag);
+ }
+ tinyMCEPopup.close();
+ }
+};
+
+tinyMCEPopup.onInit.add(CaptionFilterButton.init, CaptionFilterButton);
diff --git a/js/caption-filter-tinymce-button.tpl.php b/js/caption-filter-tinymce-button.tpl.php
new file mode 100644
index 0000000..7241414
--- /dev/null
+++ b/js/caption-filter-tinymce-button.tpl.php
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/js/caption-filter-tinymce.js b/js/caption-filter-tinymce.js
index 8e26f7b..d266c09 100644
--- a/js/caption-filter-tinymce.js
+++ b/js/caption-filter-tinymce.js
@@ -9,11 +9,47 @@
* @see http://core.svn.wordpress.org/branches/3.2/wp-admin/js/editor.dev.js
*/
(function() {
+ // Load the plugin-specific language pack.
+ tinymce.PluginManager.requireLangPack('captionfilter');
+
tinymce.create('tinymce.plugins.CaptionFilter', {
init : function(ed, url) {
var t = this;
t.url = url;
+
+ // Register the command.
+ ed.addCommand('CaptionFilter', function() {
+ ed.windowManager.open({
+ file : Drupal.settings.basePath + 'index.php?q=caption_filter/tinymce',
+ width : 400 + parseInt(ed.getLang('captionfilter.delta_width', 0)),
+ height : 200 + parseInt(ed.getLang('captionfilter.delta_height', 0)),
+ inline : 1
+ }, {
+ plugin_url : url
+ });
+ });
+
+ // Register the button.
+ ed.addButton('captionfilter', {
+ title : 'captionfilter.desc',
+ cmd : 'CaptionFilter',
+ image : url + '/caption-filter.gif'
+ });
+
+ // Add a handler to activate/deactivate the button.
+ ed.onNodeChange.add(function(ed, command, node) {
+ var p = ed.dom.getParent(node, 'DIV');
+ var selection = ed.selection.getContent();
+
+ // Enable if an image is selected, or if inside an existing caption.
+ command.setDisabled('captionfilter',
+ !(node.nodeName === 'IMG' && selection) &&
+ !(p && ed.dom.hasClass(p, 'caption-inner'))
+ );
+ // Light up the button if inside an existing caption.
+ command.setActive('captionfilter', p && ed.dom.hasClass(p, 'caption-inner'));
+ });
function _do_filter(ed, o) {
o.content = Drupal.captionFilter.toHTML(o.content, 'tinymce');
@@ -30,10 +66,6 @@
// Resize the caption wrapper when the image is soft-resized by the user.
ed.onMouseUp.add(function(ed, e) {
- // Webkit (Safari/Chrome) and Opera currently don't have resize handles.
- if (tinymce.isWebKit || tinymce.isOpera)
- return;
-
var img = ed.selection.getNode();
if (img.nodeName == 'IMG') {
window.setTimeout(function(){
@@ -107,7 +139,7 @@
align = cmd.substr(7).toLowerCase();
wrapperClass = 'caption-' + align;
ed.dom.addClass(captionWrapper, wrapperClass);
-
+
if (align == 'center')
ed.dom.addClass(captionWrapper, 'mceIEcenter');
else
diff --git a/js/langs/en.js b/js/langs/en.js
new file mode 100644
index 0000000..f686d2c
--- /dev/null
+++ b/js/langs/en.js
@@ -0,0 +1,3 @@
+tinyMCE.addI18n('en.captionfilter', {
+ desc : 'Add a caption to an image',
+});
diff --git a/js/langs/fr.js b/js/langs/fr.js
new file mode 100644
index 0000000..39090d6
--- /dev/null
+++ b/js/langs/fr.js
@@ -0,0 +1,3 @@
+tinyMCE.addI18n('fr.captionfilter', {
+ desc : 'Ajouter une légende à une image',
+});