Subversion Repositories Sites.tela-botanica.org

Compare Revisions

No changes between revisions

Ignore whitespace Rev 609 → Rev 610

/branches/v4.0/wikini/maj_wikini/tools/templates/themes/default/javascripts/tiny_mce/plugins/template/jscripts/template.js
New file
0,0 → 1,143
// Import external list url javascript
var url = tinyMCE.getParam("template_external_list_url");
if (url != null) {
// Fix relative
if (url.charAt(0) != '/' && url.indexOf('://') == -1)
url = tinyMCE.documentBasePath + "/" + url;
 
document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></sc'+'ript>');
}
 
var TPU = { //Template Popup Utils
currentTemplateHTML : null,
templates : [],
inst : tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id')),
plugin : tinyMCE.getWindowArg('pluginObj'),
data : tinyMCE.selectedInstance.getData('template'),
 
init : function() {
document.forms[0].insert.value = tinyMCE.getLang('lang_' + this.data.currentAction, 'Insert', true);
TPU.loadTemplatePaths();
 
if (this.data.currentAction == "update")
document.getElementById('warning').innerHTML = tinyMCE.getLang('lang_template_warning');
 
this.resizeInputs();
},
 
loadTemplatePaths : function() {
var tsrc, sel, x, u;
 
tsrc = tinyMCE.getParam("template_templates", false);
sel = document.getElementById('tpath');
 
// Setup external template list
if (!tsrc && typeof(tinyMCETemplateList) != 'undefined') {
for (x=0, tsrc = []; x<tinyMCETemplateList.length; x++)
tsrc.push({title : tinyMCETemplateList[x][0], src : tinyMCETemplateList[x][1], description : tinyMCETemplateList[x][2]});
}
 
for (x=0; x<tsrc.length; x++) {
u = tsrc[x].src;
 
// Force absolute
if (u.indexOf('://') == -1 && u.indexOf('/') != 0)
u = tinyMCE.documentBasePath + "/" + u;
 
tsrc[x].src = u;
}
 
TPU.templates = tsrc;
 
for (x = 0; x < tsrc.length; x++)
sel.options[sel.options.length] = new Option(tsrc[x].title, tsrc[x].src);
},
 
selectTemplate : function(o) {
var x, d = window.frames['templatesrc'].document;
 
this.currentTemplateHTML = this.plugin._replaceValues(this.getFileContents(o.value));
 
// Force complete document
/* if (!/<body/gi.test(this.currentTemplateHTML)) {
this.currentTemplateHTML = '<html xmlns="http://www.w3.org/1999/xhtml">' +
'<head>' +
'<title>blank_page</title>' +
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
'</head>' +
'<body>' +
this.currentTemplateHTML +
'</body>' +
'</html>';
}*/
 
// Write HTML to preview iframe
d.body.innerHTML = this.currentTemplateHTML;
 
// Display description
for (x = 0; x < TPU.templates.length; x++) {
if (TPU.templates[x].src == o.value) {
document.getElementById('tmpldesc').innerHTML = TPU.templates[x].description;
break;
}
}
},
 
insertTemplate : function() {
var sel, opt;
 
sel = document.getElementById('tpath');
opt = sel.options[sel.selectedIndex];
 
// Is it a template or snippet
if (TPU.currentTemplateHTML.indexOf('mceTmpl'))
tinyMCEPopup.execCommand('mceTemplate', false, {title : opt.text, tsrc : opt.value, body : TPU.currentTemplateHTML});
else
tinyMCEPopup.execCommand('mceInsertContent', false, TPU.currentTemplateHTML);
 
tinyMCEPopup.close();
},
 
getFileContents : function(u) {
var x, d, t = 'text/plain';
 
function g(s) {
x = 0;
 
try {
x = new ActiveXObject(s);
} catch (s) {
}
 
return x;
};
 
x = window.ActiveXObject ? g('Msxml2.XMLHTTP') || g('Microsoft.XMLHTTP') : new XMLHttpRequest();
 
// Synchronous AJAX load file
x.overrideMimeType && x.overrideMimeType(t);
x.open("GET", u, false);
x.send(null);
 
return x.responseText;
},
 
resizeInputs : function() {
var wHeight, wWidth, elm;
 
if (!self.innerWidth) {
wHeight = document.body.clientHeight - 160;
wWidth = document.body.clientWidth - 40;
} else {
wHeight = self.innerHeight - 160;
wWidth = self.innerWidth - 40;
}
 
elm = document.getElementById('templatesrc');
 
if (elm) {
elm.style.height = Math.abs(wHeight) + 'px';
elm.style.width = Math.abs(wWidth - 5) + 'px';
}
}
};
/branches/v4.0/wikini/maj_wikini/tools/templates/themes/default/javascripts/tiny_mce/plugins/template/template.htm
New file
0,0 → 1,37
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{$lang_template_title}</title>
<script language="javascript" type="text/javascript" src="../../tiny_mce_popup.js"></script>
<script language="javascript" type="text/javascript" src="jscripts/template.js"></script>
<link href="css/template.css" rel="stylesheet" type="text/css" />
<base target="_self" />
</head>
<body onload="tinyMCEPopup.executeOnLoad('TPU.init();');" onresize="TPU.resizeInputs();">
<form onsubmit="insert();return false;">
<div id="frmbody">
<div class="title">{$lang_template_desc}</div>
<div class="frmRow"><label for="tpath" title="{$lang_template_select}">{$lang_template_label}:</label>
<select id="tpath" name="tpath" onfocus="tinyMCE.addSelectAccessibility(event, this, window);" onchange="TPU.selectTemplate(this.options[this.selectedIndex]);">
<option value="">{$lang_template_select}...</option>
</select>
<span id="warning"></span></div>
<div class="frmRow"><label for="tdesc">{$lang_template_desc_label}:</label>
<span id="tmpldesc"></span></div>
<fieldset>
<legend>{$lang_template_preview}</legend>
<iframe id="templatesrc" name="templatesrc" src="blank.htm" width="690" height="400" frameborder="0"></iframe>
</fieldset>
</div>
<div class="mceActionPanel">
<div style="float: left">
<input type="button" id="insert" name="insert" value="{$lang_insert}" onclick="TPU.insertTemplate();" />
</div>
 
