mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Editor API enhancement, first run (still needs some work), see #17144
git-svn-id: https://develop.svn.wordpress.org/trunk@18498 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -219,7 +219,7 @@
|
||||
});
|
||||
|
||||
ed.onSaveContent.add(function(ed, o) {
|
||||
if ( typeof(switchEditors) == 'object' ) {
|
||||
if ( ed.getParam('wpautop', true) && typeof(switchEditors) == 'object' ) {
|
||||
if ( ed.isHidden() )
|
||||
o.content = o.element.value;
|
||||
else
|
||||
@@ -421,3 +421,4 @@
|
||||
// Register plugin
|
||||
tinymce.PluginManager.add('wordpress', tinymce.plugins.WordPress);
|
||||
})();
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -32,11 +32,11 @@
|
||||
});
|
||||
|
||||
ed.addCommand('wpFullScreenInit', function() {
|
||||
var d = ed.getDoc(), b = d.body, fsed;
|
||||
var d, b, fsed;
|
||||
|
||||
// Only init the editor if necessary.
|
||||
if ( ed.id == 'wp_mce_fullscreen' )
|
||||
return;
|
||||
ed = tinymce.get('content');
|
||||
d = ed.getDoc();
|
||||
b = d.body;
|
||||
|
||||
tinyMCE.oldSettings = tinyMCE.settings; // Store old settings
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
|
||||
// Register buttons
|
||||
if ( 'undefined' != fullscreen ) {
|
||||
ed.addButton('fullscreen', {
|
||||
ed.addButton('wp_fullscreen', {
|
||||
title : 'fullscreen.desc',
|
||||
onclick : function(){ fullscreen.on(); }
|
||||
});
|
||||
|
||||
@@ -1 +1 @@
|
||||
(function(){tinymce.create("tinymce.plugins.wpFullscreenPlugin",{init:function(b,d){var e=this,h=0,f={},g=tinymce.DOM,a=false;b.addCommand("wpFullScreenClose",function(){if(b.getParam("wp_fullscreen_is_enabled")){g.win.setTimeout(function(){tinyMCE.remove(b);g.remove("wp_mce_fullscreen_parent");tinyMCE.settings=tinyMCE.oldSettings},10)}});b.addCommand("wpFullScreenSave",function(){var i=tinyMCE.get("wp_mce_fullscreen"),j;i.focus();j=tinyMCE.get(i.getParam("wp_fullscreen_editor_id"));j.setContent(i.getContent({format:"raw"}),{format:"raw"})});b.addCommand("wpFullScreenInit",function(){var k=b.getDoc(),i=k.body,j;if(b.id=="wp_mce_fullscreen"){return}tinyMCE.oldSettings=tinyMCE.settings;tinymce.each(b.settings,function(l,m){f[m]=l});f.id="wp_mce_fullscreen";f.wp_fullscreen_is_enabled=true;f.wp_fullscreen_editor_id=b.id;f.theme_advanced_resizing=false;f.theme_advanced_statusbar_location="none";f.content_css=f.content_css?f.content_css+","+f.wp_fullscreen_content_css:f.wp_fullscreen_content_css;f.height=tinymce.isIE?i.scrollHeight:i.offsetHeight;tinymce.each(b.getParam("wp_fullscreen_settings"),function(m,l){f[l]=m});j=new tinymce.Editor("wp_mce_fullscreen",f);j.onInit.add(function(l){var n=tinymce.DOM,m=n.select("a.mceButton",n.get("wp-fullscreen-buttons"));if(!b.isHidden()){l.setContent(b.getContent())}else{l.setContent(switchEditors.wpautop(l.getElement().value))}setTimeout(function(){l.onNodeChange.add(function(p,o,q){tinymce.each(m,function(t){var s,r;if(s=n.get("wp_mce_fullscreen_"+t.id.substr(6))){r=s.className;if(r){t.className=r}}})})},1000);l.dom.addClass(l.getBody(),"wp-fullscreen-editor");l.focus()});j.render();if("undefined"!=fullscreen){j.dom.bind(j.dom.doc,"mousemove",function(l){fullscreen.bounder("showToolbar","hideToolbar",2000,l)})}});if("undefined"!=fullscreen){b.addButton("fullscreen",{title:"fullscreen.desc",onclick:function(){fullscreen.on()}})}if(b.getParam("fullscreen_is_enabled")||!b.getParam("wp_fullscreen_is_enabled")){return}function c(){if(a){return}var k=b.getDoc(),j=tinymce.DOM,l,i;if(tinymce.isIE){i=k.body.scrollHeight}else{i=k.documentElement.offsetHeight}l=(i>300)?i:300;if(h!=l){h=l;a=true;setTimeout(function(){a=false},100);j.setStyle(j.get(b.id+"_ifr"),"height",l+"px")}}b.onInit.add(function(j,i){j.onChange.add(c);j.onSetContent.add(c);j.onPaste.add(c);j.onKeyUp.add(c);j.onPostRender.add(c);j.getBody().style.overflowY="hidden"});if(b.getParam("autoresize_on_init",true)){b.onLoadContent.add(function(j,i){setTimeout(function(){c()},1200)})}b.addCommand("wpAutoResize",c)},getInfo:function(){return{longname:"WP Fullscreen",author:"WordPress",authorurl:"http://wordpress.org",infourl:"",version:"1.0"}}});tinymce.PluginManager.add("wpfullscreen",tinymce.plugins.wpFullscreenPlugin)})();
|
||||
(function(){tinymce.create("tinymce.plugins.wpFullscreenPlugin",{init:function(b,d){var e=this,h=0,f={},g=tinymce.DOM,a=false;b.addCommand("wpFullScreenClose",function(){if(b.getParam("wp_fullscreen_is_enabled")){g.win.setTimeout(function(){tinyMCE.remove(b);g.remove("wp_mce_fullscreen_parent");tinyMCE.settings=tinyMCE.oldSettings},10)}});b.addCommand("wpFullScreenSave",function(){var i=tinyMCE.get("wp_mce_fullscreen"),j;i.focus();j=tinyMCE.get(i.getParam("wp_fullscreen_editor_id"));j.setContent(i.getContent({format:"raw"}),{format:"raw"})});b.addCommand("wpFullScreenInit",function(){var k,i,j;b=tinymce.get("content");k=b.getDoc();i=k.body;tinyMCE.oldSettings=tinyMCE.settings;tinymce.each(b.settings,function(l,m){f[m]=l});f.id="wp_mce_fullscreen";f.wp_fullscreen_is_enabled=true;f.wp_fullscreen_editor_id=b.id;f.theme_advanced_resizing=false;f.theme_advanced_statusbar_location="none";f.content_css=f.content_css?f.content_css+","+f.wp_fullscreen_content_css:f.wp_fullscreen_content_css;f.height=tinymce.isIE?i.scrollHeight:i.offsetHeight;tinymce.each(b.getParam("wp_fullscreen_settings"),function(m,l){f[l]=m});j=new tinymce.Editor("wp_mce_fullscreen",f);j.onInit.add(function(l){var n=tinymce.DOM,m=n.select("a.mceButton",n.get("wp-fullscreen-buttons"));if(!b.isHidden()){l.setContent(b.getContent())}else{l.setContent(switchEditors.wpautop(l.getElement().value))}setTimeout(function(){l.onNodeChange.add(function(p,o,q){tinymce.each(m,function(t){var s,r;if(s=n.get("wp_mce_fullscreen_"+t.id.substr(6))){r=s.className;if(r){t.className=r}}})})},1000);l.dom.addClass(l.getBody(),"wp-fullscreen-editor");l.focus()});j.render();if("undefined"!=fullscreen){j.dom.bind(j.dom.doc,"mousemove",function(l){fullscreen.bounder("showToolbar","hideToolbar",2000,l)})}});if("undefined"!=fullscreen){b.addButton("wp_fullscreen",{title:"fullscreen.desc",onclick:function(){fullscreen.on()}})}if(b.getParam("fullscreen_is_enabled")||!b.getParam("wp_fullscreen_is_enabled")){return}function c(){if(a){return}var k=b.getDoc(),j=tinymce.DOM,l,i;if(tinymce.isIE){i=k.body.scrollHeight}else{i=k.documentElement.offsetHeight}l=(i>300)?i:300;if(h!=l){h=l;a=true;setTimeout(function(){a=false},100);j.setStyle(j.get(b.id+"_ifr"),"height",l+"px")}}b.onInit.add(function(j,i){j.onChange.add(c);j.onSetContent.add(c);j.onPaste.add(c);j.onKeyUp.add(c);j.onPostRender.add(c);j.getBody().style.overflowY="hidden"});if(b.getParam("autoresize_on_init",true)){b.onLoadContent.add(function(j,i){setTimeout(function(){c()},1200)})}b.addCommand("wpAutoResize",c)},getInfo:function(){return{longname:"WP Fullscreen",author:"WordPress",authorurl:"http://wordpress.org",infourl:"",version:"1.0"}}});tinymce.PluginManager.add("wpfullscreen",tinymce.plugins.wpFullscreenPlugin)})();
|
||||
@@ -1 +0,0 @@
|
||||
#wp-link #internal-toggle{padding-right:18px;padding-left:0;}#wp-link label span{text-align:left;padding-left:5px;padding-right:0;}#wp-link .link-search-wrapper span{float:right;}#wp-link .link-search-wrapper input[type="text"]{float:right;}#wp-link .link-search-wrapper img.waiting{margin:8px 4px 0 1px;float:right;}#wp-link .link-target{margin:0 87px 0 0;}#wp-link .item-info{left:5px;right:auto;top:4px;bottom:0;}#wp-link #search-panel{float:right;}#wp-link-cancel{float:right;}#wp-link-update{float:left;}#wp-link .toggle-arrow{background-position:bottom right;}#wp-link .toggle-arrow-active{background-position:center right;}
|
||||
@@ -1,54 +0,0 @@
|
||||
#wp-link #internal-toggle {
|
||||
padding-right: 18px;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
#wp-link label span {
|
||||
text-align: left;
|
||||
padding-left: 5px;
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
#wp-link .link-search-wrapper span {
|
||||
float: right;
|
||||
}
|
||||
|
||||
#wp-link .link-search-wrapper input[type="text"] {
|
||||
float: right;
|
||||
}
|
||||
|
||||
#wp-link .link-search-wrapper img.waiting {
|
||||
margin: 8px 4px 0 1px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
#wp-link .link-target {
|
||||
margin: 0 87px 0 0;
|
||||
}
|
||||
|
||||
#wp-link .item-info {
|
||||
left: 5px;
|
||||
right: auto;
|
||||
top: 4px;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
#wp-link #search-panel {
|
||||
float: right;
|
||||
}
|
||||
|
||||
#wp-link-cancel {
|
||||
float: right;
|
||||
}
|
||||
|
||||
#wp-link-update {
|
||||
float: left;
|
||||
}
|
||||
|
||||
#wp-link .toggle-arrow {
|
||||
background-position: bottom right;
|
||||
}
|
||||
|
||||
#wp-link .toggle-arrow-active {
|
||||
background-position: center right;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
#wp-link{line-height:1.4em;font-size:12px;}#wp-link ol,#wp-link ul{list-style:none;margin:0;padding:0;}#wp-link input[type="text"]{-webkit-box-sizing:border-box;}#wp-link input[type="text"],#wp-link textarea{border-width:1px;border-style:solid;-moz-border-radius:4px;-khtml-border-radius:4px;-webkit-border-radius:4px;border-radius:4px;font-size:12px;margin:1px;padding:3px;}#wp-link #link-options{padding:10px 0 14px;border-bottom:1px solid #dfdfdf;margin:0 6px 14px;}#wp-link p.howto{margin:3px;}#wp-link #internal-toggle{display:inline-block;cursor:pointer;padding-left:18px;}#wp-link .toggle-arrow{background:transparent url('../img/toggle-arrow.png') top left no-repeat;height:23px;line-height:23px;}#wp-link .toggle-arrow-active{background-position:center left;}#wp-link label input[type="text"]{width:360px;margin-top:5px;}#wp-link label span{display:inline-block;width:80px;text-align:right;padding-right:5px;}#wp-link .link-search-wrapper{margin:5px 6px 9px;display:block;overflow:hidden;}#wp-link .link-search-wrapper span{float:left;margin-top:6px;}#wp-link .link-search-wrapper input[type="text"]{float:left;width:220px;}#wp-link .link-search-wrapper img.waiting{margin:8px 1px 0 4px;float:left;display:none;}#wp-link .link-target{width:auto;padding:3px 0 0;margin:0 0 0 87px;font-size:11px;}#wp-link .query-results{border:1px #dfdfdf solid;margin:0 5px 5px;background:#fff;height:185px;overflow:auto;position:relative;}#wp-link li,#wp-link .query-notice{clear:both;margin-bottom:0;border-bottom:1px solid #f1f1f1;color:#333;padding:4px 6px;cursor:pointer;position:relative;}#wp-link li:hover{background:#eaf2fa;color:#151515;}#wp-link li.unselectable{border-bottom:1px solid #dfdfdf;}#wp-link li.unselectable:hover{background:#fff;cursor:auto;color:#333;}#wp-link li.selected{background:#ddd;color:#333;}#wp-link li.selected .item-title{font-weight:bold;}#wp-link .item-title{display:inline-block;width:80%;}#wp-link .item-info{text-transform:uppercase;color:#666;font-size:11px;position:absolute;right:5px;top:4px;bottom:0;}#wp-link #search-results{display:none;}#wp-link #search-panel{float:left;width:100%;}#wp-link .river-waiting{display:none;padding:10px 0;}#wp-link .river-waiting img.waiting{margin:0 auto;display:block;}#wp-link .submitbox{padding:5px 10px;font-size:11px;overflow:auto;height:29px;}#wp-link-cancel{line-height:25px;float:left;}#wp-link-update{line-height:23px;float:right;}
|
||||
@@ -1,163 +0,0 @@
|
||||
#wp-link {
|
||||
line-height: 1.4em;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
#wp-link ol,
|
||||
#wp-link ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#wp-link input[type="text"] {
|
||||
-webkit-box-sizing: border-box;
|
||||
}
|
||||
|
||||
#wp-link input[type="text"],
|
||||
#wp-link textarea {
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
-moz-border-radius: 4px;
|
||||
-khtml-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
margin: 1px;
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
#wp-link #link-options {
|
||||
padding: 10px 0 14px;
|
||||
border-bottom: 1px solid #dfdfdf;
|
||||
margin: 0 6px 14px;
|
||||
}
|
||||
#wp-link p.howto {
|
||||
margin: 3px;
|
||||
}
|
||||
#wp-link #internal-toggle {
|
||||
display: inline-block;
|
||||
cursor: pointer;
|
||||
padding-left: 18px;
|
||||
}
|
||||
#wp-link .toggle-arrow {
|
||||
background: transparent url( '../img/toggle-arrow.png' ) top left no-repeat;
|
||||
height: 23px;
|
||||
line-height: 23px;
|
||||
}
|
||||
#wp-link .toggle-arrow-active {
|
||||
background-position: center left;
|
||||
}
|
||||
#wp-link label input[type="text"] {
|
||||
width: 360px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
#wp-link label span {
|
||||
display: inline-block;
|
||||
width: 80px;
|
||||
text-align: right;
|
||||
padding-right: 5px;
|
||||
}
|
||||
#wp-link .link-search-wrapper {
|
||||
margin: 5px 6px 9px;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
}
|
||||
#wp-link .link-search-wrapper span {
|
||||
float: left;
|
||||
margin-top: 6px;
|
||||
}
|
||||
#wp-link .link-search-wrapper input[type="text"] {
|
||||
float: left;
|
||||
width: 220px;
|
||||
}
|
||||
#wp-link .link-search-wrapper img.waiting {
|
||||
margin: 8px 1px 0 4px;
|
||||
float: left;
|
||||
display: none;
|
||||
}
|
||||
#wp-link .link-target {
|
||||
width: auto;
|
||||
padding: 3px 0 0;
|
||||
margin: 0 0 0 87px;
|
||||
font-size: 11px;
|
||||
}
|
||||
#wp-link .query-results {
|
||||
border: 1px #dfdfdf solid;
|
||||
margin: 0 5px 5px;
|
||||
background: #fff;
|
||||
height: 185px;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
}
|
||||
#wp-link li,
|
||||
#wp-link .query-notice {
|
||||
clear: both;
|
||||
margin-bottom: 0;
|
||||
border-bottom: 1px solid #f1f1f1;
|
||||
color: #333;
|
||||
padding: 4px 6px;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
}
|
||||
#wp-link li:hover {
|
||||
background: #eaf2fa;
|
||||
color: #151515;
|
||||
}
|
||||
#wp-link li.unselectable {
|
||||
border-bottom: 1px solid #dfdfdf;
|
||||
}
|
||||
#wp-link li.unselectable:hover {
|
||||
background: #fff;
|
||||
cursor: auto;
|
||||
color: #333;
|
||||
}
|
||||
#wp-link li.selected {
|
||||
background: #ddd;
|
||||
color: #333;
|
||||
}
|
||||
#wp-link li.selected .item-title {
|
||||
font-weight: bold;
|
||||
}
|
||||
#wp-link .item-title {
|
||||
display: inline-block;
|
||||
width: 80%;
|
||||
}
|
||||
#wp-link .item-info {
|
||||
text-transform: uppercase;
|
||||
color: #666;
|
||||
font-size: 11px;
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
top: 4px;
|
||||
bottom: 0;
|
||||
}
|
||||
#wp-link #search-results {
|
||||
display: none;
|
||||
}
|
||||
#wp-link #search-panel {
|
||||
float: left;
|
||||
width: 100%;
|
||||
}
|
||||
#wp-link .river-waiting {
|
||||
display: none;
|
||||
padding: 10px 0;
|
||||
}
|
||||
#wp-link .river-waiting img.waiting {
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
}
|
||||
#wp-link .submitbox {
|
||||
padding: 5px 10px;
|
||||
font-size: 11px;
|
||||
overflow: auto;
|
||||
height: 29px;
|
||||
}
|
||||
#wp-link-cancel {
|
||||
line-height: 25px;
|
||||
float: left;
|
||||
}
|
||||
#wp-link-update {
|
||||
line-height: 23px;
|
||||
float: right;
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.2 KiB |
@@ -1,585 +0,0 @@
|
||||
var wpLink;
|
||||
|
||||
(function($){
|
||||
var inputs = {}, rivers = {}, ed, River, Query;
|
||||
|
||||
wpLink = {
|
||||
timeToTriggerRiver: 150,
|
||||
minRiverAJAXDuration: 200,
|
||||
riverBottomThreshold: 5,
|
||||
keySensitivity: 100,
|
||||
lastSearch: '',
|
||||
textarea: function() { return edCanvas; },
|
||||
|
||||
init : function() {
|
||||
inputs.dialog = $('#wp-link');
|
||||
inputs.submit = $('#wp-link-submit');
|
||||
// URL
|
||||
inputs.url = $('#url-field');
|
||||
// Secondary options
|
||||
inputs.title = $('#link-title-field');
|
||||
// Advanced Options
|
||||
inputs.openInNewTab = $('#link-target-checkbox');
|
||||
inputs.search = $('#search-field');
|
||||
// Build Rivers
|
||||
rivers.search = new River( $('#search-results') );
|
||||
rivers.recent = new River( $('#most-recent-results') );
|
||||
rivers.elements = $('.query-results', inputs.dialog);
|
||||
|
||||
// Bind event handlers
|
||||
inputs.dialog.keydown( wpLink.keydown );
|
||||
inputs.dialog.keyup( wpLink.keyup );
|
||||
inputs.submit.click( function(e){
|
||||
wpLink.update();
|
||||
e.preventDefault();
|
||||
});
|
||||
$('#wp-link-cancel').click( wpLink.close );
|
||||
$('#internal-toggle').click( wpLink.toggleInternalLinking );
|
||||
|
||||
rivers.elements.bind('river-select', wpLink.updateFields );
|
||||
|
||||
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() {
|
||||
// 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.
|
||||
if ( e = ed.dom.getParent(ed.selection.getNode(), 'A') ) {
|
||||
// Set URL and description.
|
||||
inputs.url.val( ed.dom.getAttrib(e, 'href') );
|
||||
inputs.title.val( ed.dom.getAttrib(e, 'title') );
|
||||
// Set open in new tab.
|
||||
if ( "_blank" == ed.dom.getAttrib(e, 'target') )
|
||||
inputs.openInNewTab.prop('checked', true);
|
||||
// Update save prompt.
|
||||
inputs.submit.val( wpLinkL10n.update );
|
||||
|
||||
// If there's no link, set the default values.
|
||||
} else {
|
||||
wpLink.setDefaultValues();
|
||||
}
|
||||
|
||||
tinyMCEPopup.storeSelection();
|
||||
},
|
||||
|
||||
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.prop('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 = '<a href="' + attrs.href + '"';
|
||||
|
||||
if ( attrs.title )
|
||||
html += ' title="' + attrs.title + '"';
|
||||
if ( attrs.target )
|
||||
html += ' target="' + attrs.target + '"';
|
||||
|
||||
html += '>';
|
||||
|
||||
// Insert HTML
|
||||
// W3C
|
||||
if ( typeof textarea.selectionStart !== 'undefined' ) {
|
||||
start = textarea.selectionStart;
|
||||
end = textarea.selectionEnd;
|
||||
selection = textarea.value.substring( start, end );
|
||||
html = html + selection + '</a>';
|
||||
cursor = start + html.length;
|
||||
|
||||
// If no next is selected, place the cursor inside the closing tag.
|
||||
if ( start == end )
|
||||
cursor -= '</a>'.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 + '</a>';
|
||||
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
|
||||
wpLink.range.select();
|
||||
|
||||
wpLink.range = null;
|
||||
}
|
||||
|
||||
wpLink.close();
|
||||
textarea.focus();
|
||||
},
|
||||
|
||||
mceUpdate : function() {
|
||||
var ed = tinyMCEPopup.editor,
|
||||
attrs = wpLink.getAttrs(),
|
||||
e, b;
|
||||
|
||||
tinyMCEPopup.restoreSelection();
|
||||
e = ed.dom.getParent(ed.selection.getNode(), 'A');
|
||||
|
||||
// If the values are empty, unlink and return
|
||||
if ( ! attrs.href || attrs.href == 'http://' ) {
|
||||
if ( e ) {
|
||||
tinyMCEPopup.execCommand("mceBeginUndoLevel");
|
||||
b = ed.selection.getBookmark();
|
||||
ed.dom.remove(e, 1);
|
||||
ed.selection.moveToBookmark(b);
|
||||
tinyMCEPopup.execCommand("mceEndUndoLevel");
|
||||
wpLink.close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
tinyMCEPopup.execCommand("mceBeginUndoLevel");
|
||||
|
||||
if (e == null) {
|
||||
ed.getDoc().execCommand("unlink", false, null);
|
||||
tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});
|
||||
|
||||
tinymce.each(ed.dom.select("a"), function(n) {
|
||||
if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
|
||||
e = n;
|
||||
ed.dom.setAttribs(e, attrs);
|
||||
}
|
||||
});
|
||||
|
||||
// Sometimes WebKit lets a user create a link where
|
||||
// they shouldn't be able to. In this case, CreateLink
|
||||
// injects "#mce_temp_url#" into their content. Fix it.
|
||||
if ( $(e).text() == '#mce_temp_url#' ) {
|
||||
ed.dom.remove(e);
|
||||
e = null;
|
||||
}
|
||||
} else {
|
||||
ed.dom.setAttribs(e, attrs);
|
||||
}
|
||||
|
||||
// Don't move caret if selection was image
|
||||
if ( e && (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') ) {
|
||||
ed.focus();
|
||||
ed.selection.select(e);
|
||||
ed.selection.collapse(0);
|
||||
tinyMCEPopup.storeSelection();
|
||||
}
|
||||
|
||||
tinyMCEPopup.execCommand("mceEndUndoLevel");
|
||||
wpLink.close();
|
||||
},
|
||||
|
||||
updateFields : function( e, li, originalEvent ) {
|
||||
inputs.url.val( li.children('.item-permalink').val() );
|
||||
inputs.title.val( li.hasClass('no-title') ? '' : li.children('.item-title').text() );
|
||||
if ( originalEvent && originalEvent.type == "click" )
|
||||
inputs.url.focus();
|
||||
},
|
||||
setDefaultValues : function() {
|
||||
// Set URL and description to defaults.
|
||||
// Leave the new tab setting as-is.
|
||||
inputs.url.val('http://');
|
||||
inputs.title.val('');
|
||||
|
||||
// Update save prompt.
|
||||
inputs.submit.val( wpLinkL10n.save );
|
||||
},
|
||||
|
||||
searchInternalLinks : function() {
|
||||
var t = $(this), waiting,
|
||||
search = t.val();
|
||||
|
||||
if ( search.length > 2 ) {
|
||||
rivers.recent.hide();
|
||||
rivers.search.show();
|
||||
|
||||
// Don't search if the keypress didn't change the title.
|
||||
if ( wpLink.lastSearch == search )
|
||||
return;
|
||||
|
||||
wpLink.lastSearch = search;
|
||||
waiting = t.siblings('img.waiting').show();
|
||||
|
||||
rivers.search.change( search );
|
||||
rivers.search.ajax( function(){ waiting.hide(); });
|
||||
} else {
|
||||
rivers.search.hide();
|
||||
rivers.recent.show();
|
||||
}
|
||||
},
|
||||
|
||||
next : function() {
|
||||
rivers.search.next();
|
||||
rivers.recent.next();
|
||||
},
|
||||
prev : function() {
|
||||
rivers.search.prev();
|
||||
rivers.recent.prev();
|
||||
},
|
||||
|
||||
keydown : function( event ) {
|
||||
var fn, key = $.ui.keyCode;
|
||||
|
||||
switch( event.which ) {
|
||||
case key.UP:
|
||||
fn = 'prev';
|
||||
case key.DOWN:
|
||||
fn = fn || 'next';
|
||||
clearInterval( wpLink.keyInterval );
|
||||
wpLink[ fn ]();
|
||||
wpLink.keyInterval = setInterval( wpLink[ fn ], wpLink.keySensitivity );
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
},
|
||||
keyup: function( event ) {
|
||||
var key = $.ui.keyCode;
|
||||
|
||||
switch( event.which ) {
|
||||
case key.ESCAPE:
|
||||
event.stopImmediatePropagation();
|
||||
if ( ! $(document).triggerHandler( 'wp_CloseOnEscape', [{ event: event, what: 'wplink', cb: wpLink.close }] ) )
|
||||
wpLink.close();
|
||||
|
||||
return false;
|
||||
break;
|
||||
case key.UP:
|
||||
case key.DOWN:
|
||||
clearInterval( wpLink.keyInterval );
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
},
|
||||
|
||||
delayedCallback : function( func, delay ) {
|
||||
var timeoutTriggered, funcTriggered, funcArgs, funcContext;
|
||||
|
||||
if ( ! delay )
|
||||
return func;
|
||||
|
||||
setTimeout( function() {
|
||||
if ( funcTriggered )
|
||||
return func.apply( funcContext, funcArgs );
|
||||
// Otherwise, wait.
|
||||
timeoutTriggered = true;
|
||||
}, delay);
|
||||
|
||||
return function() {
|
||||
if ( timeoutTriggered )
|
||||
return func.apply( this, arguments );
|
||||
// Otherwise, wait.
|
||||
funcArgs = arguments;
|
||||
funcContext = this;
|
||||
funcTriggered = true;
|
||||
};
|
||||
},
|
||||
|
||||
toggleInternalLinking : function( event ) {
|
||||
var panel = $('#search-panel'),
|
||||
widget = inputs.dialog.wpdialog('widget'),
|
||||
// We're about to toggle visibility; it's currently the opposite
|
||||
visible = !panel.is(':visible'),
|
||||
win = $(window);
|
||||
|
||||
$(this).toggleClass('toggle-arrow-active', visible);
|
||||
|
||||
inputs.dialog.height('auto');
|
||||
panel.slideToggle( 300, function() {
|
||||
setUserSetting('wplink', visible ? '1' : '0');
|
||||
inputs[ visible ? 'search' : 'url' ].focus();
|
||||
|
||||
// Move the box if the box is now expanded, was opened in a collapsed state,
|
||||
// and if it needs to be moved. (Judged by bottom not being positive or
|
||||
// bottom being smaller than top.)
|
||||
var scroll = win.scrollTop(),
|
||||
top = widget.offset().top,
|
||||
bottom = top + widget.outerHeight(),
|
||||
diff = bottom - win.height();
|
||||
|
||||
if ( diff > scroll ) {
|
||||
widget.animate({'top': diff < top ? top - diff : scroll }, 200);
|
||||
}
|
||||
});
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
River = function( element, search ) {
|
||||
var self = this;
|
||||
this.element = element;
|
||||
this.ul = element.children('ul');
|
||||
this.waiting = element.find('.river-waiting');
|
||||
|
||||
this.change( search );
|
||||
this.refresh();
|
||||
|
||||
element.scroll( function(){ self.maybeLoad(); });
|
||||
element.delegate('li', 'click', function(e){ self.select( $(this), e ); });
|
||||
};
|
||||
|
||||
$.extend( River.prototype, {
|
||||
refresh: function() {
|
||||
this.deselect();
|
||||
this.visible = this.element.is(':visible');
|
||||
},
|
||||
show: function() {
|
||||
if ( ! this.visible ) {
|
||||
this.deselect();
|
||||
this.element.show();
|
||||
this.visible = true;
|
||||
}
|
||||
},
|
||||
hide: function() {
|
||||
this.element.hide();
|
||||
this.visible = false;
|
||||
},
|
||||
// Selects a list item and triggers the river-select event.
|
||||
select: function( li, event ) {
|
||||
var liHeight, elHeight, liTop, elTop;
|
||||
|
||||
if ( li.hasClass('unselectable') || li == this.selected )
|
||||
return;
|
||||
|
||||
this.deselect();
|
||||
this.selected = li.addClass('selected');
|
||||
// Make sure the element is visible
|
||||
liHeight = li.outerHeight();
|
||||
elHeight = this.element.height();
|
||||
liTop = li.position().top;
|
||||
elTop = this.element.scrollTop();
|
||||
|
||||
if ( liTop < 0 ) // Make first visible element
|
||||
this.element.scrollTop( elTop + liTop );
|
||||
else if ( liTop + liHeight > elHeight ) // Make last visible element
|
||||
this.element.scrollTop( elTop + liTop - elHeight + liHeight );
|
||||
|
||||
// Trigger the river-select event
|
||||
this.element.trigger('river-select', [ li, event, this ]);
|
||||
},
|
||||
deselect: function() {
|
||||
if ( this.selected )
|
||||
this.selected.removeClass('selected');
|
||||
this.selected = false;
|
||||
},
|
||||
prev: function() {
|
||||
if ( ! this.visible )
|
||||
return;
|
||||
|
||||
var to;
|
||||
if ( this.selected ) {
|
||||
to = this.selected.prev('li');
|
||||
if ( to.length )
|
||||
this.select( to );
|
||||
}
|
||||
},
|
||||
next: function() {
|
||||
if ( ! this.visible )
|
||||
return;
|
||||
|
||||
var to = this.selected ? this.selected.next('li') : $('li:not(.unselectable):first', this.element);
|
||||
if ( to.length )
|
||||
this.select( to );
|
||||
},
|
||||
ajax: function( callback ) {
|
||||
var self = this,
|
||||
delay = this.query.page == 1 ? 0 : wpLink.minRiverAJAXDuration,
|
||||
response = wpLink.delayedCallback( function( results, params ) {
|
||||
self.process( results, params );
|
||||
if ( callback )
|
||||
callback( results, params );
|
||||
}, delay );
|
||||
|
||||
this.query.ajax( response );
|
||||
},
|
||||
change: function( search ) {
|
||||
if ( this.query && this._search == search )
|
||||
return;
|
||||
|
||||
this._search = search;
|
||||
this.query = new Query( search );
|
||||
this.element.scrollTop(0);
|
||||
},
|
||||
process: function( results, params ) {
|
||||
var list = '', alt = true, classes = '',
|
||||
firstPage = params.page == 1;
|
||||
|
||||
if ( !results ) {
|
||||
if ( firstPage ) {
|
||||
list += '<li class="unselectable"><span class="item-title"><em>'
|
||||
+ wpLinkL10n.noMatchesFound
|
||||
+ '</em></span></li>';
|
||||
}
|
||||
} else {
|
||||
$.each( results, function() {
|
||||
classes = alt ? 'alternate' : '';
|
||||
classes += this['title'] ? '' : ' no-title';
|
||||
list += classes ? '<li class="' + classes + '">' : '<li>';
|
||||
list += '<input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />';
|
||||
list += '<span class="item-title">';
|
||||
list += this['title'] ? this['title'] : wpLinkL10n.noTitle;
|
||||
list += '</span><span class="item-info">' + this['info'] + '</span></li>';
|
||||
alt = ! alt;
|
||||
});
|
||||
}
|
||||
|
||||
this.ul[ firstPage ? 'html' : 'append' ]( list );
|
||||
},
|
||||
maybeLoad: function() {
|
||||
var self = this,
|
||||
el = this.element,
|
||||
bottom = el.scrollTop() + el.height();
|
||||
|
||||
if ( ! this.query.ready() || bottom < this.ul.height() - wpLink.riverBottomThreshold )
|
||||
return;
|
||||
|
||||
setTimeout(function() {
|
||||
var newTop = el.scrollTop(),
|
||||
newBottom = newTop + el.height();
|
||||
|
||||
if ( ! self.query.ready() || newBottom < self.ul.height() - wpLink.riverBottomThreshold )
|
||||
return;
|
||||
|
||||
self.waiting.show();
|
||||
el.scrollTop( newTop + self.waiting.outerHeight() );
|
||||
|
||||
self.ajax( function() { self.waiting.hide(); });
|
||||
}, wpLink.timeToTriggerRiver );
|
||||
}
|
||||
});
|
||||
|
||||
Query = function( search ) {
|
||||
this.page = 1;
|
||||
this.allLoaded = false;
|
||||
this.querying = false;
|
||||
this.search = search;
|
||||
};
|
||||
|
||||
$.extend( Query.prototype, {
|
||||
ready: function() {
|
||||
return !( this.querying || this.allLoaded );
|
||||
},
|
||||
ajax: function( callback ) {
|
||||
var self = this,
|
||||
query = {
|
||||
action : 'wp-link-ajax',
|
||||
page : this.page,
|
||||
'_ajax_linking_nonce' : $('#_ajax_linking_nonce').val()
|
||||
};
|
||||
|
||||
if ( this.search )
|
||||
query.search = this.search;
|
||||
|
||||
this.querying = true;
|
||||
|
||||
$.post( ajaxurl, query, function(r) {
|
||||
self.page++;
|
||||
self.querying = false;
|
||||
self.allLoaded = !r;
|
||||
callback( r, query );
|
||||
}, "json" );
|
||||
}
|
||||
});
|
||||
|
||||
$(document).ready( wpLink.init );
|
||||
})(jQuery);
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user