diff --git a/Source/MooEditable/MooEditable.js b/Source/MooEditable/MooEditable.js index 4f61540..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){ @@ -132,7 +133,6 @@ this.MooEditable = new Class({ height: dimensions.y } }); - this.toolbar = new MooEditable.UI.Toolbar({ onItemAction: function(){ var args = Array.from(arguments); @@ -198,7 +198,7 @@ this.MooEditable = new Class({ }); }); }); - + // contentWindow and document references this.win = this.iframe.contentWindow; this.doc = this.win.document; @@ -216,7 +216,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 +254,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 +617,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 +671,7 @@ this.MooEditable = new Class({ } val = el.get('html').replace(/\n\n/g, ''); } + return val; }, @@ -1507,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;