<div style="float: right">
<input type="button" id="cancel" name="cancel" value="{$lang_cancel}" onclick="tinyMCEPopup.close();" />
</div>
</div>
</form>
</body>
</html>
/branches/v4.0/wikini/maj_wikini/tools/templates/themes/default/javascripts/tiny_mce/plugins/template/langs/en.js
New file
0,0 → 1,16
// UK lang variables
 
tinyMCE.addToLang('template',{
title : 'Templates',
label : 'Template',
desc_label : 'Description',
desc : 'Insert predefined template content',
select : 'Select a template',
preview : 'Preview',
warning : 'Warning: Updating a template with a different one may cause data loss.',
def_date_format : '%Y-%m-%d %H:%M:%S',
months_long : new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"),
months_short : new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"),
day_long : new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"),
day_short : new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
});
/branches/v4.0/wikini/maj_wikini/tools/templates/themes/default/javascripts/tiny_mce/plugins/template/images/template.gif
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/branches/v4.0/wikini/maj_wikini/tools/templates/themes/default/javascripts/tiny_mce/plugins/template/images/template.gif
New file
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/v4.0/wikini/maj_wikini/tools/templates/themes/default/javascripts/tiny_mce/plugins/template/editor_plugin_src.js
New file
0,0 → 1,551
/**
* $Id: editor_plugin_src.js 162 2007-01-03 16:16:52Z spocke $
*
* @author Moxiecode
* @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
*/
 
tinyMCE.importPluginLanguagePack('template');
 
