init
This commit is contained in:
commit
ff6f6c80cd
1709 changed files with 840760 additions and 0 deletions
202
wp-includes/js/tinymce/plugins/wpview/plugin.js
Normal file
202
wp-includes/js/tinymce/plugins/wpview/plugin.js
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
/**
|
||||
* WordPress View plugin.
|
||||
*/
|
||||
( function( tinymce, wp ) {
|
||||
tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||
function noop () {}
|
||||
|
||||
if ( ! wp || ! wp.mce || ! wp.mce.views ) {
|
||||
return {
|
||||
getView: noop
|
||||
};
|
||||
}
|
||||
|
||||
// Check if a node is a view or not.
|
||||
function isView( node ) {
|
||||
return editor.dom.hasClass( node, 'wpview' );
|
||||
}
|
||||
|
||||
// Replace view tags with their text.
|
||||
function resetViews( content ) {
|
||||
function callback( match, $1 ) {
|
||||
return '<p>' + window.decodeURIComponent( $1 ) + '</p>';
|
||||
}
|
||||
|
||||
if ( ! content ) {
|
||||
return content;
|
||||
}
|
||||
|
||||
return content
|
||||
.replace( /<div[^>]+data-wpview-text="([^"]+)"[^>]*>(?:\.|[\s\S]+?wpview-end[^>]+>\s*<\/span>\s*)?<\/div>/g, callback )
|
||||
.replace( /<p[^>]+data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g, callback );
|
||||
}
|
||||
|
||||
editor.on( 'init', function() {
|
||||
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
|
||||
|
||||
if ( MutationObserver ) {
|
||||
new MutationObserver( function() {
|
||||
editor.fire( 'wp-body-class-change' );
|
||||
} )
|
||||
.observe( editor.getBody(), {
|
||||
attributes: true,
|
||||
attributeFilter: ['class']
|
||||
} );
|
||||
}
|
||||
|
||||
// Pass on body class name changes from the editor to the wpView iframes.
|
||||
editor.on( 'wp-body-class-change', function() {
|
||||
var className = editor.getBody().className;
|
||||
|
||||
editor.$( 'iframe[class="wpview-sandbox"]' ).each( function( i, iframe ) {
|
||||
// Make sure it is a local iframe
|
||||
// jshint scripturl: true
|
||||
if ( ! iframe.src || iframe.src === 'javascript:""' ) {
|
||||
try {
|
||||
iframe.contentWindow.document.body.className = className;
|
||||
} catch( er ) {}
|
||||
}
|
||||
});
|
||||
} );
|
||||
});
|
||||
|
||||
// Scan new content for matching view patterns and replace them with markers.
|
||||
editor.on( 'beforesetcontent', function( event ) {
|
||||
var node;
|
||||
|
||||
if ( ! event.selection ) {
|
||||
wp.mce.views.unbind();
|
||||
}
|
||||
|
||||
if ( ! event.content ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! event.load ) {
|
||||
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( editor.$( node ).text() || '' ) ) {
|
||||
// Make sure there are no empty inline elements in the <p>
|
||||
node.innerHTML = '';
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event.content = wp.mce.views.setMarkers( event.content, editor );
|
||||
} );
|
||||
|
||||
// Replace any new markers nodes with views.
|
||||
editor.on( 'setcontent', function() {
|
||||
wp.mce.views.render();
|
||||
} );
|
||||
|
||||
// Empty view nodes for easier processing.
|
||||
editor.on( 'preprocess hide', function( event ) {
|
||||
editor.$( 'div[data-wpview-text], p[data-wpview-marker]', event.node ).each( function( i, node ) {
|
||||
node.innerHTML = '.';
|
||||
} );
|
||||
}, true );
|
||||
|
||||
// Replace views with their text.
|
||||
editor.on( 'postprocess', function( event ) {
|
||||
event.content = resetViews( event.content );
|
||||
} );
|
||||
|
||||
// Replace views with their text inside undo levels.
|
||||
// This also prevents that new levels are added when there are changes inside the views.
|
||||
editor.on( 'beforeaddundo', function( event ) {
|
||||
event.level.content = resetViews( event.level.content );
|
||||
} );
|
||||
|
||||
// Make sure views are copied as their text.
|
||||
editor.on( 'drop objectselected', function( event ) {
|
||||
if ( isView( event.targetClone ) ) {
|
||||
event.targetClone = editor.getDoc().createTextNode(
|
||||
window.decodeURIComponent( editor.dom.getAttrib( event.targetClone, 'data-wpview-text' ) )
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
||||
// Clean up URLs for easier processing.
|
||||
editor.on( 'pastepreprocess', function( event ) {
|
||||
var content = event.content;
|
||||
|
||||
if ( content ) {
|
||||
content = tinymce.trim( content.replace( /<[^>]+>/g, '' ) );
|
||||
|
||||
if ( /^https?:\/\/\S+$/i.test( content ) ) {
|
||||
event.content = content;
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
// Show the view type in the element path.
|
||||
editor.on( 'resolvename', function( event ) {
|
||||
if ( isView( event.target ) ) {
|
||||
event.name = editor.dom.getAttrib( event.target, 'data-wpview-type' ) || 'object';
|
||||
}
|
||||
} );
|
||||
|
||||
// See `media` plugin.
|
||||
editor.on( 'click keyup', function() {
|
||||
var node = editor.selection.getNode();
|
||||
|
||||
if ( isView( node ) ) {
|
||||
if ( editor.dom.getAttrib( node, 'data-mce-selected' ) ) {
|
||||
node.setAttribute( 'data-mce-selected', '2' );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
editor.addButton( 'wp_view_edit', {
|
||||
tooltip: 'Edit|button', // '|button' is not displayed, only used for context
|
||||
icon: 'dashicon dashicons-edit',
|
||||
onclick: function() {
|
||||
var node = editor.selection.getNode();
|
||||
|
||||
if ( isView( node ) ) {
|
||||
wp.mce.views.edit( editor, node );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
editor.addButton( 'wp_view_remove', {
|
||||
tooltip: 'Remove',
|
||||
icon: 'dashicon dashicons-no',
|
||||
onclick: function() {
|
||||
editor.fire( 'cut' );
|
||||
}
|
||||
} );
|
||||
|
||||
editor.once( 'preinit', function() {
|
||||
var toolbar;
|
||||
|
||||
if ( editor.wp && editor.wp._createToolbar ) {
|
||||
toolbar = editor.wp._createToolbar( [
|
||||
'wp_view_edit',
|
||||
'wp_view_remove'
|
||||
] );
|
||||
|
||||
editor.on( 'wptoolbar', function( event ) {
|
||||
if ( ! event.collapsed && isView( event.element ) ) {
|
||||
event.toolbar = toolbar;
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
editor.wp = editor.wp || {};
|
||||
editor.wp.getView = noop;
|
||||
editor.wp.setViewCursor = noop;
|
||||
|
||||
return {
|
||||
getView: noop
|
||||
};
|
||||
} );
|
||||
} )( window.tinymce, window.wp );
|
||||
1
wp-includes/js/tinymce/plugins/wpview/plugin.min.js
vendored
Normal file
1
wp-includes/js/tinymce/plugins/wpview/plugin.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
!function(a,b){a.PluginManager.add("wpview",function(c){function d(){}function e(a){return c.dom.hasClass(a,"wpview")}function f(a){function b(a,b){return"<p>"+window.decodeURIComponent(b)+"</p>"}return a?a.replace(/<div[^>]+data-wpview-text="([^"]+)"[^>]*>(?:\.|[\s\S]+?wpview-end[^>]+>\s*<\/span>\s*)?<\/div>/g,b).replace(/<p[^>]+data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g,b):a}return b&&b.mce&&b.mce.views?(c.on("init",function(){var a=window.MutationObserver||window.WebKitMutationObserver;a&&new a(function(){c.fire("wp-body-class-change")}).observe(c.getBody(),{attributes:!0,attributeFilter:["class"]}),c.on("wp-body-class-change",function(){var a=c.getBody().className;c.$('iframe[class="wpview-sandbox"]').each(function(b,c){if(!c.src||'javascript:""'===c.src)try{c.contentWindow.document.body.className=a}catch(d){}})})}),c.on("beforesetcontent",function(a){var d;if(a.selection||b.mce.views.unbind(),a.content){if(!a.load&&(d=c.selection.getNode(),d&&d!==c.getBody()&&/^\s*https?:\/\/\S+\s*$/i.test(a.content))){if(d=c.dom.getParent(d,"p"),!d||!/^[\s\uFEFF\u00A0]*$/.test(c.$(d).text()||""))return;d.innerHTML=""}a.content=b.mce.views.setMarkers(a.content,c)}}),c.on("setcontent",function(){b.mce.views.render()}),c.on("preprocess hide",function(a){c.$("div[data-wpview-text], p[data-wpview-marker]",a.node).each(function(a,b){b.innerHTML="."})},!0),c.on("postprocess",function(a){a.content=f(a.content)}),c.on("beforeaddundo",function(a){a.level.content=f(a.level.content)}),c.on("drop objectselected",function(a){e(a.targetClone)&&(a.targetClone=c.getDoc().createTextNode(window.decodeURIComponent(c.dom.getAttrib(a.targetClone,"data-wpview-text"))))}),c.on("pastepreprocess",function(b){var c=b.content;c&&(c=a.trim(c.replace(/<[^>]+>/g,"")),/^https?:\/\/\S+$/i.test(c)&&(b.content=c))}),c.on("resolvename",function(a){e(a.target)&&(a.name=c.dom.getAttrib(a.target,"data-wpview-type")||"object")}),c.on("click keyup",function(){var a=c.selection.getNode();e(a)&&c.dom.getAttrib(a,"data-mce-selected")&&a.setAttribute("data-mce-selected","2")}),c.addButton("wp_view_edit",{tooltip:"Edit|button",icon:"dashicon dashicons-edit",onclick:function(){var a=c.selection.getNode();e(a)&&b.mce.views.edit(c,a)}}),c.addButton("wp_view_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",onclick:function(){c.fire("cut")}}),c.once("preinit",function(){var a;c.wp&&c.wp._createToolbar&&(a=c.wp._createToolbar(["wp_view_edit","wp_view_remove"]),c.on("wptoolbar",function(b){!b.collapsed&&e(b.element)&&(b.toolbar=a)}))}),c.wp=c.wp||{},c.wp.getView=d,c.wp.setViewCursor=d,{getView:d}):{getView:d}})}(window.tinymce,window.wp);
|
||||
Loading…
Add table
Add a link
Reference in a new issue