Archived
Updates
This commit is contained in:
1 parent
70d2335bba
commit
7428b67da5
1086 files changed
+94145
-59082
No files matched your search
@@ -4,7 +4,8 @@
|
||||
* WordPress View plugin.
|
||||
*/
|
||||
tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
var selected,
|
||||
var $ = editor.$,
|
||||
selected,
|
||||
Env = tinymce.Env,
|
||||
VK = tinymce.util.VK,
|
||||
TreeWalker = tinymce.dom.TreeWalker,
|
||||
@@ -12,7 +13,13 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
firstFocus = true,
|
||||
_noop = function() { return false; },
|
||||
isios = /iPad|iPod|iPhone/.test( navigator.userAgent ),
|
||||
cursorInterval, lastKeyDownNode, setViewCursorTries, focus, execCommandView, execCommandBefore;
|
||||
cursorInterval,
|
||||
lastKeyDownNode,
|
||||
setViewCursorTries,
|
||||
focus,
|
||||
execCommandView,
|
||||
execCommandBefore,
|
||||
toolbar;
|
||||
|
||||
function getView( node ) {
|
||||
return getParent( node, 'wpview-wrap' );
|
||||
@@ -34,37 +41,6 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text/shortcode string for a view.
|
||||
*
|
||||
* @param view The view wrapper's node
|
||||
* @returns string The text/shoercode string of the view
|
||||
*/
|
||||
function getViewText( view ) {
|
||||
if ( view = getView( view ) ) {
|
||||
return window.decodeURIComponent( editor.dom.getAttrib( view, 'data-wpview-text' ) || '' );
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view's original text/shortcode string
|
||||
*
|
||||
* @param view The view wrapper's HTML id or node
|
||||
* @param text The text string to be set
|
||||
*/
|
||||
function setViewText( view, text ) {
|
||||
view = getView( view );
|
||||
|
||||
if ( view ) {
|
||||
editor.dom.setAttrib( view, 'data-wpview-text', window.encodeURIComponent( text || '' ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function _stop( event ) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
@@ -103,11 +79,9 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
}
|
||||
|
||||
function removeView( view ) {
|
||||
// TODO: trigger an event to run a clean up function.
|
||||
// Maybe `jQuery( view ).trigger( 'remove' );`?
|
||||
editor.undoManager.transact( function() {
|
||||
handleEnter( view );
|
||||
editor.dom.remove( view );
|
||||
wp.mce.views.remove( editor, view );
|
||||
});
|
||||
}
|
||||
|
||||
@@ -115,36 +89,37 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
var clipboard,
|
||||
dom = editor.dom;
|
||||
|
||||
// Bail if node is already selected.
|
||||
if ( ! viewNode || viewNode === selected ) {
|
||||
if ( ! viewNode ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure that the editor is focused.
|
||||
// It is possible that the editor is not focused when the mouse event fires
|
||||
// without focus, the selection will not work properly.
|
||||
editor.getBody().focus();
|
||||
if ( viewNode !== selected ) {
|
||||
// Make sure that the editor is focused.
|
||||
// It is possible that the editor is not focused when the mouse event fires
|
||||
// without focus, the selection will not work properly.
|
||||
editor.getBody().focus();
|
||||
|
||||
deselect();
|
||||
selected = viewNode;
|
||||
dom.setAttrib( viewNode, 'data-mce-selected', 1 );
|
||||
deselect();
|
||||
selected = viewNode;
|
||||
dom.setAttrib( viewNode, 'data-mce-selected', 1 );
|
||||
|
||||
clipboard = dom.create( 'div', {
|
||||
'class': 'wpview-clipboard',
|
||||
'contenteditable': 'true'
|
||||
}, getViewText( viewNode ) );
|
||||
clipboard = dom.create( 'div', {
|
||||
'class': 'wpview-clipboard',
|
||||
'contenteditable': 'true'
|
||||
}, wp.mce.views.getText( viewNode ) );
|
||||
|
||||
editor.dom.select( '.wpview-body', viewNode )[0].appendChild( clipboard );
|
||||
editor.dom.select( '.wpview-body', viewNode )[0].appendChild( clipboard );
|
||||
|
||||
// Both of the following are necessary to prevent manipulating the selection/focus
|
||||
dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop );
|
||||
dom.bind( selected, 'beforedeactivate focusin focusout', _stop );
|
||||
// Both of the following are necessary to prevent manipulating the selection/focus
|
||||
dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop );
|
||||
dom.bind( selected, 'beforedeactivate focusin focusout', _stop );
|
||||
|
||||
// select the hidden div
|
||||
if ( isios ) {
|
||||
editor.selection.select( clipboard );
|
||||
} else {
|
||||
editor.selection.select( clipboard, true );
|
||||
// select the hidden div
|
||||
if ( isios ) {
|
||||
editor.selection.select( clipboard );
|
||||
} else {
|
||||
editor.selection.select( clipboard, true );
|
||||
}
|
||||
}
|
||||
|
||||
editor.nodeChanged();
|
||||
@@ -173,21 +148,23 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
// Check if the `wp.mce` API exists.
|
||||
if ( typeof wp === 'undefined' || ! wp.mce ) {
|
||||
return {
|
||||
getViewText: _noop,
|
||||
setViewText: _noop,
|
||||
getView: _noop
|
||||
};
|
||||
}
|
||||
|
||||
// Remove the content of view wrappers from HTML string
|
||||
function emptyViews( content ) {
|
||||
return content.replace(/<div[^>]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?: |\u00a0)*<\/p><\/div>/g, '$1' );
|
||||
content = content.replace( /<div[^>]+data-wpview-text="([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>[^<>]*<\/p>\s*<\/div>/g, function( all, match ) {
|
||||
return '<p>' + window.decodeURIComponent( match ) + '</p>';
|
||||
});
|
||||
|
||||
return content.replace( / data-wpview-marker="[^"]+"/g, '' );
|
||||
}
|
||||
|
||||
// Prevent adding undo levels on changes inside a view wrapper
|
||||
editor.on( 'BeforeAddUndo', function( event ) {
|
||||
if ( event.lastLevel && emptyViews( event.level.content ) === emptyViews( event.lastLevel.content ) ) {
|
||||
event.preventDefault();
|
||||
if ( event.level.content ) {
|
||||
event.level.content = emptyViews( event.level.content );
|
||||
}
|
||||
});
|
||||
|
||||
@@ -197,23 +174,49 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
editor.on( 'BeforeSetContent', function( event ) {
|
||||
var node;
|
||||
|
||||
if ( ! event.selection ) {
|
||||
wp.mce.views.unbind();
|
||||
}
|
||||
|
||||
if ( ! event.content ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( selected ) {
|
||||
removeView( selected );
|
||||
if ( ! event.load ) {
|
||||
if ( selected ) {
|
||||
removeView( selected );
|
||||
}
|
||||
|
||||
node = editor.selection.getNode();
|
||||
|
||||
if ( node && node !== editor.getBody() && /^\s*https?:\/\/\S+\s*$/i.test( event.content ) ) {
|
||||
// When a url is pasted or inserted, only try to embed it when it is in an empty paragrapgh.
|
||||
node = editor.dom.getParent( node, 'p' );
|
||||
|
||||
if ( node && /^[\s\uFEFF\u00A0]*$/.test( $( node ).text() || '' ) ) {
|
||||
// Make sure there are no empty inline elements in the <p>
|
||||
node.innerHTML = '';
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
node = editor.selection.getNode();
|
||||
event.content = wp.mce.views.setMarkers( event.content );
|
||||
});
|
||||
|
||||
// When a url is pasted, only try to embed it when pasted in an empty paragrapgh.
|
||||
if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/i ) &&
|
||||
( node.nodeName !== 'P' || node.parentNode !== editor.getBody() || ! editor.dom.isEmpty( node ) ) ) {
|
||||
return;
|
||||
// When pasting strip all tags and check if the string is an URL.
|
||||
// Then replace the pasted content with the cleaned URL.
|
||||
editor.on( 'pastePreProcess', function( event ) {
|
||||
var pastedStr = event.content;
|
||||
|
||||
if ( pastedStr ) {
|
||||
pastedStr = tinymce.trim( pastedStr.replace( /<[^>]+>/g, '' ) );
|
||||
|
||||
if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) {
|
||||
event.content = pastedStr;
|
||||
}
|
||||
}
|
||||
|
||||
event.content = wp.mce.views.toViews( event.content );
|
||||
});
|
||||
|
||||
// When the editor's content has been updated and the DOM has been
|
||||
@@ -229,10 +232,15 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
body = editor.getBody(),
|
||||
bodyRect = body.getBoundingClientRect(),
|
||||
first = body.firstChild,
|
||||
firstRect = first.getBoundingClientRect(),
|
||||
last = body.lastChild,
|
||||
lastRect = last.getBoundingClientRect(),
|
||||
view;
|
||||
firstRect, lastRect, view;
|
||||
|
||||
if ( ! first || ! last ) {
|
||||
return;
|
||||
}
|
||||
|
||||
firstRect = first.getBoundingClientRect();
|
||||
lastRect = last.getBoundingClientRect();
|
||||
|
||||
if ( y < firstRect.top && ( view = getView( first ) ) ) {
|
||||
setViewCursor( true, view );
|
||||
@@ -240,10 +248,14 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
} else if ( y > lastRect.bottom && ( view = getView( last ) ) ) {
|
||||
setViewCursor( false, view );
|
||||
event.preventDefault();
|
||||
} else {
|
||||
} else if ( x < bodyRect.left || x > bodyRect.right ) {
|
||||
tinymce.each( editor.dom.select( '.wpview-wrap' ), function( view ) {
|
||||
var rect = view.getBoundingClientRect();
|
||||
|
||||
if ( y < rect.top ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( y >= rect.top && y <= rect.bottom ) {
|
||||
if ( x < bodyRect.left ) {
|
||||
setViewCursor( true, view );
|
||||
@@ -252,7 +264,8 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
setViewCursor( false, view );
|
||||
event.preventDefault();
|
||||
}
|
||||
return;
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -304,17 +317,6 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
event.stopImmediatePropagation();
|
||||
event.preventDefault();
|
||||
|
||||
if ( ( event.type === 'touchend' || event.type === 'mousedown' ) && ! event.metaKey && ! event.ctrlKey ) {
|
||||
if ( editor.dom.hasClass( event.target, 'edit' ) ) {
|
||||
wp.mce.views.edit( view );
|
||||
editor.focus();
|
||||
return false;
|
||||
} else if ( editor.dom.hasClass( event.target, 'remove' ) ) {
|
||||
removeView( view );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( event.type === 'touchend' && scrolled ) {
|
||||
scrolled = false;
|
||||
} else {
|
||||
@@ -346,22 +348,31 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
}
|
||||
});
|
||||
|
||||
editor.on( 'PreProcess', function( event ) {
|
||||
// Empty the wpview wrap nodes
|
||||
tinymce.each( editor.dom.select( 'div[data-wpview-text]', event.node ), function( node ) {
|
||||
node.textContent = node.innerText = '\u00a0';
|
||||
});
|
||||
});
|
||||
function resetViews( rootNode ) {
|
||||
// Replace view nodes
|
||||
$( 'div[data-wpview-text]', rootNode ).each( function( i, node ) {
|
||||
var $node = $( node ),
|
||||
text = window.decodeURIComponent( $node.attr( 'data-wpview-text' ) || '' );
|
||||
|
||||
editor.on( 'PostProcess', function( event ) {
|
||||
if ( event.content ) {
|
||||
event.content = event.content.replace( /<div [^>]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g, function( match, shortcode ) {
|
||||
if ( shortcode ) {
|
||||
return '<p>' + window.decodeURIComponent( shortcode ) + '</p>';
|
||||
}
|
||||
return ''; // If error, remove the view wrapper
|
||||
});
|
||||
}
|
||||
if ( text && node.parentNode ) {
|
||||
$node.replaceWith( $( editor.dom.create('p') ).text( text ) );
|
||||
}
|
||||
});
|
||||
|
||||
// Remove marker attributes
|
||||
$( 'p[data-wpview-marker]', rootNode ).attr( 'data-wpview-marker', null );
|
||||
}
|
||||
|
||||
editor.on( 'PreProcess', function( event ) {
|
||||
// Replace the view nodes with their text in the DOM clone.
|
||||
resetViews( event.node );
|
||||
}, true );
|
||||
|
||||
editor.on( 'hide', function() {
|
||||
// Replace the view nodes with their text directly in the editor body.
|
||||
wp.mce.views.unbind();
|
||||
deselect();
|
||||
resetViews( editor.getBody() );
|
||||
});
|
||||
|
||||
// Excludes arrow keys, delete, backspace, enter, space bar.
|
||||
@@ -686,9 +697,42 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
}
|
||||
});
|
||||
|
||||
editor.addButton( 'wp_view_edit', {
|
||||
tooltip: 'Edit ', // trailing space is needed, used for context
|
||||
icon: 'dashicon dashicons-edit',
|
||||
onclick: function() {
|
||||
selected && wp.mce.views.edit( editor, selected );
|
||||
}
|
||||
} );
|
||||
|
||||
editor.addButton( 'wp_view_remove', {
|
||||
tooltip: 'Remove',
|
||||
icon: 'dashicon dashicons-no',
|
||||
onclick: function() {
|
||||
selected && removeView( selected );
|
||||
}
|
||||
} );
|
||||
|
||||
editor.once( 'preinit', function() {
|
||||
toolbar = editor.wp._createToolbar( [
|
||||
'wp_view_edit',
|
||||
'wp_view_remove'
|
||||
] );
|
||||
} );
|
||||
|
||||
editor.on( 'wptoolbar', function( event ) {
|
||||
if ( selected ) {
|
||||
event.element = selected;
|
||||
event.toolbar = toolbar;
|
||||
}
|
||||
} );
|
||||
|
||||
// Add to editor.wp
|
||||
editor.wp = editor.wp || {};
|
||||
editor.wp.getView = getView;
|
||||
|
||||
// Keep for back-compat.
|
||||
return {
|
||||
getViewText: getViewText,
|
||||
setViewText: setViewText,
|
||||
getView: getView
|
||||
};
|
||||
});
|
||||
+1
-1
@@ -1 +1 @@
|
||||
tinymce.PluginManager.add("wpview",function(a){function b(a){return c(a,"wpview-wrap")}function c(a,b){for(;a&&a.parentNode;){if(a.className&&-1!==(" "+a.className+" ").indexOf(" "+b+" "))return a;a=a.parentNode}return!1}function d(c){return(c=b(c))?window.decodeURIComponent(a.dom.getAttrib(c,"data-wpview-text")||""):""}function e(c,d){return c=b(c),c?(a.dom.setAttrib(c,"data-wpview-text",window.encodeURIComponent(d||"")),!0):!1}function f(a){a.stopPropagation()}function g(b,c){var d=b?"before":"after",e=b?0:1;k(),a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function h(b,c,d){var e=a.dom,f=e.create("p");u.ie&&u.ie<11||(f.innerHTML='<br data-mce-bogus="1">'),c?b.parentNode.insertBefore(f,b):e.insertAfter(f,b),k(),c&&d===v.ENTER?g(c,b):a.selection.setCursorLocation(f,0),a.nodeChanged()}function i(b){a.undoManager.transact(function(){h(b),a.dom.remove(b)})}function j(b){var c,e=a.dom;b&&b!==n&&(a.getBody().focus(),k(),n=b,e.setAttrib(b,"data-mce-selected",1),c=e.create("div",{"class":"wpview-clipboard",contenteditable:"true"},d(b)),a.dom.select(".wpview-body",b)[0].appendChild(c),e.bind(c,"beforedeactivate focusin focusout",f),e.bind(n,"beforedeactivate focusin focusout",f),A?a.selection.select(c):a.selection.select(c,!0),a.nodeChanged(),a.fire("wpview-selected",b))}function k(){var b,c=a.dom;n&&(b=a.dom.select(".wpview-clipboard",n)[0],c.unbind(b),c.remove(b),c.unbind(n,"beforedeactivate focusin focusout click mouseup",f),c.setAttrib(n,"data-mce-selected",null)),n=null}function l(a){return a.replace(/<div[^>]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?: |\u00a0)*<\/p><\/div>/g,"$1")}function m(a){return 47>=a&&a!==v.SPACEBAR&&a!==v.ENTER&&a!==v.DELETE&&a!==v.BACKSPACE&&(37>a||a>40)||a>=224||a>=144&&150>=a||a>=91&&93>=a||a>=112&&135>=a}var n,o,p,q,r,s,t,u=tinymce.Env,v=tinymce.util.VK,w=tinymce.dom.TreeWalker,x=!1,y=!0,z=function(){return!1},A=/iPad|iPod|iPhone/.test(navigator.userAgent);return"undefined"!=typeof wp&&wp.mce?(a.on("BeforeAddUndo",function(a){a.lastLevel&&l(a.level.content)===l(a.lastLevel.content)&&a.preventDefault()}),a.on("BeforeSetContent",function(b){var c;b.content&&(n&&i(n),c=a.selection.getNode(),(!b.content.match(/^\s*(https?:\/\/[^\s"]+)\s*$/i)||"P"===c.nodeName&&c.parentNode===a.getBody()&&a.dom.isEmpty(c))&&(b.content=wp.mce.views.toViews(b.content)))}),a.on("SetContent",function(){wp.mce.views.render()}),a.on("click",function(c){var d,e=c.clientX,f=c.clientY,h=a.getBody(),i=h.getBoundingClientRect(),j=h.firstChild,k=j.getBoundingClientRect(),l=h.lastChild,m=l.getBoundingClientRect();f<k.top&&(d=b(j))?(g(!0,d),c.preventDefault()):f>m.bottom&&(d=b(l))?(g(!1,d),c.preventDefault()):tinymce.each(a.dom.select(".wpview-wrap"),function(a){var b=a.getBoundingClientRect();return f>=b.top&&f<=b.bottom?void(e<i.left?(g(!0,a),c.preventDefault()):e>i.right&&(g(!1,a),c.preventDefault())):void 0})}),a.on("init",function(){var c=!1,d=a.selection,e=window.MutationObserver||window.WebKitMutationObserver;a.on("BeforeSetContent",function(){var c,e,f=b(d.getNode());f&&(!f.nextSibling||b(f.nextSibling)?(e=a.getDoc().createTextNode(""),a.dom.insertAfter(e,f)):(c=new w(f.nextSibling,f.nextSibling),e=c.next()),d.select(e),d.collapse(!0))}),a.dom.bind(a.getDoc(),"touchmove",function(){c=!0}),a.on("mousedown mouseup click touchend",function(d){var e=b(d.target);if(y=!1,e){if(d.stopImmediatePropagation(),d.preventDefault(),!("touchend"!==d.type&&"mousedown"!==d.type||d.metaKey||d.ctrlKey)){if(a.dom.hasClass(d.target,"edit"))return wp.mce.views.edit(e),a.focus(),!1;if(a.dom.hasClass(d.target,"remove"))return i(e),!1}return"touchend"===d.type&&c?c=!1:j(e),!1}("touchend"===d.type||"mousedown"===d.type)&&k(),"touchend"===d.type&&c&&(c=!1)},!0),e&&new e(function(){a.fire("wp-body-class-change")}).observe(a.getBody(),{attributes:!0,attributeFilter:["class"]})}),a.on("PreProcess",function(b){tinymce.each(a.dom.select("div[data-wpview-text]",b.node),function(a){a.textContent=a.innerText=" "})}),a.on("PostProcess",function(a){a.content&&(a.content=a.content.replace(/<div [^>]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g,function(a,b){return b?"<p>"+window.decodeURIComponent(b)+"</p>":""}))}),a.on("keydown",function(c){var d,e,f,l,o,q,r,s=c.keyCode,t=a.dom,u=a.selection;if(n){if((c.metaKey||c.ctrlKey)&&s!==v.BACKSPACE&&86!==s||s>=112&&123>=s)return void((c.metaKey||c.ctrlKey)&&88===s&&(x=n));if(e=b(u.getNode()),e!==n)return void k();s===v.LEFT?(g(!0,e),c.preventDefault()):s===v.UP?(e.previousSibling?b(e.previousSibling)?g(!0,e.previousSibling):(k(),u.select(e.previousSibling,!0),u.collapse()):g(!0,e),c.preventDefault()):s===v.RIGHT?(g(!1,e),c.preventDefault()):s===v.DOWN?(e.nextSibling?b(e.nextSibling)?g(!1,e.nextSibling):(k(),u.setCursorLocation(e.nextSibling,0)):g(!1,e),c.preventDefault()):m(s)||(i(n),(s===v.ENTER||s===v.DELETE||s===v.BACKSPACE)&&c.preventDefault())}else{if(c.metaKey||c.ctrlKey||s>=112&&123>=s)return;if(d=u.getNode()Line truncated
|
||||
tinymce.PluginManager.add("wpview",function(a){function b(a){return c(a,"wpview-wrap")}function c(a,b){for(;a&&a.parentNode;){if(a.className&&-1!==(" "+a.className+" ").indexOf(" "+b+" "))return a;a=a.parentNode}return!1}function d(a){a.stopPropagation()}function e(b,c){var d=b?"before":"after",e=b?0:1;i(),a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function f(b,c,d){var f=a.dom,g=f.create("p");v.ie&&v.ie<11||(g.innerHTML='<br data-mce-bogus="1">'),c?b.parentNode.insertBefore(g,b):f.insertAfter(g,b),i(),c&&d===w.ENTER?e(c,b):a.selection.setCursorLocation(g,0),a.nodeChanged()}function g(b){a.undoManager.transact(function(){f(b),wp.mce.views.remove(a,b)})}function h(b){var c,e=a.dom;b&&(b!==m&&(a.getBody().focus(),i(),m=b,e.setAttrib(b,"data-mce-selected",1),c=e.create("div",{"class":"wpview-clipboard",contenteditable:"true"},wp.mce.views.getText(b)),a.dom.select(".wpview-body",b)[0].appendChild(c),e.bind(c,"beforedeactivate focusin focusout",d),e.bind(m,"beforedeactivate focusin focusout",d),B?a.selection.select(c):a.selection.select(c,!0)),a.nodeChanged(),a.fire("wpview-selected",b))}function i(){var b,c=a.dom;m&&(b=a.dom.select(".wpview-clipboard",m)[0],c.unbind(b),c.remove(b),c.unbind(m,"beforedeactivate focusin focusout click mouseup",d),c.setAttrib(m,"data-mce-selected",null)),m=null}function j(a){return a=a.replace(/<div[^>]+data-wpview-text="([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>[^<>]*<\/p>\s*<\/div>/g,function(a,b){return"<p>"+window.decodeURIComponent(b)+"</p>"}),a.replace(/ data-wpview-marker="[^"]+"/g,"")}function k(b){u("div[data-wpview-text]",b).each(function(b,c){var d=u(c),e=window.decodeURIComponent(d.attr("data-wpview-text")||"");e&&c.parentNode&&d.replaceWith(u(a.dom.create("p")).text(e))}),u("p[data-wpview-marker]",b).attr("data-wpview-marker",null)}function l(a){return 47>=a&&a!==w.SPACEBAR&&a!==w.ENTER&&a!==w.DELETE&&a!==w.BACKSPACE&&(37>a||a>40)||a>=224||a>=144&&150>=a||a>=91&&93>=a||a>=112&&135>=a}var m,n,o,p,q,r,s,t,u=a.$,v=tinymce.Env,w=tinymce.util.VK,x=tinymce.dom.TreeWalker,y=!1,z=!0,A=function(){return!1},B=/iPad|iPod|iPhone/.test(navigator.userAgent);return"undefined"!=typeof wp&&wp.mce?(a.on("BeforeAddUndo",function(a){a.level.content&&(a.level.content=j(a.level.content))}),a.on("BeforeSetContent",function(b){var c;if(b.selection||wp.mce.views.unbind(),b.content){if(!b.load&&(m&&g(m),c=a.selection.getNode(),c&&c!==a.getBody()&&/^\s*https?:\/\/\S+\s*$/i.test(b.content))){if(c=a.dom.getParent(c,"p"),!c||!/^[\s\uFEFF\u00A0]*$/.test(u(c).text()||""))return;c.innerHTML=""}b.content=wp.mce.views.setMarkers(b.content)}}),a.on("pastePreProcess",function(a){var b=a.content;b&&(b=tinymce.trim(b.replace(/<[^>]+>/g,"")),/^https?:\/\/\S+$/i.test(b)&&(a.content=b))}),a.on("SetContent",function(){wp.mce.views.render()}),a.on("click",function(c){var d,f,g,h=c.clientX,i=c.clientY,j=a.getBody(),k=j.getBoundingClientRect(),l=j.firstChild,m=j.lastChild;l&&m&&(d=l.getBoundingClientRect(),f=m.getBoundingClientRect(),i<d.top&&(g=b(l))?(e(!0,g),c.preventDefault()):i>f.bottom&&(g=b(m))?(e(!1,g),c.preventDefault()):(h<k.left||h>k.right)&&tinymce.each(a.dom.select(".wpview-wrap"),function(a){var b=a.getBoundingClientRect();return i<b.top?!1:i>=b.top&&i<=b.bottom?(h<k.left?(e(!0,a),c.preventDefault()):h>k.right&&(e(!1,a),c.preventDefault()),!1):void 0}))}),a.on("init",function(){var c=!1,d=a.selection,e=window.MutationObserver||window.WebKitMutationObserver;a.on("BeforeSetContent",function(){var c,e,f=b(d.getNode());f&&(!f.nextSibling||b(f.nextSibling)?(e=a.getDoc().createTextNode(""),a.dom.insertAfter(e,f)):(c=new x(f.nextSibling,f.nextSibling),e=c.next()),d.select(e),d.collapse(!0))}),a.dom.bind(a.getDoc(),"touchmove",function(){c=!0}),a.on("mousedown mouseup click touchend",function(a){var d=b(a.target);return z=!1,d?(a.stopImmediatePropagation(),a.preventDefault(),"touchend"===a.type&&c?c=!1:h(d),!1):(("touchend"===a.type||"mousedown"===a.type)&&i(),void("touchend"===a.type&&c&&(c=!1)))},!0),e&&new e(function(){a.fire("wp-body-class-change")}).observe(a.getBody(),{attributes:!0,attributeFilter:["class"]})}),a.on("PreProcess",function(a){k(a.node)},!0),a.on("hide",function(){wp.mce.views.unbind(),i(),k(a.getBody())}),a.on("keydown",function(c){var d,j,k,n,p,q,r,s=c.keyCode,t=a.dom,u=a.selection;if(m){if((c.metaKey||c.ctrlKey)&&s!==w.BACKSPACE&&86!==s||s>=112&&123>=s)return void((c.metaKey||c.ctrlKey)&&88===s&&(y=m));if(j=b(u.getNode()),j!==m)return void i();s===w.LEFT?(e(!0,j),c.preventDefault()):s===w.UP?(j.previousSibling?b(j.previousSibling)?e(!0,j.previousSibling):(i(),u.select(j.previousSibling,!0),u.collapse()):e(!0,j),c.preventDefault()):s===w.RIGHT?(e(!1,j),c.preventDefault()):s===w.DOWN?(j.nextSibling?b(j.nextSibling)?e(!1,j.nextSibling):(i(),u.setCursorLocation(j.nextSibling,0)):e(!1,j),c.preventDefault()):l(s)||(g(m),(s===w.ENTER||s===w.DELETE||s===w.BACKSPACE)&&c.preventDefault())}else{if(c.metaKey||c.ctrlKey||s>=112&&123>=s)returnLine truncated
|
||||
Reference in new issue
Block a user