2013-11-15 06:18:10 +01:00
|
|
|
/* global tinymce */
|
2012-09-24 02:13:18 +02:00
|
|
|
/**
|
|
|
|
* WordPress View plugin.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
2012-10-12 05:28:22 +02:00
|
|
|
var VK = tinymce.VK,
|
|
|
|
TreeWalker = tinymce.dom.TreeWalker,
|
|
|
|
selected;
|
2012-10-12 01:52:09 +02:00
|
|
|
|
2012-09-24 02:13:18 +02:00
|
|
|
tinymce.create('tinymce.plugins.wpView', {
|
2013-11-15 06:18:10 +01:00
|
|
|
init : function( editor ) {
|
2012-10-12 05:28:22 +02:00
|
|
|
var wpView = this;
|
2012-09-24 02:13:18 +02:00
|
|
|
|
|
|
|
// Check if the `wp.mce` API exists.
|
2013-12-30 02:54:11 +01:00
|
|
|
if ( typeof wp === 'undefined' || ! wp.mce ) {
|
2012-09-24 02:13:18 +02:00
|
|
|
return;
|
2013-12-30 02:54:11 +01:00
|
|
|
}
|
2012-09-24 02:13:18 +02:00
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
editor.on( 'PreInit', function() {
|
2012-09-24 02:13:18 +02:00
|
|
|
// Add elements so we can set `contenteditable` to false.
|
|
|
|
editor.schema.addValidElements('div[*],span[*]');
|
|
|
|
});
|
|
|
|
|
|
|
|
// When the editor's content changes, scan the new content for
|
|
|
|
// matching view patterns, and transform the matches into
|
|
|
|
// view wrappers. Since the editor's DOM is outdated at this point,
|
|
|
|
// we'll wait to render the views.
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
editor.on( 'BeforeSetContent', function( e ) {
|
2013-12-30 02:54:11 +01:00
|
|
|
if ( ! e.content ) {
|
2012-09-24 02:13:18 +02:00
|
|
|
return;
|
2013-12-30 02:54:11 +01:00
|
|
|
}
|
2012-09-24 02:13:18 +02:00
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
e.content = wp.mce.view.toViews( e.content );
|
2012-09-24 02:13:18 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// When the editor's content has been updated and the DOM has been
|
|
|
|
// processed, render the views in the document.
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
editor.on( 'SetContent', function() {
|
2012-09-24 02:13:18 +02:00
|
|
|
wp.mce.view.render( editor.getDoc() );
|
|
|
|
});
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
editor.on( 'init', function() {
|
|
|
|
var selection = editor.selection;
|
2012-10-12 05:28:22 +02:00
|
|
|
// When a view is selected, ensure content that is being pasted
|
|
|
|
// or inserted is added to a text node (instead of the view).
|
2013-12-30 02:54:11 +01:00
|
|
|
editor.on( 'BeforeSetContent', function() {
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
var walker, target,
|
|
|
|
view = wpView.getParentView( selection.getNode() );
|
2012-10-12 05:28:22 +02:00
|
|
|
|
|
|
|
// If the selection is not within a view, bail.
|
2013-12-30 02:54:11 +01:00
|
|
|
if ( ! view ) {
|
2012-10-12 05:28:22 +02:00
|
|
|
return;
|
2013-12-30 02:54:11 +01:00
|
|
|
}
|
2012-10-12 05:28:22 +02:00
|
|
|
|
|
|
|
// If there are no additional nodes or the next node is a
|
|
|
|
// view, create a text node after the current view.
|
|
|
|
if ( ! view.nextSibling || wpView.isView( view.nextSibling ) ) {
|
|
|
|
target = editor.getDoc().createTextNode('');
|
|
|
|
editor.dom.insertAfter( target, view );
|
|
|
|
|
|
|
|
// Otherwise, find the next text node.
|
|
|
|
} else {
|
|
|
|
walker = new TreeWalker( view.nextSibling, view.nextSibling );
|
|
|
|
target = walker.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select the `target` text node.
|
|
|
|
selection.select( target );
|
|
|
|
selection.collapse( true );
|
|
|
|
});
|
|
|
|
|
2012-09-24 02:13:18 +02:00
|
|
|
// When the selection's content changes, scan any new content
|
|
|
|
// for matching views and immediately render them.
|
|
|
|
//
|
|
|
|
// Runs on paste and on inserting nodes/html.
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
editor.on( 'SetContent', function( e ) {
|
2013-12-30 02:54:11 +01:00
|
|
|
if ( ! e.context ) {
|
2012-09-24 02:13:18 +02:00
|
|
|
return;
|
2013-12-30 02:54:11 +01:00
|
|
|
}
|
2012-09-24 02:13:18 +02:00
|
|
|
|
|
|
|
var node = selection.getNode();
|
|
|
|
|
2013-12-30 02:54:11 +01:00
|
|
|
if ( ! node.innerHTML ) {
|
2012-09-24 02:13:18 +02:00
|
|
|
return;
|
2013-12-30 02:54:11 +01:00
|
|
|
}
|
2012-09-24 02:13:18 +02:00
|
|
|
|
|
|
|
node.innerHTML = wp.mce.view.toViews( node.innerHTML );
|
|
|
|
wp.mce.view.render( node );
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// When the editor's contents are being accessed as a string,
|
|
|
|
// transform any views back to their text representations.
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
editor.on( 'PostProcess', function( e ) {
|
2013-12-30 02:54:11 +01:00
|
|
|
if ( ( ! e.get && ! e.save ) || ! e.content ) {
|
2012-09-24 02:13:18 +02:00
|
|
|
return;
|
2013-12-30 02:54:11 +01:00
|
|
|
}
|
2012-09-24 02:13:18 +02:00
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
e.content = wp.mce.view.toText( e.content );
|
2012-09-24 02:13:18 +02:00
|
|
|
});
|
2012-10-12 01:52:09 +02:00
|
|
|
|
|
|
|
// Triggers when the selection is changed.
|
2012-10-12 05:28:22 +02:00
|
|
|
// Add the event handler to the top of the stack.
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
editor.on( 'NodeChange', function( e ) {
|
2013-12-30 02:54:11 +01:00
|
|
|
var view = wpView.getParentView( e.element );
|
2012-10-12 01:52:09 +02:00
|
|
|
|
2012-10-12 05:28:22 +02:00
|
|
|
// Update the selected view.
|
|
|
|
if ( view ) {
|
|
|
|
wpView.select( view );
|
|
|
|
|
|
|
|
// Prevent the selection from propagating to other plugins.
|
|
|
|
return false;
|
|
|
|
|
2012-10-12 01:52:09 +02:00
|
|
|
// If we've clicked off of the selected view, deselect it.
|
2012-10-12 05:28:22 +02:00
|
|
|
} else {
|
|
|
|
wpView.deselect();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
editor.on( 'keydown', function( event ) {
|
2012-10-12 05:28:22 +02:00
|
|
|
var keyCode = event.keyCode,
|
|
|
|
view, instance;
|
2012-10-12 01:52:09 +02:00
|
|
|
|
2012-10-12 05:28:22 +02:00
|
|
|
// If a view isn't selected, let the event go on its merry way.
|
2013-12-30 02:54:11 +01:00
|
|
|
if ( ! selected ) {
|
2012-10-12 01:52:09 +02:00
|
|
|
return;
|
2013-12-30 02:54:11 +01:00
|
|
|
}
|
2012-10-12 01:52:09 +02:00
|
|
|
|
2012-10-12 05:28:22 +02:00
|
|
|
// If the caret is not within the selected view, deselect the
|
|
|
|
// view and bail.
|
2013-12-30 02:54:11 +01:00
|
|
|
view = wpView.getParentView( editor.selection.getNode() );
|
2012-10-12 05:28:22 +02:00
|
|
|
if ( view !== selected ) {
|
|
|
|
wpView.deselect();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If delete or backspace is pressed, delete the view.
|
|
|
|
if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) {
|
|
|
|
if ( (instance = wp.mce.view.instance( selected )) ) {
|
|
|
|
instance.remove();
|
|
|
|
wpView.deselect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let keypresses that involve the command or control keys through.
|
|
|
|
// Also, let any of the F# keys through.
|
2013-12-30 02:54:11 +01:00
|
|
|
if ( event.metaKey || event.ctrlKey || ( keyCode >= 112 && keyCode <= 123 ) ) {
|
2012-10-12 05:28:22 +02:00
|
|
|
return;
|
2013-12-30 02:54:11 +01:00
|
|
|
}
|
2012-10-12 01:52:09 +02:00
|
|
|
|
2012-10-12 05:28:22 +02:00
|
|
|
event.preventDefault();
|
2012-10-12 01:52:09 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
getParentView : function( node ) {
|
|
|
|
while ( node ) {
|
2013-12-30 02:54:11 +01:00
|
|
|
if ( this.isView( node ) ) {
|
2012-10-12 01:52:09 +02:00
|
|
|
return node;
|
2013-12-30 02:54:11 +01:00
|
|
|
}
|
2012-10-12 01:52:09 +02:00
|
|
|
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
2012-09-24 02:13:18 +02:00
|
|
|
},
|
|
|
|
|
2012-10-12 05:28:22 +02:00
|
|
|
isView : function( node ) {
|
|
|
|
return (/(?:^|\s)wp-view-wrap(?:\s|$)/).test( node.className );
|
|
|
|
},
|
|
|
|
|
|
|
|
select : function( view ) {
|
2013-12-30 02:54:11 +01:00
|
|
|
if ( view === selected ) {
|
2012-10-12 05:28:22 +02:00
|
|
|
return;
|
2013-12-30 02:54:11 +01:00
|
|
|
}
|
2012-10-12 05:28:22 +02:00
|
|
|
|
|
|
|
this.deselect();
|
|
|
|
selected = view;
|
|
|
|
wp.mce.view.select( selected );
|
|
|
|
},
|
|
|
|
|
|
|
|
deselect : function() {
|
2013-12-30 02:54:11 +01:00
|
|
|
if ( selected ) {
|
2012-10-12 05:28:22 +02:00
|
|
|
wp.mce.view.deselect( selected );
|
2013-12-30 02:54:11 +01:00
|
|
|
}
|
|
|
|
|
2012-10-12 05:28:22 +02:00
|
|
|
selected = null;
|
2012-09-24 02:13:18 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Register plugin
|
|
|
|
tinymce.PluginManager.add( 'wpview', tinymce.plugins.wpView );
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-29 00:53:15 +01:00
|
|
|
})();
|