This commit is contained in:
root@pico committed 2015-05-01 21:20:47 +02:00
1 parent 70d2335bba
commit 7428b67da5
1086 files changed
+94145 -59082

No files matched your search

@@ -4,9 +4,16 @@
tinymce.ui.FloatPanel.zIndex = 100100;
tinymce.PluginManager.add( 'wordpress', function( editor ) {
var DOM = tinymce.DOM, wpAdvButton, modKey, style,
var DOM = tinymce.DOM,
each = tinymce.each,
__ = editor.editorManager.i18n.translate,
wpAdvButton, style,
last = 0;
if ( typeof window.jQuery !== 'undefined' ) {
window.jQuery( document ).triggerHandler( 'tinymce-editor-setup', [ editor ] );
}
function toggleToolbars( state ) {
var iframe, initial, toolbars,
pixels = 0;
@@ -25,7 +32,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
state = 'hide';
}
tinymce.each( toolbars, function( toolbar, i ) {
each( toolbars, function( toolbar, i ) {
if ( i > 0 ) {
if ( state === 'hide' ) {
toolbar.hide();
@@ -87,7 +94,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
if ( e.content ) {
if ( e.content.indexOf( '<!--more' ) !== -1 ) {
title = editor.editorManager.i18n.translate( 'Read more...' );
title = __( 'Read more...' );
e.content = e.content.replace( /<!--more(.*?)-->/g, function( match, moretext ) {
return '<img src="' + tinymce.Env.transparentSrc + '" data-wp-more="more" data-wp-more-text="' + moretext + '" ' +
@@ -96,7 +103,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
}
if ( e.content.indexOf( '<!--nextpage-->' ) !== -1 ) {
title = editor.editorManager.i18n.translate( 'Page break' );
title = __( 'Page break' );
e.content = e.content.replace( /<!--nextpage-->/g,
'<img src="' + tinymce.Env.transparentSrc + '" data-wp-more="nextpage" class="wp-more-tag mce-wp-nextpage" ' +
@@ -145,7 +152,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
tag = tag || 'more';
classname += ' mce-wp-' + tag;
title = tag === 'more' ? 'Read more...' : 'Next page';
title = editor.editorManager.i18n.translate( title );
title = __( title );
html = '<img src="' + tinymce.Env.transparentSrc + '" title="' + title + '" class="' + classname + '" ' +
'data-wp-more="' + tag + '" data-mce-resize="false" data-mce-placeholder="1" />';
@@ -189,8 +196,8 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
title: 'Keyboard Shortcuts',
width: 450,
height: 420,
inline: 1,
classes: 'wp-help'
classes: 'wp-help',
buttons: { text: 'Close', onclick: 'close' }
});
});
@@ -305,7 +312,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
bodyClass.push('wp-editor');
tinymce.each( bodyClass, function( cls ) {
each( bodyClass, function( cls ) {
if ( cls ) {
dom.addClass( doc.body, cls );
}
@@ -347,7 +354,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
editor.on( 'PastePostProcess', function( event ) {
// Remove empty paragraphs
tinymce.each( dom.select( 'p', event.node ), function( node ) {
each( dom.select( 'p', event.node ), function( node ) {
if ( dom.isEmpty( node ) ) {
dom.remove( node );
}
@@ -390,8 +397,10 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
// Remove spaces from empty paragraphs.
editor.on( 'BeforeSetContent', function( event ) {
var paragraph = tinymce.Env.webkit ? '<p><br /></p>' : '<p></p>';
if ( event.content ) {
event.content = event.content.replace( /<p>(?:&nbsp;|\u00a0|\uFEFF| )+<\/p>/gi, '<p></p>' );
event.content = event.content.replace( /<p>(?:&nbsp;|\u00a0|\uFEFF|\s)+<\/p>/gi, paragraph );
}
});
@@ -402,112 +411,344 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
if ( tinymce.Env.iOS ) {
editor.settings.height = 300;
}
});
// Add custom shortcuts
modKey = 'alt+shift';
each( {
c: 'JustifyCenter',
r: 'JustifyRight',
l: 'JustifyLeft',
j: 'JustifyFull',
q: 'mceBlockQuote',
u: 'InsertUnorderedList',
o: 'InsertOrderedList',
s: 'unlink',
m: 'WP_Medialib',
z: 'WP_Adv',
t: 'WP_More',
d: 'Strikethrough',
h: 'WP_Help',
p: 'WP_Page',
x: 'WP_Code'
}, function( command, key ) {
editor.shortcuts.add( 'access+' + key, '', command );
} );
editor.addShortcut( modKey + '+c', '', 'JustifyCenter' );
editor.addShortcut( modKey + '+r', '', 'JustifyRight' );
editor.addShortcut( modKey + '+l', '', 'JustifyLeft' );
editor.addShortcut( modKey + '+j', '', 'JustifyFull' );
editor.addShortcut( modKey + '+q', '', 'mceBlockQuote' );
editor.addShortcut( modKey + '+u', '', 'InsertUnorderedList' );
editor.addShortcut( modKey + '+o', '', 'InsertOrderedList' );
editor.addShortcut( modKey + '+n', '', 'mceSpellCheck' );
editor.addShortcut( modKey + '+s', '', 'unlink' );
editor.addShortcut( modKey + '+m', '', 'WP_Medialib' );
editor.addShortcut( modKey + '+z', '', 'WP_Adv' );
editor.addShortcut( modKey + '+t', '', 'WP_More' );
editor.addShortcut( modKey + '+d', '', 'Strikethrough' );
editor.addShortcut( modKey + '+h', '', 'WP_Help' );
editor.addShortcut( modKey + '+p', '', 'WP_Page' );
editor.addShortcut( modKey + '+x', '', 'WP_Code' );
editor.addShortcut( 'ctrl+s', '', function() {
if ( typeof wp !== 'undefined' && wp.autosave ) {
wp.autosave.server.triggerSave();
}
});
editor.addShortcut( 'ctrl+s', '', function() {
if ( typeof wp !== 'undefined' && wp.autosave ) {
wp.autosave.server.triggerSave();
}
} );
} );
// popup buttons for the gallery, etc.
editor.on( 'init', function() {
editor.dom.bind( editor.getWin(), 'scroll', function() {
_hideButtons();
});
/**
* Experimental: create a floating toolbar.
* This functionality will change in the next releases. Not recommended for use by plugins.
*/
( function() {
var Factory = tinymce.ui.Factory,
settings = editor.settings,
currentToolbar,
currentSelection;
editor.dom.bind( editor.getBody(), 'dragstart', function() {
_hideButtons();
});
});
function create( buttons ) {
var toolbar,
toolbarItems = [],
buttonGroup;
editor.on( 'BeforeExecCommand', function() {
_hideButtons();
});
each( buttons, function( item ) {
var itemName;
editor.on( 'SaveContent', function() {
_hideButtons();
});
function bindSelectorChanged() {
var selection = editor.selection;
editor.on( 'MouseDown', function( e ) {
if ( e.target.nodeName !== 'IMG' ) {
_hideButtons();
}
});
if ( itemName === 'bullist' ) {
selection.selectorChanged( 'ul > li', function( state, args ) {
var i = args.parents.length,
nodeName;
editor.on( 'keydown', function( e ) {
if ( e.which === tinymce.util.VK.DELETE || e.which === tinymce.util.VK.BACKSPACE ) {
_hideButtons();
}
});
while ( i-- ) {
nodeName = args.parents[ i ].nodeName;
// Internal functions
function _setEmbed( c ) {
return c.replace( /\[embed\]([\s\S]+?)\[\/embed\][\s\u00a0]*/g, function( a, b ) {
return '<img width="300" height="200" src="' + tinymce.Env.transparentSrc + '" class="wp-oembed" ' +
'alt="'+ b +'" title="'+ b +'" data-mce-resize="false" data-mce-placeholder="1" />';
});
}
if ( nodeName === 'OL' || nodeName == 'UL' ) {
break;
}
}
function _getEmbed( c ) {
return c.replace( /<img[^>]+>/g, function( a ) {
if ( a.indexOf('class="wp-oembed') !== -1 ) {
var u = a.match( /alt="([^\"]+)"/ );
item.active( state && nodeName === 'UL' );
} );
}
if ( u[1] ) {
a = '[embed]' + u[1] + '[/embed]';
if ( itemName === 'numlist' ) {
selection.selectorChanged( 'ol > li', function( state, args ) {
var i = args.parents.length,
nodeName;
while ( i-- ) {
nodeName = args.parents[ i ].nodeName;
if ( nodeName === 'OL' || nodeName === 'UL' ) {
break;
}
}
item.active( state && nodeName === 'OL' );
} );
}
if ( item.settings.stateSelector ) {
selection.selectorChanged( item.settings.stateSelector, function( state ) {
item.active( state );
}, true );
}
if ( item.settings.disabledStateSelector ) {
selection.selectorChanged( item.settings.disabledStateSelector, function( state ) {
item.disabled( state );
} );
}
}
if ( item === '|' ) {
buttonGroup = null;
} else {
if ( Factory.has( item ) ) {
item = {
type: item
};
if ( settings.toolbar_items_size ) {
item.size = settings.toolbar_items_size;
}
toolbarItems.push( item );
buttonGroup = null;
} else {
if ( ! buttonGroup ) {
buttonGroup = {
type: 'buttongroup',
items: []
};
toolbarItems.push( buttonGroup );
}
if ( editor.buttons[ item ] ) {
itemName = item;
item = editor.buttons[ itemName ];
if ( typeof item === 'function' ) {
item = item();
}
item.type = item.type || 'button';
if ( settings.toolbar_items_size ) {
item.size = settings.toolbar_items_size;
}
item = Factory.create( item );
buttonGroup.items.push( item );
if ( editor.initialized ) {
bindSelectorChanged();
} else {
editor.on( 'init', bindSelectorChanged );
}
}
}
}
} );
toolbar = Factory.create( {
type: 'panel',
layout: 'stack',
classes: 'toolbar-grp inline-toolbar-grp',
ariaRoot: true,
ariaRemember: true,
items: [ {
type: 'toolbar',
layout: 'flow',
items: toolbarItems
} ]
} );
function hide() {
toolbar.hide();
}
return a;
});
}
function reposition() {
var top, left, minTop, className,
windowPos, adminbar, mceToolbar, boundary,
boundaryMiddle, boundaryVerticalMiddle, spaceTop,
spaceBottom, windowWidth, toolbarWidth, toolbarHalf,
iframe, iframePos, iframeWidth, iframeHeigth,
toolbarNodeHeight, verticalSpaceNeeded,
toolbarNode = this.getEl(),
buffer = 5,
margin = 8,
adminbarHeight = 0;
function _showButtons( n, id ) {
var p1, p2, vp, X, Y;
if ( ! currentSelection ) {
return;
}
vp = editor.dom.getViewPort( editor.getWin() );
p1 = DOM.getPos( editor.getContentAreaContainer() );
p2 = editor.dom.getPos( n );
windowPos = window.pageYOffset || document.documentElement.scrollTop;
adminbar = tinymce.$( '#wpadminbar' )[0];
mceToolbar = tinymce.$( '.mce-toolbar-grp', editor.getContainer() )[0];
boundary = currentSelection.getBoundingClientRect();
boundaryMiddle = ( boundary.left + boundary.right ) / 2;
boundaryVerticalMiddle = ( boundary.top + boundary.bottom ) / 2;
spaceTop = boundary.top;
spaceBottom = iframeHeigth - boundary.bottom;
windowWidth = window.innerWidth;
toolbarWidth = toolbarNode.offsetWidth;
toolbarHalf = toolbarWidth / 2;
iframe = document.getElementById( editor.id + '_ifr' );
iframePos = DOM.getPos( iframe );
iframeWidth = iframe.offsetWidth;
iframeHeigth = iframe.offsetHeight;
toolbarNodeHeight = toolbarNode.offsetHeight;
verticalSpaceNeeded = toolbarNodeHeight + margin + buffer;
X = Math.max( p2.x - vp.x, 0 ) + p1.x;
Y = Math.max( p2.y - vp.y, 0 ) + p1.y;
if ( spaceTop >= verticalSpaceNeeded ) {
className = ' mce-arrow-down';
top = boundary.top + iframePos.y - toolbarNodeHeight - margin;
} else if ( spaceBottom >= verticalSpaceNeeded ) {
className = ' mce-arrow-up';
top = boundary.bottom + iframePos.y;
} else {
top = buffer;
DOM.setStyles( id, {
'top' : Y + 5 + 'px',
'left' : X + 5 + 'px',
'display': 'block'
});
}
if ( boundaryVerticalMiddle >= verticalSpaceNeeded ) {
className = ' mce-arrow-down';
} else {
className = ' mce-arrow-up';
}
}
function _hideButtons() {
DOM.hide( DOM.select( '#wp_editbtns, #wp_gallerybtns' ) );
}
// Make sure the image toolbar is below the main toolbar.
if ( mceToolbar ) {
minTop = DOM.getPos( mceToolbar ).y + mceToolbar.clientHeight;
} else {
minTop = iframePos.y;
}
// Make sure the image toolbar is below the adminbar (if visible) or below the top of the window.
if ( windowPos ) {
if ( adminbar && adminbar.getBoundingClientRect().top === 0 ) {
adminbarHeight = adminbar.clientHeight;
}
if ( windowPos + adminbarHeight > minTop ) {
minTop = windowPos + adminbarHeight;
}
}
if ( top && minTop && ( minTop + buffer > top ) ) {
top = minTop + buffer;
className = '';
}
left = boundaryMiddle - toolbarHalf;
left += iframePos.x;
if ( boundary.left < 0 || boundary.right > iframeWidth ) {
left = iframePos.x + ( iframeWidth - toolbarWidth ) / 2;
} else if ( toolbarWidth >= windowWidth ) {
className += ' mce-arrow-full';
left = 0;
} else if ( ( left < 0 && boundary.left + toolbarWidth > windowWidth ) ||
( left + toolbarWidth > windowWidth && boundary.right - toolbarWidth < 0 ) ) {
left = ( windowWidth - toolbarWidth ) / 2;
} else if ( left < iframePos.x ) {
className += ' mce-arrow-left';
left = boundary.left + iframePos.x;
} else if ( left + toolbarWidth > iframeWidth + iframePos.x ) {
className += ' mce-arrow-right';
left = boundary.right - toolbarWidth + iframePos.x;
}
toolbarNode.className = toolbarNode.className.replace( / ?mce-arrow-[\w]+/g, '' );
toolbarNode.className += className;
DOM.setStyles( toolbarNode, { 'left': left, 'top': top } );
return this;
}
toolbar.on( 'show', function() {
currentToolbar = this;
this.reposition();
} );
toolbar.on( 'hide', function() {
currentToolbar = false;
} );
toolbar.on( 'keydown', function( event ) {
if ( event.keyCode === 27 ) {
this.hide();
editor.focus();
}
} );
toolbar.on( 'remove', function() {
DOM.unbind( window, 'resize scroll', hide );
editor.dom.unbind( editor.getWin(), 'resize scroll', hide );
editor.off( 'blur hide', hide );
} );
editor.once( 'init', function() {
DOM.bind( window, 'resize scroll', hide );
editor.dom.bind( editor.getWin(), 'resize scroll', hide );
editor.on( 'blur hide', hide );
} );
toolbar.reposition = reposition;
toolbar.hide().renderTo( document.body );
return toolbar;
}
editor.shortcuts.add( 'alt+119', '', function() {
var node;
if ( currentToolbar ) {
node = currentToolbar.find( 'toolbar' )[0];
node && node.focus( true );
}
} );
editor.on( 'nodechange', function( event ) {
var collapsed = editor.selection.isCollapsed();
var args = {
element: event.element,
parents: event.parents,
collapsed: collapsed
};
editor.fire( 'wptoolbar', args );
currentSelection = args.selection || args.element;
currentToolbar && currentToolbar.hide();
args.toolbar && args.toolbar.show();
} );
editor.wp = editor.wp || {};
editor.wp._createToolbar = create;
}());
function noop() {}
// Expose some functions (back-compat)
return {
_showButtons: _showButtons,
_hideButtons: _hideButtons,
_setEmbed: _setEmbed,
_getEmbed: _getEmbed
_showButtons: noop,
_hideButtons: noop,
_setEmbed: noop,
_getEmbed: noop
};
});