-1){var n="",m;if(Links[o].newWin==1){n=' target="_blank"'}m='"+Links[o].display+" ";p.selectedIndex=0;edInsertContent(j.Canvas,m)}else{p.selectedIndex=0}};j.edInsertTag=function(o){if(document.selection){j.Canvas.focus();d=document.selection.createRange();if(d.text.length>0){d.text=j.Buttons[o].tagStart+d.text+j.Buttons[o].tagEnd}else{if(!j.edCheckOpenTags(o)||j.Buttons[o].tagEnd==""){d.text=j.Buttons[o].tagStart;j.edAddTag(o)}else{d.text=j.Buttons[o].tagEnd;j.edRemoveTag(o)}}j.Canvas.focus()}else{if(j.Canvas.selectionStart||j.Canvas.selectionStart=="0"){var n=j.Canvas.selectionStart,m=j.Canvas.selectionEnd,q=m,p=j.Canvas.scrollTop;if(n!=m){j.Canvas.value=j.Canvas.value.substring(0,n)+j.Buttons[o].tagStart+j.Canvas.value.substring(n,m)+j.Buttons[o].tagEnd+j.Canvas.value.substring(m,j.Canvas.value.length);q+=j.Buttons[o].tagStart.length+j.Buttons[o].tagEnd.length}else{if(!j.edCheckOpenTags(o)||j.Buttons[o].tagEnd==""){j.Canvas.value=j.Canvas.value.substring(0,n)+j.Buttons[o].tagStart+j.Canvas.value.substring(m,j.Canvas.value.length);j.edAddTag(o);q=n+j.Buttons[o].tagStart.length}else{j.Canvas.value=j.Canvas.value.substring(0,n)+j.Buttons[o].tagEnd+j.Canvas.value.substring(m,j.Canvas.value.length);j.edRemoveTag(o);q=n+j.Buttons[o].tagEnd.length}}j.Canvas.focus();j.Canvas.selectionStart=q;j.Canvas.selectionEnd=q;j.Canvas.scrollTop=p}else{if(!j.edCheckOpenTags(o)||j.Buttons[o].tagEnd==""){j.Canvas.value+=Buttons[o].tagStart;j.edAddTag(o)}else{j.Canvas.value+=Buttons[o].tagEnd;j.edRemoveTag(o)}j.Canvas.focus()}}};this.edInsertLink=function(o,n){if(!n){n="http://"}if(!j.edCheckOpenTags(o)){var m=prompt(quicktagsL10n.enterURL,n);if(m){j.Buttons[o].tagStart='';j.edInsertTag(o)}}else{j.edInsertTag(o)}};this.edInsertImage=function(){var i=prompt(quicktagsL10n.enterImageURL,"http://");if(i){i=' ';edInsertContent(j.Canvas,i)}};j.Buttons[j.Buttons.length]=new edButton(a+"_strong","b",""," ","b");j.Buttons[j.Buttons.length]=new edButton(a+"_em","i",""," ","i");j.Buttons[j.Buttons.length]=new edButton(a+"_link","link",""," ","a");j.Buttons[j.Buttons.length]=new edButton(a+"_block","b-quote","\n\n"," \n\n","q");j.Buttons[j.Buttons.length]=new edButton(a+"_del","del",'',"","d");j.Buttons[j.Buttons.length]=new edButton(a+"_ins","ins",''," ","s");j.Buttons[j.Buttons.length]=new edButton(a+"_img","img","","","m",-1);j.Buttons[j.Buttons.length]=new edButton(a+"_ul","ul","\n\n","u");j.Buttons[j.Buttons.length]=new edButton(a+"_ol","ol","\n"," \n\n","o");j.Buttons[j.Buttons.length]=new edButton(a+"_li","li","\t"," \n","l");j.Buttons[j.Buttons.length]=new edButton(a+"_code","code","","
","c");j.Buttons[j.Buttons.length]=new edButton(a+"_more","more","","","t",-1);e=document.createElement("div");e.id=a+"_qtags";h=' ';for(g=0;g ';h+='
';e.innerHTML=h;k.parentNode.insertBefore(e,k)};
\ No newline at end of file
+var edButtons=new Array(),edLinks=new Array(),edOpenTags=new Array(),now=new Date(),datetime;function edButton(f,e,c,b,a,d){this.id=f;this.display=e;this.tagStart=c;this.tagEnd=b;this.access=a;this.open=d}function zeroise(b,a){var c=b.toString();if(b<0){c=c.substr(1,c.length)}while(c.length","","b");edButtons[edButtons.length]=new edButton("ed_em","i",""," ","i");edButtons[edButtons.length]=new edButton("ed_link","link",""," ","a");edButtons[edButtons.length]=new edButton("ed_block","b-quote","\n\n"," \n\n","q");edButtons[edButtons.length]=new edButton("ed_del","del",'',"","d");edButtons[edButtons.length]=new edButton("ed_ins","ins",''," ","s");edButtons[edButtons.length]=new edButton("ed_img","img","","","m",-1);edButtons[edButtons.length]=new edButton("ed_ul","ul","\n\n","u");edButtons[edButtons.length]=new edButton("ed_ol","ol","\n"," \n\n","o");edButtons[edButtons.length]=new edButton("ed_li","li","\t"," \n","l");edButtons[edButtons.length]=new edButton("ed_code","code","","
","c");edButtons[edButtons.length]=new edButton("ed_more","more","","","t",-1);function edLink(){this.display="";this.URL="";this.newWin=0}edLinks[edLinks.length]=new edLink("WordPress","http://wordpress.org/");edLinks[edLinks.length]=new edLink("alexking.org","http://www.alexking.org/");function edShowButton(b,a){if(b.id=="ed_img"){document.write(' ')}else{if(b.id=="ed_link"){document.write(' ')}else{document.write(' ')}}}function edShowLinks(){var a=''+quicktagsL10n.quickLinks+" ",b;for(b=0;b'+edLinks[b].display+""}a+=" ";document.write(a)}function edAddTag(a){if(edButtons[a].tagEnd!=""){edOpenTags[edOpenTags.length]=a;document.getElementById(edButtons[a].id).value="/"+document.getElementById(edButtons[a].id).value}}function edRemoveTag(b){for(var a=0;a0){return true}else{return false}}function edCloseAllTags(){var a=edOpenTags.length,b;for(b=0;b-1){var b="",a;if(edLinks[c].newWin==1){b=' target="_blank"'}a=' "+edLinks[c].display+" ";d.selectedIndex=0;edInsertContent(edCanvas,a)}else{d.selectedIndex=0}}function edSpell(c){var e="",d,b,a;if(document.selection){c.focus();d=document.selection.createRange();if(d.text.length>0){e=d.text}}else{if(c.selectionStart||c.selectionStart=="0"){b=c.selectionStart;a=c.selectionEnd;if(b!=a){e=c.value.substring(b,a)}}}if(e==""){e=prompt(quicktagsL10n.wordLookup,"")}if(e!==null&&/^\w[\w ]*$/.test(e)){window.open("http://www.answers.com/"+escape(e))}}function edToolbar(){document.write('');for(var a=0;a ');document.write(' ');document.write("
")}function edInsertTag(d,c){if(document.selection){d.focus();var e=document.selection.createRange();if(e.text.length>0){e.text=edButtons[c].tagStart+e.text+edButtons[c].tagEnd}else{if(!edCheckOpenTags(c)||edButtons[c].tagEnd==""){e.text=edButtons[c].tagStart;edAddTag(c)}else{e.text=edButtons[c].tagEnd;edRemoveTag(c)}}d.focus()}else{if(d.selectionStart||d.selectionStart=="0"){var b=d.selectionStart,a=d.selectionEnd,g=a,f=d.scrollTop;if(b!=a){d.value=d.value.substring(0,b)+edButtons[c].tagStart+d.value.substring(b,a)+edButtons[c].tagEnd+d.value.substring(a,d.value.length);g+=edButtons[c].tagStart.length+edButtons[c].tagEnd.length}else{if(!edCheckOpenTags(c)||edButtons[c].tagEnd==""){d.value=d.value.substring(0,b)+edButtons[c].tagStart+d.value.substring(a,d.value.length);edAddTag(c);g=b+edButtons[c].tagStart.length}else{d.value=d.value.substring(0,b)+edButtons[c].tagEnd+d.value.substring(a,d.value.length);edRemoveTag(c);g=b+edButtons[c].tagEnd.length}}d.focus();d.selectionStart=g;d.selectionEnd=g;d.scrollTop=f}else{if(!edCheckOpenTags(c)||edButtons[c].tagEnd==""){d.value+=edButtons[c].tagStart;edAddTag(c)}else{d.value+=edButtons[c].tagEnd;edRemoveTag(c)}d.focus()}}}function edInsertContent(d,c){var e,b,a,f;if(document.selection){d.focus();e=document.selection.createRange();e.text=c;d.focus()}else{if(d.selectionStart||d.selectionStart=="0"){b=d.selectionStart;a=d.selectionEnd;f=d.scrollTop;d.value=d.value.substring(0,b)+c+d.value.substring(a,d.value.length);d.focus();d.selectionStart=b+c.length;d.selectionEnd=b+c.length;d.scrollTop=f}else{d.value+=c;d.focus()}}}function edInsertLink(d,c,b){if("object"==typeof(wpLink)){wpLink.open()}else{if(!b){b="http://"}if(!edCheckOpenTags(c)){var a=prompt(quicktagsL10n.enterURL,b);if(a){edButtons[c].tagStart='';edInsertTag(d,c)}}else{edInsertTag(d,c)}}}function edInsertImage(b){var a=prompt(quicktagsL10n.enterImageURL,"http://");if(a){a=' ';edInsertContent(b,a)}}var QTags=function(a,c,b,f){var j=this,k=document.getElementById(b),g,l,e,h,d;j.Buttons=[];j.Links=[];j.OpenTags=[];j.Canvas=document.getElementById(c);if(!j.Canvas||!k){return}f=(typeof f!="undefined")?","+f+",":"";j.edShowButton=function(n,m){if(f&&(f.indexOf(","+n.display+",")!=-1)){return""}else{if(n.id==a+"_img"){return' '}else{if(n.id==a+"_link"){return' '}else{return' '}}}};j.edAddTag=function(i){if(j.Buttons[i].tagEnd!=""){j.OpenTags[j.OpenTags.length]=i;document.getElementById(j.Buttons[i].id).value="/"+document.getElementById(j.Buttons[i].id).value}};j.edRemoveTag=function(i){for(g=0;g0){return true}else{return false}};this.edCloseAllTags=function(){var i=j.OpenTags.length;for(var m=0;m-1){var n="",m;if(Links[o].newWin==1){n=' target="_blank"'}m='"+Links[o].display+" ";p.selectedIndex=0;edInsertContent(j.Canvas,m)}else{p.selectedIndex=0}};j.edInsertTag=function(o){if(document.selection){j.Canvas.focus();d=document.selection.createRange();if(d.text.length>0){d.text=j.Buttons[o].tagStart+d.text+j.Buttons[o].tagEnd}else{if(!j.edCheckOpenTags(o)||j.Buttons[o].tagEnd==""){d.text=j.Buttons[o].tagStart;j.edAddTag(o)}else{d.text=j.Buttons[o].tagEnd;j.edRemoveTag(o)}}j.Canvas.focus()}else{if(j.Canvas.selectionStart||j.Canvas.selectionStart=="0"){var n=j.Canvas.selectionStart,m=j.Canvas.selectionEnd,q=m,p=j.Canvas.scrollTop;if(n!=m){j.Canvas.value=j.Canvas.value.substring(0,n)+j.Buttons[o].tagStart+j.Canvas.value.substring(n,m)+j.Buttons[o].tagEnd+j.Canvas.value.substring(m,j.Canvas.value.length);q+=j.Buttons[o].tagStart.length+j.Buttons[o].tagEnd.length}else{if(!j.edCheckOpenTags(o)||j.Buttons[o].tagEnd==""){j.Canvas.value=j.Canvas.value.substring(0,n)+j.Buttons[o].tagStart+j.Canvas.value.substring(m,j.Canvas.value.length);j.edAddTag(o);q=n+j.Buttons[o].tagStart.length}else{j.Canvas.value=j.Canvas.value.substring(0,n)+j.Buttons[o].tagEnd+j.Canvas.value.substring(m,j.Canvas.value.length);j.edRemoveTag(o);q=n+j.Buttons[o].tagEnd.length}}j.Canvas.focus();j.Canvas.selectionStart=q;j.Canvas.selectionEnd=q;j.Canvas.scrollTop=p}else{if(!j.edCheckOpenTags(o)||j.Buttons[o].tagEnd==""){j.Canvas.value+=Buttons[o].tagStart;j.edAddTag(o)}else{j.Canvas.value+=Buttons[o].tagEnd;j.edRemoveTag(o)}j.Canvas.focus()}}};this.edInsertLink=function(o,n){if(!n){n="http://"}if(!j.edCheckOpenTags(o)){var m=prompt(quicktagsL10n.enterURL,n);if(m){j.Buttons[o].tagStart='';j.edInsertTag(o)}}else{j.edInsertTag(o)}};this.edInsertImage=function(){var i=prompt(quicktagsL10n.enterImageURL,"http://");if(i){i=' ';edInsertContent(j.Canvas,i)}};j.Buttons[j.Buttons.length]=new edButton(a+"_strong","b",""," ","b");j.Buttons[j.Buttons.length]=new edButton(a+"_em","i",""," ","i");j.Buttons[j.Buttons.length]=new edButton(a+"_link","link",""," ","a");j.Buttons[j.Buttons.length]=new edButton(a+"_block","b-quote","\n\n"," \n\n","q");j.Buttons[j.Buttons.length]=new edButton(a+"_del","del",'',"","d");j.Buttons[j.Buttons.length]=new edButton(a+"_ins","ins",''," ","s");j.Buttons[j.Buttons.length]=new edButton(a+"_img","img","","","m",-1);j.Buttons[j.Buttons.length]=new edButton(a+"_ul","ul","\n\n","u");j.Buttons[j.Buttons.length]=new edButton(a+"_ol","ol","\n"," \n\n","o");j.Buttons[j.Buttons.length]=new edButton(a+"_li","li","\t"," \n","l");j.Buttons[j.Buttons.length]=new edButton(a+"_code","code","","
","c");j.Buttons[j.Buttons.length]=new edButton(a+"_more","more","","","t",-1);e=document.createElement("div");e.id=a+"_qtags";h=' ';for(g=0;g ';h+='
';e.innerHTML=h;k.parentNode.insertBefore(e,k)};
\ No newline at end of file
diff --git a/wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin.dev.js b/wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin.dev.js
index bdc63ddc5b..4be9c3faf4 100644
--- a/wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin.dev.js
+++ b/wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin.dev.js
@@ -8,18 +8,56 @@
* Contributing: http://tinymce.moxiecode.com/contributing
*/
-(function($) {
- var wpDialogFn = function( fn ) {
- return function() {
- if ( this.features.wpDialog )
- return fn.apply( this, arguments );
- else
- return this.parent.apply( this, arguments );
- };
- };
-
+(function() {
tinymce.create('tinymce.plugins.WPDialogs', {
init : function(ed, url) {
+ tinymce.create('tinymce.WPWindowManager:tinymce.InlineWindowManager', {
+ WPWindowManager : function(ed) {
+ this.parent(ed);
+ },
+
+ open : function(f, p) {
+ var t = this, element;
+
+ if ( ! f.wpDialog )
+ return this.parent( f, p );
+ else if ( ! f.id )
+ return;
+
+ element = jQuery('#' + f.id);
+ if ( ! element.length )
+ return;
+
+ t.features = f;
+ t.params = p;
+ t.onOpen.dispatch(t, f, p);
+ t.element = t.windows[ f.id ] = element;
+
+ // Store selection
+ t.bookmark = t.editor.selection.getBookmark(1);
+
+ // Create the dialog if necessary
+ if ( ! element.data('wpdialog') ) {
+ element.wpdialog({
+ title: f.title,
+ width: f.width,
+ height: f.height,
+ modal: true,
+ dialogClass: 'wp-dialog',
+ zIndex: 300000
+ });
+ }
+
+ element.wpdialog('open');
+ },
+ close : function() {
+ if ( ! this.features.wpDialog )
+ return this.parent.apply( this, arguments );
+
+ this.element.wpdialog('close');
+ }
+ });
+
// Replace window manager
ed.onBeforeRenderUI.add(function() {
ed.windowManager = new tinymce.WPWindowManager(ed);
@@ -36,62 +74,7 @@
};
}
});
-
- $(document).ready(function() {
- $.widget("wp.wpdialog", $.ui.dialog, {
- open: function() {
- // Initialize tinyMCEPopup if it exists.
- if ( tinyMCEPopup )
- tinyMCEPopup.init();
- // Open the dialog.
- $.ui.dialog.prototype.open.apply( this, arguments );
- // WebKit leaves focus in the TinyMCE editor unless we shift focus.
- this.element.focus();
- this._trigger('refresh');
- }
- });
- });
-
- tinymce.create('tinymce.WPWindowManager:tinymce.InlineWindowManager', {
- WPWindowManager : function(ed) {
- this.parent(ed);
- },
-
- open : function(f, p) {
- var t = this, element;
- // Can't use wpDialogFn here; this.features isn't set yet.
- if ( ! f.wpDialog )
- return this.parent( f, p );
- else if ( ! f.id )
- return;
-
- element = $('#' + f.id);
- if ( ! element.length )
- return;
-
- t.features = f;
- t.params = p;
- t.onOpen.dispatch(t, f, p);
- t.element = t.windows[ f.id ] = element;
-
- // Store selection
- t.bookmark = t.editor.selection.getBookmark(1);
-
- element.wpdialog({
- title: f.title,
- width: f.width,
- height: f.height,
- modal: true,
- dialogClass: 'wp-dialog',
- zIndex: 300000
- });
- },
- close : wpDialogFn(function() {
- this.element.wpdialog('close');
- })
- });
// Register plugin
tinymce.PluginManager.add('wpdialogs', tinymce.plugins.WPDialogs);
-})(jQuery);
-
+})();
diff --git a/wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin.js b/wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin.js
index fc621f13a9..1ba21e3ce3 100644
--- a/wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin.js
+++ b/wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin.js
@@ -1 +1 @@
-(function(b){var a=function(c){return function(){if(this.features.wpDialog){return c.apply(this,arguments)}else{return this.parent.apply(this,arguments)}}};tinymce.create("tinymce.plugins.WPDialogs",{init:function(c,d){c.onBeforeRenderUI.add(function(){c.windowManager=new tinymce.WPWindowManager(c)})},getInfo:function(){return{longname:"WPDialogs",author:"WordPress",authorurl:"http://wordpress.org",infourl:"http://wordpress.org",version:"0.1"}}});b(document).ready(function(){b.widget("wp.wpdialog",b.ui.dialog,{open:function(){if(tinyMCEPopup){tinyMCEPopup.init()}b.ui.dialog.prototype.open.apply(this,arguments);this.element.focus();this._trigger("refresh")}})});tinymce.create("tinymce.WPWindowManager:tinymce.InlineWindowManager",{WPWindowManager:function(c){this.parent(c)},open:function(e,g){var d=this,c;if(!e.wpDialog){return this.parent(e,g)}else{if(!e.id){return}}c=b("#"+e.id);if(!c.length){return}d.features=e;d.params=g;d.onOpen.dispatch(d,e,g);d.element=d.windows[e.id]=c;d.bookmark=d.editor.selection.getBookmark(1);c.wpdialog({title:e.title,width:e.width,height:e.height,modal:true,dialogClass:"wp-dialog",zIndex:300000})},close:a(function(){this.element.wpdialog("close")})});tinymce.PluginManager.add("wpdialogs",tinymce.plugins.WPDialogs)})(jQuery);
\ No newline at end of file
+(function(){tinymce.create("tinymce.plugins.WPDialogs",{init:function(a,b){tinymce.create("tinymce.WPWindowManager:tinymce.InlineWindowManager",{WPWindowManager:function(c){this.parent(c)},open:function(e,g){var d=this,c;if(!e.wpDialog){return this.parent(e,g)}else{if(!e.id){return}}c=jQuery("#"+e.id);if(!c.length){return}d.features=e;d.params=g;d.onOpen.dispatch(d,e,g);d.element=d.windows[e.id]=c;d.bookmark=d.editor.selection.getBookmark(1);if(!c.data("wpdialog")){c.wpdialog({title:e.title,width:e.width,height:e.height,modal:true,dialogClass:"wp-dialog",zIndex:300000})}c.wpdialog("open")},close:function(){if(!this.features.wpDialog){return this.parent.apply(this,arguments)}this.element.wpdialog("close")}});a.onBeforeRenderUI.add(function(){a.windowManager=new tinymce.WPWindowManager(a)})},getInfo:function(){return{longname:"WPDialogs",author:"WordPress",authorurl:"http://wordpress.org",infourl:"http://wordpress.org",version:"0.1"}}});tinymce.PluginManager.add("wpdialogs",tinymce.plugins.WPDialogs)})();
\ No newline at end of file
diff --git a/wp-includes/js/tinymce/plugins/wpdialogs/js/wpdialog.dev.js b/wp-includes/js/tinymce/plugins/wpdialogs/js/wpdialog.dev.js
new file mode 100644
index 0000000000..620213fe85
--- /dev/null
+++ b/wp-includes/js/tinymce/plugins/wpdialogs/js/wpdialog.dev.js
@@ -0,0 +1,23 @@
+(function($){
+ $.widget("wp.wpdialog", $.ui.dialog, {
+ open: function() {
+ var ed;
+
+ // Initialize tinyMCEPopup if it exists and is the editor is active.
+ if ( tinyMCEPopup && typeof tinyMCE != 'undefined' && ( ed = tinyMCE.activeEditor ) && !ed.isHidden() ) {
+ tinyMCEPopup.init();
+ }
+
+ // Add beforeOpen event.
+ if ( this._isOpen || false === this._trigger('beforeOpen') ) {
+ return;
+ }
+
+ // Open the dialog.
+ $.ui.dialog.prototype.open.apply( this, arguments );
+ // WebKit leaves focus in the TinyMCE editor unless we shift focus.
+ this.element.focus();
+ this._trigger('refresh');
+ }
+ });
+})(jQuery);
diff --git a/wp-includes/js/tinymce/plugins/wpdialogs/js/wpdialog.js b/wp-includes/js/tinymce/plugins/wpdialogs/js/wpdialog.js
new file mode 100644
index 0000000000..bf6f05ce17
--- /dev/null
+++ b/wp-includes/js/tinymce/plugins/wpdialogs/js/wpdialog.js
@@ -0,0 +1 @@
+(function(a){a.widget("wp.wpdialog",a.ui.dialog,{open:function(){var b;if(tinyMCEPopup&&typeof tinyMCE!="undefined"&&(b=tinyMCE.activeEditor)&&!b.isHidden()){tinyMCEPopup.init()}if(this._isOpen||false===this._trigger("beforeOpen")){return}a.ui.dialog.prototype.open.apply(this,arguments);this.element.focus();this._trigger("refresh")}})})(jQuery);
\ No newline at end of file
diff --git a/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js b/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js
index 8f12ebec29..233c491638 100644
--- a/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js
+++ b/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js
@@ -9,6 +9,8 @@ var wpLink;
riverBottomThreshold: 5,
keySensitivity: 100,
lastSearch: '',
+ textarea: edCanvas,
+
init : function() {
inputs.dialog = $('#wp-link');
inputs.submit = $('#wp-link-submit');
@@ -31,7 +33,7 @@ var wpLink;
wpLink.update();
e.preventDefault();
});
- $('#wp-link-cancel').click( wpLink.cancel );
+ $('#wp-link-cancel').click( wpLink.close );
$('#internal-toggle').click( wpLink.toggleInternalLinking );
rivers.elements.bind('river-select', wpLink.updateFields );
@@ -39,16 +41,62 @@ var wpLink;
inputs.search.keyup( wpLink.searchInternalLinks );
inputs.dialog.bind('wpdialogrefresh', wpLink.refresh);
+ inputs.dialog.bind('wpdialogbeforeopen', wpLink.beforeOpen);
+ inputs.dialog.bind('wpdialogclose', wpLink.onClose);
+ },
+
+ beforeOpen : function() {
+ wpLink.range = null;
+
+ if ( ! wpLink.isMCE() && document.selection ) {
+ wpLink.textarea.focus();
+ wpLink.range = document.selection.createRange();
+ }
+ },
+
+ open : function() {
+ // Initialize the dialog if necessary (html mode).
+ if ( ! inputs.dialog.data('wpdialog') ) {
+ inputs.dialog.wpdialog({
+ title: wpLinkL10n.title,
+ width: 480,
+ height: 'auto',
+ modal: true,
+ dialogClass: 'wp-dialog',
+ zIndex: 300000
+ });
+ }
+
+ inputs.dialog.wpdialog('open');
+ },
+
+ isMCE : function() {
+ return tinyMCEPopup && ( ed = tinyMCEPopup.editor ) && ! ed.isHidden();
},
refresh : function() {
- var e;
- ed = tinyMCEPopup.editor;
-
// Refresh rivers (clear links, check visibility)
rivers.search.refresh();
rivers.recent.refresh();
+ if ( wpLink.isMCE() )
+ wpLink.mceRefresh();
+ else
+ wpLink.setDefaultValues();
+
+ // Focus the URL field and highlight its contents.
+ // If this is moved above the selection changes,
+ // IE will show a flashing cursor over the dialog.
+ inputs.url.focus()[0].select();
+ // Load the most recent results if this is the first time opening the panel.
+ if ( ! rivers.recent.ul.children().length )
+ rivers.recent.ajax();
+ },
+
+ mceRefresh : function() {
+ var e;
+ ed = tinyMCEPopup.editor;
+
tinyMCEPopup.restoreSelection();
// If link exists, select proper values.
@@ -65,31 +113,106 @@ var wpLink;
// If there's no link, set the default values.
} else {
wpLink.setDefaultValues();
- // Update save prompt.
- inputs.submit.val( wpLinkL10n.save );
}
tinyMCEPopup.storeSelection();
- // Focus the URL field and highlight its contents.
- // If this is moved above the selection changes,
- // IE will show a flashing cursor over the dialog.
- inputs.url.focus()[0].select();
- // Load the most recent results if this is the first time opening the panel.
- if ( ! rivers.recent.ul.children().length )
- rivers.recent.ajax();
},
- cancel : function() {
- tinyMCEPopup.close();
+ close : function() {
+ if ( wpLink.isMCE() )
+ tinyMCEPopup.close();
+ else
+ inputs.dialog.wpdialog('close');
+ },
+
+ onClose: function() {
+ if ( ! wpLink.isMCE() ) {
+ wpLink.textarea.focus();
+ if ( wpLink.range ) {
+ wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
+ wpLink.range.select();
+ }
+ }
+ },
+
+ getAttrs : function() {
+ return {
+ href : inputs.url.val(),
+ title : inputs.title.val(),
+ target : inputs.openInNewTab.attr('checked') ? '_blank' : ''
+ };
},
update : function() {
+ if ( wpLink.isMCE() )
+ wpLink.mceUpdate();
+ else
+ wpLink.htmlUpdate();
+ },
+
+ htmlUpdate : function() {
+ var attrs, html, start, end, cursor,
+ textarea = wpLink.textarea;
+
+ if ( ! textarea )
+ return;
+
+ attrs = wpLink.getAttrs();
+
+ // If there's no href, return.
+ if ( ! attrs.href || attrs.href == 'http://' )
+ return;
+
+ // Build HTML
+ html = '';
+
+ // Insert HTML
+ // W3C
+ if ( typeof textarea.selectionStart !== 'undefined' ) {
+ start = textarea.selectionStart;
+ end = textarea.selectionEnd;
+ selection = textarea.value.substring( start, end );
+ html = html + selection + ' ';
+ cursor = start + html.length;
+
+ // If no next is selected, place the cursor inside the closing tag.
+ if ( start == end )
+ cursor -= ' '.length;
+
+ textarea.value = textarea.value.substring( 0, start )
+ + html
+ + textarea.value.substring( end, textarea.value.length );
+
+ // Update cursor position
+ textarea.selectionStart = textarea.selectionEnd = cursor;
+
+ // IE
+ // Note: If no text is selected, IE will not place the cursor
+ // inside the closing tag.
+ } else if ( document.selection && wpLink.range ) {
+ textarea.focus();
+ wpLink.range.text = html + wpLink.range.text + '