From 4be88f57c99a6cb0a1bb1ad5b802df24b240e091 Mon Sep 17 00:00:00 2001
From: Jorrit Schippers <jorrit@161217.no-reply.drupal.org>
Date: Mon, 31 Oct 2011 08:18:37 +0100
Subject: [PATCH] Issue #1327010 by Jorrit: Fix reading the lightbox value from the tag when switching from plain text to TinyMCE

---
 drupalimage/editor_plugin.js |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drupalimage/editor_plugin.js b/drupalimage/editor_plugin.js
index 8887e3d..e3ba2a7 100644
--- a/drupalimage/editor_plugin.js
+++ b/drupalimage/editor_plugin.js
@@ -1,4 +1,4 @@
-(function() {
+(function(undef) {
   // Load plugin specific language pack.
   tinymce.PluginManager.requireLangPack('imagefield_assist');
 
@@ -28,7 +28,7 @@
           // Expand inline tag in alt attribute
           node.alt = decodeURIComponent(node.alt);
           var chunks = node.alt.split('|');
-          for (var i in chunks) {
+          for (var i = 0, l = chunks.length; i < l; i++) {
             chunks[i].replace(/([^=]+)=(.*)/g, function(o, property, value) {
               data[property] = value;
             });
@@ -84,16 +84,17 @@
       ed.onBeforeSetContent.add(function(ed, data) {
         data.content = data.content.replace(/\[imagefield_assist\|([^\[\]]+)\]/g, function(orig, match) {
           var node = {}, chunks = match.split('|');
-          for (var i in chunks) {
+          for (var i = 0, l = chunks.length; i < l; i++) {
             chunks[i].replace(/([^=]+)=(.*)/g, function(o, property, value) {
               node[property] = value;
             });
           }
           node.name = 'mceItemDrupalImage';
           node.src = Drupal.settings.basePath + 'index.php?q=imagefield_assist/preview/' + node.fid + '/' + node.preset;
-	  if (this.lightbox != '') light = '|lightbox=true';
-	  else light = '';
-          node.alt = 'fid=' + node.fid + '|preset=' + node.preset + light + '|title=' + node.title + '|desc=' + node.desc;
+          node.alt = 'fid=' + node.fid + '|preset=' + node.preset + '|title=' + node.title + '|desc=' + node.desc;
+          if (node.lightbox != undef && node.lightbox != '') {
+            node.alt += '|lightbox=true';
+          }
           if (node.link.indexOf(',') != -1) {
             var link = node.link.split(',', 2);
             node.alt += '|link=' + link[0] + '|url=' + link[1];
@@ -101,7 +102,7 @@
           else {
             node.alt += '|link=' + node.link;
           }
-          if (typeof node.url != 'undefined') {
+          if (node.url != undef) {
             node.alt += '|url=' + node.url;
           }
           node.alt = encodeURIComponent(node.alt);
-- 
1.7.4.1

