From e8c3cfd49e9305deddf7ba61e662612e843e2a46 Mon Sep 17 00:00:00 2001 From: Jo Carter Date: Fri, 11 May 2012 08:51:55 -0700 Subject: [PATCH 1/2] Fixing IE7 issue with latest version of MooTools --- Source/MooEditable/MooEditable.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/MooEditable/MooEditable.js b/Source/MooEditable/MooEditable.js index 4f61540..2a21fe8 100644 --- a/Source/MooEditable/MooEditable.js +++ b/Source/MooEditable/MooEditable.js @@ -132,7 +132,6 @@ this.MooEditable = new Class({ height: dimensions.y } }); - this.toolbar = new MooEditable.UI.Toolbar({ onItemAction: function(){ var args = Array.from(arguments); @@ -198,7 +197,7 @@ this.MooEditable = new Class({ }); }); }); - + // contentWindow and document references this.win = this.iframe.contentWindow; this.doc = this.win.document; @@ -216,7 +215,7 @@ this.MooEditable = new Class({ this.doc.open(); this.doc.write(docHTML); this.doc.close(); - + // Turn on Design Mode // IE fired load event twice if designMode is set (Browser.ie) ? this.doc.body.contentEditable = true : this.doc.designMode = 'On'; @@ -254,6 +253,7 @@ this.MooEditable = new Class({ focus: this.editorFocus.bind(this), blur: this.editorBlur.bind(this) }); + this.win.addEvents({ focus: this.editorFocus.bind(this), blur: this.editorBlur.bind(this) @@ -616,7 +616,10 @@ this.MooEditable = new Class({ protect.push(a); return ''; }); - this.doc.body.set('html', this.ensureRootElement(content)); + + this.doc.body.innerHTML = this.ensureRootElement(content); + //this.doc.body.set('html', this.ensureRootElement(content)); // breaks in IE7 with mootools 1.4.5 + return this; }, @@ -667,6 +670,7 @@ this.MooEditable = new Class({ } val = el.get('html').replace(/\n\n/g, ''); } + return val; }, From c11b64034e5b30c63c3aa659e15da03951b06441 Mon Sep 17 00:00:00 2001 From: Jo Carter Date: Thu, 19 Dec 2013 03:05:08 -0800 Subject: [PATCH 2/2] Adding ability to make external links open in new windows --- Source/MooEditable/MooEditable.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Source/MooEditable/MooEditable.js b/Source/MooEditable/MooEditable.js index 2a21fe8..1c73585 100644 --- a/Source/MooEditable/MooEditable.js +++ b/Source/MooEditable/MooEditable.js @@ -60,7 +60,8 @@ this.MooEditable = new Class({ html: '{BASEHREF}{EXTERNALCSS}', rootElement: 'p', baseURL: '', - dimensions: null + dimensions: null, + linksInNewWindow: false }, initialize: function(el, options){ @@ -1511,16 +1512,26 @@ MooEditable.Actions = { dialogs: { alert: MooEditable.UI.AlertDialog.pass(MooEditable.Locale.get('selectTextHyperlink')), prompt: function(editor){ - return MooEditable.UI.PromptDialog(MooEditable.Locale.get('enterURL'), 'http://', function(url){ - editor.execute('createlink', false, url.trim()); + return MooEditable.UI.PromptDialog(MooEditable.Locale.get('enterURL') + ' (start with http:// for external URLs and / for internal URLs)', '', function(url){ + var url = url.trim(); + editor.execute('createlink', false, url); + + if (editor.options.linksInNewWindow) { + if (url && (url.contains('http://') || url.contains('https://'))) { + var node = editor.selection.getNode(); + node.set('target', '_blank'); + this.saveContent(); + } + } }); } }, command: function(){ var selection = this.selection; var dialogs = this.dialogs.createlink; - if (selection.isCollapsed()){ - var node = selection.getNode(); + var node = selection.getNode(); + + if (node.get('tag') == 'a' || selection.isCollapsed()){ if (node.get('tag') == 'a' && node.get('href')){ selection.selectNode(node); var prompt = dialogs.prompt;