Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
(function () {
var Dom = YAHOO.util.Dom;
var myConfig = {
height: '250px',
width: '628px',
animate: true,
dompath: false,
focusAtStart: false,
extracss: ' img {display:block;margin:0 auto;}html{width:100%;overflow:auto;}.yui-media {display:block; height: 100px; width: 100px; border: 1px solid black; background-color: #f2f2f2; cursor:pointer !important; background-image: url( ${resource(dir:'css', file:'media_placeholder.gif')} ); background-position: 50% 50%; background-repeat: no-repeat; }.yui-media *{display:none;height:0px; text-indent:-4999px; width:0px;overflow:hidden; /*height width and overflow for safari*/}',
toolbar: {
collapse: true,
titlebar: 'The(G)net-Editor',
draggable: false,
buttons: [{
group: 'textstyle',
label: 'Font Style',
buttons: [{
type: 'push',
label: 'Bold CTRL + SHIFT + B',
value: 'bold'
},
{
type: 'push',
label: 'Italic CTRL + SHIFT + I',
value: 'italic'
},
{
type: 'push',
label: 'Underline CTRL + SHIFT + U',
value: 'underline'
},
{
type: 'separator'
},
{
type: 'color',
label: 'Font Color',
value: 'forecolor',
disabled: true
},
{
type: 'color',
label: 'Background Color',
value: 'backcolor',
disabled: true
}]
},
{
type: 'separator'
},
{
group: 'alignment',
label: 'Alignment',
buttons: [{
type: 'push',
label: 'Align Left CTRL + SHIFT + [',
value: 'justifyleft'
},
{
type: 'push',
label: 'Align Center CTRL + SHIFT + |',
value: 'justifycenter'
},
{
type: 'push',
label: 'Align Right CTRL + SHIFT + ]',
value: 'justifyright'
},
{
type: 'push',
label: 'Justify',
value: 'justifyfull'
}]
},
{
type: 'separator'
},
{
group: 'parastyle',
label: 'Paragraph Style',
buttons: [{
type: 'select',
label: 'Normal',
value: 'heading',
disabled: true,
menu: [{
text: 'Normal',
value: 'none',
checked: true
},
{
text: 'Header 1',
value: 'h1'
},
{
text: 'Header 2',
value: 'h2'
},
{
text: 'Header 3',
value: 'h3'
},
{
text: 'Header 4',
value: 'h4'
},
{
text: 'Header 5',
value: 'h5'
},
{
text: 'Header 6',
value: 'h6'
}]
}]
},
{
type: 'separator'
},
{
group: 'indentlist',
label: 'Lists',
buttons: [{
type: 'push',
label: 'Create an Unordered List',
value: 'insertunorderedlist'
},
{
type: 'push',
label: 'Create an Ordered List',
value: 'insertorderedlist'
}]
},
{
type: 'separator'
},
{
group: 'insertitem',
label: 'Insert Item',
buttons: [{
type: 'push',
label: 'HTML Link CTRL + SHIFT + L',
value: 'createlink',
disabled: true
},
{
type: 'push',
label: 'Insert Image',
value: 'insertimage'
},
{
type: 'push',
label: 'Media Options',
value: 'insertmedia'
}]
}]
}
};
var myEditor = new YAHOO.widget.Editor('text', myConfig);
/* after the window is closed */
var _handleWindowClose = function () {
var el = this.currentElement[0];
//set the attribute on the element so we can parse it out afterward.
var textarea = document.getElementById('embedplugin');
var val = textarea.value;
if (-1 != val.indexOf("<embed")) {
el.setAttribute('embeddedcode', textarea.value);
} else {
el.parentNode.removeChild(el);
}
textarea.value = "";
this.nodeChange();
};
/* the very call */
var _handleMediaWindow = function () {
var el = this.currentElement[0];
var win = new YAHOO.widget.EditorWindow('insertmedia', {
width: '425px'
});
var bFlag = false;
win.setHeader('Edit Media');
this.openWindow(win);
this.on('afterOpenWindow', function () {
this.get('panel').syncIframe();
},
this, true);
if (null != el.getAttribute("embeddedcode")) {
var textarea = document.getElementById('embedplugin');
if (null != textarea) {
textarea.value = el.getAttribute("embeddedcode");
} else {
bFlag = true;
}
}
};
/* if a embeded is selected */
myEditor.on('toolbarLoaded', function () {
this.toolbar.on('insertmediaClick', function () {
var el = this._getSelectedElement();
if (Dom.hasClass(el, 'yui-media')) {
this.currentElement = [el];
handleInsertIcon.call(this);
return false;
}
},
this, true);
},
myEditor, true);
/* press on the toolbar button */
myEditor.cmd_insertmedia = function () {
/* prevent to overwrite a valid media placeholder !!! */
if (!Dom.hasClass(this._getSelectedElement(), 'yui-media')) {
/* dummy image */
this.execCommand('insertimage', 'none ');
/* replace that image with a span or div */
var el = this._swapEl(this.currentElement[0], 'span', function (el) {
el.className = 'yui-media';
Dom.setStyle(el, 'fontSize', '100px');
});
/* set the current element */
this.currentElement = [el];
}
/* handle */
_handleMediaWindow.call(this);
/* no further event handling */
return[false];
};
/* double click event */
myEditor.on('editorDoubleClick', function () {
var el = this._getSelectedElement();
if (Dom.hasClass(el, 'yui-media')) {
this.currentElement = [el];
_handleMediaWindow.call(this);
return false;
}
},
myEditor, true);
/* selects the button */
myEditor.on('afterNodeChange', function () {
if (this._hasSelection()) {
this.toolbar.disableButton('insertmedia');
} else {
this.toolbar.enableButton('insertmedia');
var el = this._getSelectedElement();
if (Dom.hasClass(el, 'yui-media')) {
this.toolbar.selectButton('insertmedia');
} else {
this.toolbar.deselectButton('insertmedia');
}
}
},
myEditor, true);
/* on close handler */
myEditor.on('windowinsertmediaClose', function () {
_handleWindowClose.call(this);
},
myEditor, true);
/* one timers */
myEditor.on('windowRender', function () {
var body = document.createElement('div');
// a nice styled - simple (and just for <object><param>..<embed/></object>) text entry window
body.innerHTML = '<p style="margin: 5px">Paste your embed string here:</p><textarea id="embedplugin" style="width: 95%; margin: 5px" rows="10"></textarea>';
myEditor._windows.insertmedia = {
body: body
};
});
myEditor.on('editorContentLoaded', function () {
var b = this._getDoc().body;
var val = b.innerHTML;
var regex = /(<object .+?>.+?<\/object>)/gi;
var valReplaceInitial = val.replace(/"/g, "'");
var valReplace = valReplaceInitial.replace(regex, '<span class="yui-media" embeddedcode="$1" style="font-size:100px"></span>');
this.setEditorHTML(valReplace);
},
myEditor, true);
myEditor.render();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.