var TinyMCE_TemplatePlugin = {
getInfo : function() {
return {
longname : 'Template plugin',
author : 'Moxiecode Systems AB',
authorurl : 'http://www.moxiecode.com',
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/template',
version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
};
},
 
initInstance : function(inst) {
var cdate, mdate, content, x = 0, key, value, rvals, ds = inst.getData('template');
 
// ensure the required elements and sttributes are added
//inst.cleanup.addRuleStr('*[' + TinyMCE_TemplatePlugin.TMPL_DATE_SRC_ATTR + '],div[title,tsrc]');
 
//setup template content functions
// creation date and modified date classes
cdate = tinyMCE.getParam("template_cdate_classes", '').split(/\s+/);
mdate = tinyMCE.getParam("template_mdate_classes", '').split(/\s+/);
 
// classes that specify where selected content should go
content = tinyMCE.getParam("template_selected_content_classes", '').split(/\s+/);
 
for (x = 0; x < cdate.length; x++)
TinyMCE_TemplatePlugin.functions[cdate[x]] = TinyMCE_TemplatePlugin.functions['cdate'];
 
for (x = 0; x < mdate.length; x++)
TinyMCE_TemplatePlugin.functions[mdate[x]] = TinyMCE_TemplatePlugin.functions['mdate'];
 
for (x = 0; x < content.length; x++)
TinyMCE_TemplatePlugin.functions[content[x]] = TinyMCE_TemplatePlugin.functions['selectedContent'];
 
// special template functions for replacing template content
rvals = tinyMCE.getParam("template_replace_values", false);
for (key in rvals) {
value = rvals[key];
 
if (typeof value == "function")
TinyMCE_TemplatePlugin.functions[key] = value;
else
TinyMCE_TemplatePlugin.functions[key] = TinyMCE_TemplatePlugin.functions['generateReplacer'](value);
}
 
// Setup replace_items
rvals = tinyMCE.getParam("template_replace_values", false);
ds.replace_items = {};
 
for (key in rvals)
ds.replace_items[key] = rvals[key];
 
inst.addShortcut('ctrl', 't', 'lang_template_desc', 'mceTemplate');
 
// Setup data storage
ds.currentAction = "insert";
ds.currentTmplNode = null;
},
 
getControlHTML : function(cn) {
switch (cn) {
case "template":
return tinyMCE.getButtonHTML(cn, 'lang_template_desc', '{$pluginurl}/images/template.gif', 'mceTemplate', true);
}
 
return "";
},
 
execCommand : function(editor_id, element, command, user_interface, value) {
var nodeArray, current, newTmpl, x, inst = tinyMCE.getInstanceById(editor_id), ds = inst.getData('template'), telm;
 
switch (command) {
case "mceTemplate":
if (user_interface) {
// called from toolbar button - show the popup
tinyMCE.openWindow({
file : '../../plugins/template/template.htm', // Relative to theme
width : tinyMCE.getParam('template_popup_width', 750),
height : tinyMCE.getParam('template_popup_height', 600)
}, {editor_id : editor_id, resizable : "yes", scrollbars : "no", pluginObj : TinyMCE_TemplatePlugin});
} else {
// internal command do the template stuff
 
// get the returned HTML string from the pop-up and appened it to a DIV element
telm = TinyMCE_TemplatePlugin._convertToNode(value.body);
 
// Find template body
nodeArray = tinyMCE.selectElements(telm, 'div', function(n) {
return tinyMCE.hasCSSClass(n, TinyMCE_TemplatePlugin.TMPL);
});
 
telm = nodeArray.length > 0 ? nodeArray[0] : null;
nodeArray = [];
 
if (ds.currentAction == "insert") {
//insert new template after applying all the template content functions
 
// Is it a template or snippet
if (telm) {
tinyMCE.execCommand('mceBeginUndoLevel');
ds.currentAction = "insert-new";
TinyMCE_TemplatePlugin._insertTemplate(editor_id, telm, value.title, value.tsrc, true);
ds.currentAction == "insert";
tinyMCE.execCommand('mceEndUndoLevel');
tinyMCE.execInstanceCommand(editor_id, 'mceCleanup', false);
} else
tinyMCE.execCommand('mceInsertContent', false, this._replaceValues(value.body));
} else {
// First collect the selected template in the editor
nodeArray = TinyMCE_TemplatePlugin._collectTemplateElements(ds.currentTmplNode);
current = [];
newTmpl = [];
tinyMCE.getNodeTree(telm, newTmpl);
 
for (x=0; x<nodeArray.length; x++)
tinyMCE.getNodeTree(nodeArray[x], current);
 
/**
* inner function used in the loop below.
* compares the supplied HTML element to the new template to:
* - find a match with the new template and copy the element's content over
* - find no match and indicate content will be lost
*/
var _test = function(elm) {
var replaced = true;
 
if (elm.className) {
var names = elm.className.split(/\s+/), c, n;
 
for (c = 0; c<names.length; c++) {
if (names[c].match(/^mce/i))
continue; // ignore all internal class names
 
for (n=0; n<newTmpl.length; n++){
replaced = false;
 
if (newTmpl[n].className && newTmpl[n].className.match(new RegExp(names[c], "gi"))) {
newTmpl[n].innerHTML = elm.innerHTML;
//if(tinyMCE.getAttrib(elm,TinyMCE_TemplatePlugin.TMPL_DATE_SRC_ATTR,"") != "") {
// tinyMCE.setAttrib(newTmpl[n], TinyMCE_TemplatePlugin.TMPL_DATE_SRC_ATTR, tinyMCE.getAttrib(elm,TinyMCE_TemplatePlugin.TMPL_DATE_SRC_ATTR));
//}
replaced = true;
break;
}
 
}
}
}
return replaced;
};
 
// comparison loop - first mis-match alerts user for confirmation.
var cont = true;
var asked = false;
 
for (x = 0; x < current.length; x++) {
if(!_test(current[x])) {
cont = (asked || confirm("The new template has less elements than the currently selected content.\nIf you proceed you will loose content.\nAre you sure you want to proceed?", "Proceed?"));
asked = true;
 
if (!cont)
break;
}
};
 
// apply replacement if allowed to
if (cont) {
tinyMCE.execCommand('mceBeginUndoLevel');
TinyMCE_TemplatePlugin._replaceTemplateContent(current[0], editor_id, telm, value.title, value.tsrc);
tinyMCE.execCommand('mceEndUndoLevel');
tinyMCE.execInstanceCommand(editor_id, 'mceCleanup', false);
}
}
 
tinyMCE.triggerNodeChange(true);
}
 
return true;
}
 
return false;
},
 
handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
var inst = tinyMCE.getInstanceById(editor_id), ds = inst.getData('template');
 
if (tinyMCE.hasCSSClass(node, TinyMCE_TemplatePlugin.TMPL_ELEMENT) || tinyMCE.hasCSSClass(node.parentNode, TinyMCE_TemplatePlugin.TMPL_ELEMENT)) {
tinyMCE.switchClass(editor_id + '_template', 'mceButtonSelected');
ds.currentAction = "update";
ds.currentTmplNode = node;
 
return true;
}
 
ds.currentAction = "insert";
ds.currentTmplNode = null;
tinyMCE.switchClass(editor_id + '_template', 'mceButtonNormal');
 
return false;
},
 
cleanup : function(type, content, inst) {
var nodes = [];
 
switch (type) {
case "get_from_editor":
// replace the opening wrapper div tag with a HTML comment
content = content.replace(
new RegExp('<div class="' + TinyMCE_TemplatePlugin.TMPL + '">', 'gi'),
'<!-- ' + TinyMCE_TemplatePlugin.TMPL_BEGINS + ' -->'
);
 
// delete any empty template wrappers
content = content.replace(
new RegExp('<div class="' + TinyMCE_TemplatePlugin.TMPL + '">(\s|&nbsp;|&#160;)?(<!-- ' + TinyMCE_TemplatePlugin.TMPL_ENDS + ' -->|\s)?</div>', 'gi'),
''
);
 
// replace the closing wrapper tag
content = content.replace(
new RegExp('<!-- ' + TinyMCE_TemplatePlugin.TMPL_ENDS + ' --></div>', 'gi'),
'<!-- ' + TinyMCE_TemplatePlugin.TMPL_ENDS + ' -->'
);
 
break;
 
case "insert_to_editor":
// replace HTML comment with DIV wrapper
content = content.replace(
new RegExp('<!-- ' + TinyMCE_TemplatePlugin.TMPL_BEGINS + ' -->', 'gi'),
'<div class="' + TinyMCE_TemplatePlugin.TMPL + '">'
);
 
content = content.replace(
new RegExp('<!-- ' + TinyMCE_TemplatePlugin.TMPL_ENDS + ' -->', 'gi'),
'<!-- ' + TinyMCE_TemplatePlugin.TMPL_ENDS + ' --></div>'
);
 
break;
 
case "get_from_editor_dom":
// apply template content replacement functions
nodes = tinyMCE.selectNodes(content, function(n) {
return tinyMCE.hasCSSClass(n, TinyMCE_TemplatePlugin.TMPL_ELEMENT);
}
);
 
TinyMCE_TemplatePlugin._applyFunctions(nodes, type);
 
break;
 
case "insert_to_editor_dom":
// apply template content replacement functions
nodes = tinyMCE.selectNodes(content, function(n) {
return tinyMCE.hasCSSClass(n, TinyMCE_TemplatePlugin.TMPL_ELEMENT);
}
);
 
TinyMCE_TemplatePlugin._applyFunctions(nodes, type);
 
break;
}
 
return content;
},
 
// Private plugin internal methods
 
/**
* Creates a HTML DIV element and sets the innerHTML to equal the temlate innerHTML so that the template can be manipulated as DOM nodes.
*
* @param {string} Template innerHTML
* @return a HTML Element
* @type HTMLElement
*/
_convertToNode : function(html) {
var elm = document.createElement('div');
 
elm.innerHTML = html;
 
return elm;
},
 
/**
* pass an array of template html elements and they will have the template class name added and any template functions applied
*
* @param {array} template HTML elements
* @return array of template HTML elements
* @type array
*/
_prepareTemplateContent : function(elms) {
var x, n, nodes = [];
 
if (!elms)
return {};
 
if (!elms.length)
elms = [elms];
 
for (x = 0; x<elms.length; x++)
tinyMCE.getNodeTree(elms[x], nodes, 1);
 
for (n = 0; n<nodes.length; n++) {
tinyMCE.addCSSClass(nodes[n], TinyMCE_TemplatePlugin.TMPL_ELEMENT);
TinyMCE_TemplatePlugin._applyFunctions(nodes[n], TinyMCE_TemplatePlugin.TMPL_TEMPLATE_EVENT);
}
 
return elms;
},
 
_replaceValues : function(s) {
var t = this, ds = tinyMCE.selectedInstance.getData('template');
 
return s.replace(/\{\$([^\}]+)\}/g, function(a, b) {
var it = ds.replace_items[b];
 
if (it) {
// Only supports text for now
if (typeof(it) != 'function')
return it;
}
 
return b;
});
},
 
/**
* Applies any special functions to the template elements
*
* @param {array} template HTML elements
* @return array of template HTML elements
* @type array
*/
_applyFunctions : function(elms, editor_event) {
var x, elm, names, c, f;
 
if (!elms)
return {};
 
if (!elms.length)
elms = [elms];
 
for(x = 0; x < elms.length; x++) {
elm = elms[x];
 
if (elm.className){
names = elm.className.split(/\s+/);
 
for (c = 0; c < names.length; c++){
if (names[c] == TinyMCE_TemplatePlugin.TMPL_ELEMENT)
continue;
 
f = (TinyMCE_TemplatePlugin.functions[names[c]] ? TinyMCE_TemplatePlugin.functions[names[c]] : TinyMCE_TemplatePlugin.functions['blank']);
f(elm, editor_event);
}
}
}
 
return elms;
},
 
/**
* Given one node reference this function will collect all the nodes of the template to which it belongs.
* It does this by finding the parent template wrapper DIV and returning all child nodes.
*
* @param {HTMLElement} a HTMLElement which is part of a template
* @return array of template HTML elements
* @type array
*/
_collectTemplateElements : function(node) {
var nodeArray = [], p;
 
p = tinyMCE.getParentElement(node, 'DIV', function(n) {
return tinyMCE.hasCSSClass(n, TinyMCE_TemplatePlugin.TMPL);
});
 
if (p)
tinyMCE.getNodeTree(p, nodeArray);
 
return nodeArray;
},
 
/**
* Simply calls TinyMCE_TemplatePlugin._deleteTemplateContent and then TinyMCE_TemplatePlugin._insertTemplate
*
* @param {HTMLElement} currently selected template node in editor
* @param {string} id of editor instance
* @param {HTMLElement} template contents as a HTMLElement (the parent DIV wrapper)
* @param {string} title of template (unused as yet)
* @param {string} source URI of the template file (unused as yet)
* @return array of template HTML elements
* @type array
*/
_replaceTemplateContent : function(currentNode, editor_id, newTemplate, title, tsrc) {
TinyMCE_TemplatePlugin._deleteTemplateContent(currentNode);
TinyMCE_TemplatePlugin._insertTemplate(editor_id, newTemplate, title, tsrc, false);
},
 
/**
* Deletes a template from the editor content
* Finds the parent DIV wrapper and deletes it and all children
* @param {HTMLElement} currently selected template node in editor
*/
_deleteTemplateContent : function(node) {
var p = tinyMCE.getParentElement(node, 'DIV', function(n) {
return tinyMCE.hasCSSClass(n, TinyMCE_TemplatePlugin.TMPL);
});
 
if (p)
p.parentNode.removeChild(p, true);
},
 
/**
* Inserts a template into the specified editor
*
* @param {string} id of editor instance
* @param {HTMLElement} template contents as a HTMLElement (the parent DIV wrapper)
* @param {string} title of template (unused as yet)
* @param {string} source URI of the template file (unused as yet)
*/
_insertTemplate : function(editor_id, elm, title, tsrc, incComments) {
var html;
 
TinyMCE_TemplatePlugin._prepareTemplateContent(elm);
 
html = '<div class="' + TinyMCE_TemplatePlugin.TMPL + '">';
html += elm.innerHTML;
html += '<!-- ' + TinyMCE_TemplatePlugin.TMPL_ENDS + ' --></div>';
 
tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html);
},
 
/**
* template functions - functions for modifying template content
*/
functions : {
blank : function(elm, editor_event) {},
 
cdate : function(elm, editor_event) {
var d, dsrc;
 
if (editor_event != TinyMCE_TemplatePlugin.TMPL_TEMPLATE_EVENT)
return;
 
d = new Date();
// find out if the creation date was previously stored
dsrc = elm.innerHTML.match(new RegExp("<!-- " + TinyMCE_TemplatePlugin.TMPL_DATE_SRC_ATTR + ":(.*) -->", "gi"));
 
if (dsrc)
d = new Date(RegExp.$1);
 
elm.innerHTML = TinyMCE_TemplatePlugin._getDateTime(d, tinyMCE.getParam("template_cdate_format", tinyMCE.getLang("lang_template_def_date_format")));
//now we have to store the date value in a format easily read again, in case a future template change changes the date format...
elm.innerHTML += "<!-- " + TinyMCE_TemplatePlugin.TMPL_DATE_SRC_ATTR + ":" + d.toUTCString() + " -->";
},
 
mdate : function(elm, editor_event) {
var d = new Date();
elm.innerHTML = TinyMCE_TemplatePlugin._getDateTime(d, tinyMCE.getParam("template_mdate_format", tinyMCE.getLang("lang_template_def_date_format")));
},
 
/**
* This will insert the currently selected editor content into the template element.
* It only does this if the template inserted is a new one and if the element does not have the special class.
* The special class name prevents this from happening more than once.
*/
selectedContent : function(elm, editor_event) {
var ds = tinyMCE.selectedInstance.getData('template');
if (editor_event != TinyMCE_TemplatePlugin.TMPL_TEMPLATE_EVENT)
return;
 
if (ds.currentAction == "insert-new" && !tinyMCE.hasCSSClass(elm, TinyMCE_TemplatePlugin.TMPL_SEL_HTML_DONE)) {
elm.innerHTML = tinyMCE.selectedInstance.selection.getSelectedHTML();
tinyMCE.addCSSClass(elm, TinyMCE_TemplatePlugin.TMPL_SEL_HTML_DONE);
}
},
 
/**
* When the plugin is initialised this generates the functions that insert configured strings into template elements.
*/
generateReplacer : function(s) {
return function(elm, editor_event) {elm.innerHTML = "" + s;};
}
},
 
/**
* formats a date according to the format string - straight from the 'insert date/time' plugin
*
* @param {Date} date object
* @param {string} format string
* @return formatted date
* @type string
*/
_getDateTime : function(d,fmt) {
if (!fmt)
return "";
 
function addZeros(value, len) {
var i;
 
value = "" + value;
 
if (value.length < len) {
for (i=0; i<(len-value.length); i++)
value = "0" + value;
}
 
return value;
}
 
fmt = fmt.replace("%D", "%m/%d/%y");
fmt = fmt.replace("%r", "%I:%M:%S %p");
fmt = fmt.replace("%Y", "" + d.getFullYear());
fmt = fmt.replace("%y", "" + d.getYear());
fmt = fmt.replace("%m", addZeros(d.getMonth()+1, 2));
fmt = fmt.replace("%d", addZeros(d.getDate(), 2));
fmt = fmt.replace("%H", "" + addZeros(d.getHours(), 2));
fmt = fmt.replace("%M", "" + addZeros(d.getMinutes(), 2));
fmt = fmt.replace("%S", "" + addZeros(d.getSeconds(), 2));
fmt = fmt.replace("%I", "" + ((d.getHours() + 11) % 12 + 1));
fmt = fmt.replace("%p", "" + (d.getHours() < 12 ? "AM" : "PM"));
fmt = fmt.replace("%B", "" + tinyMCE.getLang("lang_template_months_long")[d.getMonth()]);
fmt = fmt.replace("%b", "" + tinyMCE.getLang("lang_template_months_short")[d.getMonth()]);
fmt = fmt.replace("%A", "" + tinyMCE.getLang("lang_template_day_long")[d.getDay()]);
fmt = fmt.replace("%a", "" + tinyMCE.getLang("lang_template_day_short")[d.getDay()]);
fmt = fmt.replace("%%", "%");
 
return fmt;
},
 
TMPL_ELEMENT : 'mceTmplElm',
TMPL : 'mceTmpl',
TMPL_BEGINS : 'mceTmplBegins',
TMPL_SEL_HTML_DONE : 'mceSelHTMLDone',
TMPL_ENDS : 'mceTmplEnds',
TMPL_DATE_SRC_ATTR : 'mcetmpldtesrc',
TMPL_TEMPLATE_EVENT : 'prepare_template'
};
 
tinyMCE.addPlugin("template", TinyMCE_TemplatePlugin);
/branches/v4.0/wikini/maj_wikini/tools/templates/themes/default/javascripts/tiny_mce/plugins/template/css/template.css
New file
0,0 → 1,23
#frmbody {
padding: 10px;
background-color: #FFF;
border: 1px solid #CCC;
}
 
.frmRow {
margin-bottom: 10px;
}
 
#templatesrc {
border: none;
width: 320px;
height: 240px;
}
 
.title {
padding-bottom: 5px;
}
 
.mceActionPanel {
padding-top: 5px;
}
/branches/v4.0/wikini/maj_wikini/tools/templates/themes/default/javascripts/tiny_mce/plugins/template/blank.htm
New file
0,0 → 1,23
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>blank_page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
var tinyMCE = parent.tinyMCE, css = tinyMCE.getParam("content_css").split(','), i, u;
 
// Load content CSS files
for (i=0; i<css.length; i++) {
u = css[i];
 
// Fix relative
if (u.charAt(0) != '/' && u.indexOf('://') == -1)
u = tinyMCE.documentBasePath + "/" + u;
 
document.write('<link href="' + u + '" rel="stylesheet" type="text/css" />');
}
</script>
</head>
<body id="mceTemplatePreview" class="mceContentBody">
 
</body>
</html>
/branches/v4.0/wikini/maj_wikini/tools/templates/themes/default/javascripts/tiny_mce/plugins/template/editor_plugin.js
New file
0,0 → 1,0
tinyMCE.importPluginLanguagePack('template');var TinyMCE_TemplatePlugin={getInfo:function(){return{longname:'Template plugin',author:'Moxiecode Systems AB',authorurl:'http://www.moxiecode.com',infourl:'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/template',version:tinyMCE.majorVersion+"."+tinyMCE.minorVersion}},initInstance:function(inst){var cdate,mdate,content,x=0,key,value,rvals,ds=inst.getData('template');cdate=tinyMCE.getParam("template_cdate_classes",'').split(/\s+/);mdate=tinyMCE.getParam("template_mdate_classes",'').split(/\s+/);content=tinyMCE.getParam("template_selected_content_classes",'').split(/\s+/);for(x=0;x<cdate.length;x++)TinyMCE_TemplatePlugin.functions[cdate[x]]=TinyMCE_TemplatePlugin.functions['cdate'];for(x=0;x<mdate.length;x++)TinyMCE_TemplatePlugin.functions[mdate[x]]=TinyMCE_TemplatePlugin.functions['mdate'];for(x=0;x<content.length;x++)TinyMCE_TemplatePlugin.functions[content[x]]=TinyMCE_TemplatePlugin.functions['selectedContent'];rvals=tinyMCE.getParam("template_replace_values",false);for(key in rvals){value=rvals[key];if(typeof value=="function")TinyMCE_TemplatePlugin.functions[key]=value;else TinyMCE_TemplatePlugin.functions[key]=TinyMCE_TemplatePlugin.functions['generateReplacer'](value)}rvals=tinyMCE.getParam("template_replace_values",false);ds.replace_items={};for(key in rvals)ds.replace_items[key]=rvals[key];inst.addShortcut('ctrl','t','lang_template_desc','mceTemplate');ds.currentAction="insert";ds.currentTmplNode=null},getControlHTML:function(cn){switch(cn){case"template":return tinyMCE.getButtonHTML(cn,'lang_template_desc','{$pluginurl}/images/template.gif','mceTemplate',true)}return""},execCommand:function(editor_id,element,command,user_interface,value){var nodeArray,current,newTmpl,x,inst=tinyMCE.getInstanceById(editor_id),ds=inst.getData('template'),telm;switch(command){case"mceTemplate":if(user_interface){tinyMCE.openWindow({file:'../../plugins/template/template.htm',width:tinyMCE.getParam('template_popup_width',750),height:tinyMCE.getParam('template_popup_height',600)},{editor_id:editor_id,resizable:"yes",scrollbars:"no",pluginObj:TinyMCE_TemplatePlugin})}else{telm=TinyMCE_TemplatePlugin._convertToNode(value.body);nodeArray=tinyMCE.selectElements(telm,'div',function(n){return tinyMCE.hasCSSClass(n,TinyMCE_TemplatePlugin.TMPL)});telm=nodeArray.length>0?nodeArray[0]:null;nodeArray=[];if(ds.currentAction=="insert"){if(telm){tinyMCE.execCommand('mceBeginUndoLevel');ds.currentAction="insert-new";TinyMCE_TemplatePlugin._insertTemplate(editor_id,telm,value.title,value.tsrc,true);ds.currentAction=="insert";tinyMCE.execCommand('mceEndUndoLevel');tinyMCE.execInstanceCommand(editor_id,'mceCleanup',false)}else tinyMCE.execCommand('mceInsertContent',false,this._replaceValues(value.body))}else{nodeArray=TinyMCE_TemplatePlugin._collectTemplateElements(ds.currentTmplNode);current=[];newTmpl=[];tinyMCE.getNodeTree(telm,newTmpl);for(x=0;x<nodeArray.length;x++)tinyMCE.getNodeTree(nodeArray[x],current);var _test=function(elm){var replaced=true;if(elm.className){var names=elm.className.split(/\s+/),c,n;for(c=0;c<names.length;c++){if(names[c].match(/^mce/i))continue;for(n=0;n<newTmpl.length;n++){replaced=false;if(newTmpl[n].className&&newTmpl[n].className.match(new RegExp(names[c],"gi"))){newTmpl[n].innerHTML=elm.innerHTML;replaced=true;break}}}}return replaced};var cont=true;var asked=false;for(x=0;x<current.length;x++){if(!_test(current[x])){cont=(asked||confirm("The new template has less elements than the currently selected content.\nIf you proceed you will loose content.\nAre you sure you want to proceed?","Proceed?"));asked=true;if(!cont)break}};if(cont){tinyMCE.execCommand('mceBeginUndoLevel');TinyMCE_TemplatePlugin._replaceTemplateContent(current[0],editor_id,telm,value.title,value.tsrc);tinyMCE.execCommand('mceEndUndoLevel');tinyMCE.execInstanceCommand(editor_id,'mceCleanup',false)}}tinyMCE.triggerNodeChange(true)}return true}return false},handleNodeChange:function(editor_id,node,undo_index,undo_levels,visual_aid,any_selection){var inst=tinyMCE.getInstanceById(editor_id),ds=inst.getData('template');if(tinyMCE.hasCSSClass(node,TinyMCE_TemplatePlugin.TMPL_ELEMENT)||tinyMCE.hasCSSClass(node.parentNode,TinyMCE_TemplatePlugin.TMPL_ELEMENT)){tinyMCE.switchClass(editor_id+'_template','mceButtonSelected');ds.currentAction="update";ds.currentTmplNode=node;return true}ds.currentAction="insert";ds.currentTmplNode=null;tinyMCE.switchClass(editor_id+'_template','mceButtonNormal');return false},cleanup:function(type,content,inst){var nodes=[];switch(type){case"get_from_editor":content=content.replace(new RegExp('<div class="'+TinyMCE_TemplatePlugin.TMPL+'">','gi'),'<!-- '+TinyMCE_TemplatePlugin.TMPL_BEGINS+' -->');content=content.replace(new RegExp('<div class="'+TinyMCE_TemplatePlugin.TMPL+'">(\s|&nbsp;|&#160;)?(<!-- '+TinyMCE_TemplatePlugin.TMPL_ENDS+' -->|\s)?</div>','gi'),'');content=content.replace(new RegExp('<!-- '+TinyMCE_TemplatePlugin.TMPL_ENDS+' --></div>','gi'),'<!-- '+TinyMCE_TemplatePlugin.TMPL_ENDS+' -->');break;case"insert_to_editor":content=content.replace(new RegExp('<!-- '+TinyMCE_TemplatePlugin.TMPL_BEGINS+' -->','gi'),'<div class="'+TinyMCE_TemplatePlugin.TMPL+'">');content=content.replace(new RegExp('<!-- '+TinyMCE_TemplatePlugin.TMPL_ENDS+' -->','gi'),'<!-- '+TinyMCE_TemplatePlugin.TMPL_ENDS+' --></div>');break;case"get_from_editor_dom":nodes=tinyMCE.selectNodes(content,function(n){return tinyMCE.hasCSSClass(n,TinyMCE_TemplatePlugin.TMPL_ELEMENT)});TinyMCE_TemplatePlugin._applyFunctions(nodes,type);break;case"insert_to_editor_dom":nodes=tinyMCE.selectNodes(content,function(n){return tinyMCE.hasCSSClass(n,TinyMCE_TemplatePlugin.TMPL_ELEMENT)});TinyMCE_TemplatePlugin._applyFunctions(nodes,type);break}return content},_convertToNode:function(html){var elm=document.createElement('div');elm.innerHTML=html;return elm},_prepareTemplateContent:function(elms){var x,n,nodes=[];if(!elms)return{};if(!elms.length)elms=[elms];for(x=0;x<elms.length;x++)tinyMCE.getNodeTree(elms[x],nodes,1);for(n=0;n<nodes.length;n++){tinyMCE.addCSSClass(nodes[n],TinyMCE_TemplatePlugin.TMPL_ELEMENT);TinyMCE_TemplatePlugin._applyFunctions(nodes[n],TinyMCE_TemplatePlugin.TMPL_TEMPLATE_EVENT)}return elms},_replaceValues:function(s){var t=this,ds=tinyMCE.selectedInstance.getData('template');return s.replace(/\{\$([^\}]+)\}/g,function(a,b){var it=ds.replace_items[b];if(it){if(typeof(it)!='function')return it}return b})},_applyFunctions:function(elms,editor_event){var x,elm,names,c,f;if(!elms)return{};if(!elms.length)elms=[elms];for(x=0;x<elms.length;x++){elm=elms[x];if(elm.className){names=elm.className.split(/\s+/);for(c=0;c<names.length;c++){if(names[c]==TinyMCE_TemplatePlugin.TMPL_ELEMENT)continue;f=(TinyMCE_TemplatePlugin.functions[names[c]]?TinyMCE_TemplatePlugin.functions[names[c]]:TinyMCE_TemplatePlugin.functions['blank']);f(elm,editor_event)}}}return elms},_collectTemplateElements:function(node){var nodeArray=[],p;p=tinyMCE.getParentElement(node,'DIV',function(n){return tinyMCE.hasCSSClass(n,TinyMCE_TemplatePlugin.TMPL)});if(p)tinyMCE.getNodeTree(p,nodeArray);return nodeArray},_replaceTemplateContent:function(currentNode,editor_id,newTemplate,title,tsrc){TinyMCE_TemplatePlugin._deleteTemplateContent(currentNode);TinyMCE_TemplatePlugin._insertTemplate(editor_id,newTemplate,title,tsrc,false)},_deleteTemplateContent:function(node){var p=tinyMCE.getParentElement(node,'DIV',function(n){return tinyMCE.hasCSSClass(n,TinyMCE_TemplatePlugin.TMPL)});if(p)p.parentNode.removeChild(p,true)},_insertTemplate:function(editor_id,elm,title,tsrc,incComments){var html;TinyMCE_TemplatePlugin._prepareTemplateContent(elm);html='<div class="'+TinyMCE_TemplatePlugin.TMPL+'">';html+=elm.innerHTML;html+='<!-- '+TinyMCE_TemplatePlugin.TMPL_ENDS+' --></div>';tinyMCE.execInstanceCommand(editor_id,'mceInsertContent',false,html)},functions:{blank:function(elm,editor_event){},cdate:function(elm,editor_event){var d,dsrc;if(editor_event!=TinyMCE_TemplatePlugin.TMPL_TEMPLATE_EVENT)return;d=new Date();dsrc=elm.innerHTML.match(new RegExp("<!-- "+TinyMCE_TemplatePlugin.TMPL_DATE_SRC_ATTR+":(.*) -->","gi"));if(dsrc)d=new Date(RegExp.$1);elm.innerHTML=TinyMCE_TemplatePlugin._getDateTime(d,tinyMCE.getParam("template_cdate_format",tinyMCE.getLang("lang_template_def_date_format")));elm.innerHTML+="<!-- "+TinyMCE_TemplatePlugin.TMPL_DATE_SRC_ATTR+":"+d.toUTCString()+" -->"},mdate:function(elm,editor_event){var d=new Date();elm.innerHTML=TinyMCE_TemplatePlugin._getDateTime(d,tinyMCE.getParam("template_mdate_format",tinyMCE.getLang("lang_template_def_date_format")))},selectedContent:function(elm,editor_event){var ds=tinyMCE.selectedInstance.getData('template');if(editor_event!=TinyMCE_TemplatePlugin.TMPL_TEMPLATE_EVENT)return;if(ds.currentAction=="insert-new"&&!tinyMCE.hasCSSClass(elm,TinyMCE_TemplatePlugin.TMPL_SEL_HTML_DONE)){elm.innerHTML=tinyMCE.selectedInstance.selection.getSelectedHTML();tinyMCE.addCSSClass(elm,TinyMCE_TemplatePlugin.TMPL_SEL_HTML_DONE)}},generateReplacer:function(s){return function(elm,editor_event){elm.innerHTML=""+s}}},_getDateTime:function(d,fmt){if(!fmt)return"";function addZeros(value,len){var i;value=""+value;if(value.length<len){for(i=0;i<(len-value.length);i++)value="0"+value}return value}fmt=fmt.replace("%D","%m/%d/%y");fmt=fmt.replace("%r","%I:%M:%S %p");fmt=fmt.replace("%Y",""+d.getFullYear());fmt=fmt.replace("%y",""+d.getYear());fmt=fmt.replace("%m",addZeros(d.getMonth()+1,2));fmt=fmt.replace("%d",addZeros(d.getDate(),2));fmt=fmt.replace("%H",""+addZeros(d.getHours(),2));fmt=fmt.replace("%M",""+addZeros(d.getMinutes(),2));fmt=fmt.replace("%S",""+addZeros(d.getSeconds(),2));fmt=fmt.replace("%I",""+((d.getHours()+11)%12+1));fmt=fmt.replace("%p",""+(d.getHours()<12?"AM":"PM"));fmt=fmt.replace("%B",""+tinyMCE.getLang("lang_template_months_long")[d.getMonth()]);fmt=fmt.replace("%b",""+tinyMCE.getLang("lang_template_months_short")[d.getMonth()]);fmt=fmt.replace("%A",""+tinyMCE.getLang("lang_template_day_long")[d.getDay()]);fmt=fmt.replace("%a",""+tinyMCE.getLang("lang_template_day_short")[d.getDay()]);fmt=fmt.replace("%%","%");return fmt},TMPL_ELEMENT:'mceTmplElm',TMPL:'mceTmpl',TMPL_BEGINS:'mceTmplBegins',TMPL_SEL_HTML_DONE:'mceSelHTMLDone',TMPL_ENDS:'mceTmplEnds',TMPL_DATE_SRC_ATTR:'mcetmpldtesrc',TMPL_TEMPLATE_EVENT:'prepare_template'};tinyMCE.addPlugin("template",TinyMCE_TemplatePlugin);