Upgrade to Xinha 0.931. Xinha has been optimized for size and dozens of issues have been closed
out since the last upgrade . Add Firefox and Xinha buttons to main page to show our support.
This commit is contained in:
5
xinha/plugins/Stylist/lang/ja.js
Normal file
5
xinha/plugins/Stylist/lang/ja.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// I18N constants
|
||||
// LANG: "ja", ENCODING: UTF-8
|
||||
{
|
||||
"Styles": "スタイル"
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
// I18N constants
|
||||
// LANG: "no", ENCODING: UTF-8
|
||||
// LANG: "nb", ENCODING: UTF-8
|
||||
// translated: Kim Steinhaug, http://www.steinhaug.com/, kim@steinhaug.com
|
||||
{
|
||||
"Styles": "Stiler"
|
||||
@@ -1,542 +1,372 @@
|
||||
/**
|
||||
* Add an empty css_style to Config object's prototype
|
||||
* the format is { '.className' : 'Description' }
|
||||
*/
|
||||
|
||||
HTMLArea.Config.prototype.css_style = { };
|
||||
|
||||
/**
|
||||
* This method loads an external stylesheet and uses it in the stylist
|
||||
*/
|
||||
HTMLArea.Config.prototype.stylistLoadStylesheet = function(url, altnames)
|
||||
{
|
||||
if(!altnames) altnames = { };
|
||||
var newStyles = HTMLArea.ripStylesFromCSSFile(url);
|
||||
for(var i in newStyles)
|
||||
{
|
||||
if(altnames[i])
|
||||
{
|
||||
this.css_style[i] = altnames[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
this.css_style[i] = newStyles[i];
|
||||
}
|
||||
}
|
||||
this.pageStyleSheets[this.pageStyleSheets.length] = url;
|
||||
};
|
||||
|
||||
/**
|
||||
* This method takes raw style definitions and uses them in the stylist
|
||||
*/
|
||||
HTMLArea.Config.prototype.stylistLoadStyles = function(styles, altnames)
|
||||
{
|
||||
if(!altnames) altnames = { };
|
||||
var newStyles = HTMLArea.ripStylesFromCSSString(styles);
|
||||
for(var i in newStyles)
|
||||
{
|
||||
if(altnames[i])
|
||||
{
|
||||
this.css_style[i] = altnames[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
this.css_style[i] = newStyles[i];
|
||||
}
|
||||
}
|
||||
this.pageStyle += styles;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fill the stylist panel with styles that may be applied to the current selection. Styles
|
||||
* are supplied in the css_style property of the HTMLArea.Config object, which is in the format
|
||||
* { '.className' : 'Description' }
|
||||
* classes that are defined on a specific tag (eg 'a.email_link') are only shown in the panel
|
||||
* when an element of that type is selected.
|
||||
* classes that are defined with selectors/psuedoclasses (eg 'a.email_link:hover') are never
|
||||
* shown (if you have an 'a.email_link' without the pseudoclass it will be shown of course)
|
||||
* multiple classes (eg 'a.email_link.staff_member') are shown as a single class, and applied
|
||||
* to the element as multiple classes (class="email_link staff_member")
|
||||
* you may click a class name in the stylist panel to add it, and click again to remove it
|
||||
* you may add multiple classes to any element
|
||||
* spans will be added where no single _and_entire_ element is selected
|
||||
*/
|
||||
HTMLArea.prototype._fillStylist = function()
|
||||
{
|
||||
if(!this._stylist) return false;
|
||||
this._stylist.innerHTML = '<h1>'+HTMLArea._lc('Styles', 'Stylist')+'</h1>';
|
||||
|
||||
var may_apply = true;
|
||||
var sel = this._getSelection();
|
||||
|
||||
// What is applied
|
||||
// var applied = this._getAncestorsClassNames(this._getSelection());
|
||||
|
||||
// Get an active element
|
||||
var active_elem = this._activeElement(sel);
|
||||
|
||||
for(var x in this.config.css_style)
|
||||
{
|
||||
var tag = null;
|
||||
var className = x.trim();
|
||||
var applicable = true;
|
||||
var apply_to = active_elem;
|
||||
|
||||
if(applicable && /[^a-zA-Z0-9_.-]/.test(className))
|
||||
{
|
||||
applicable = false; // Only basic classes are accepted, no selectors, etc.. presumed
|
||||
// that if you have a.foo:visited you'll also have a.foo
|
||||
// alert('complex');
|
||||
}
|
||||
|
||||
if(className.indexOf('.') < 0)
|
||||
{
|
||||
// No class name, just redefines a tag
|
||||
applicable = false;
|
||||
}
|
||||
|
||||
if(applicable && (className.indexOf('.') > 0))
|
||||
{
|
||||
// requires specific html tag
|
||||
tag = className.substring(0, className.indexOf('.')).toLowerCase();
|
||||
className = className.substring(className.indexOf('.'), className.length);
|
||||
|
||||
// To apply we must have an ancestor tag that is the right type
|
||||
if(active_elem != null && active_elem.tagName.toLowerCase() == tag)
|
||||
{
|
||||
applicable = true;
|
||||
apply_to = active_elem;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this._getFirstAncestor(this._getSelection(), [tag]) != null)
|
||||
{
|
||||
applicable = true;
|
||||
apply_to = this._getFirstAncestor(this._getSelection(), [tag]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// alert (this._getFirstAncestor(this._getSelection(), tag));
|
||||
// If we don't have an ancestor, but it's a div/span/p/hx stle, we can make one
|
||||
if(( tag == 'div' || tag == 'span' || tag == 'p'
|
||||
|| (tag.substr(0,1) == 'h' && tag.length == 2 && tag != 'hr')))
|
||||
{
|
||||
if(!this._selectionEmpty(this._getSelection()))
|
||||
{
|
||||
applicable = true;
|
||||
apply_to = 'new';
|
||||
}
|
||||
else
|
||||
{
|
||||
// See if we can get a paragraph or header that can be converted
|
||||
apply_to = this._getFirstAncestor(sel, ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7']);
|
||||
if(apply_to != null)
|
||||
{
|
||||
applicable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
applicable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(applicable)
|
||||
{
|
||||
// Remove the first .
|
||||
className = className.substring(className.indexOf('.'), className.length);
|
||||
|
||||
// Replace any futher ones with spaces (for multiple class definitions)
|
||||
className = className.replace('.', ' ');
|
||||
|
||||
if(apply_to == null)
|
||||
{
|
||||
if(this._selectionEmpty(this._getSelection()))
|
||||
{
|
||||
// Get the previous element and apply to that
|
||||
apply_to = this._getFirstAncestor(this._getSelection(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
apply_to = 'new';
|
||||
tag = 'span';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var applied = (this._ancestorsWithClasses(sel, tag, className).length > 0 ? true : false);
|
||||
var applied_to = this._ancestorsWithClasses(sel, tag, className);
|
||||
|
||||
if(applicable)
|
||||
{
|
||||
var anch = document.createElement('a');
|
||||
anch._stylist_className = className.trim();
|
||||
anch._stylist_applied = applied;
|
||||
anch._stylist_appliedTo = applied_to;
|
||||
anch._stylist_applyTo = apply_to;
|
||||
anch._stylist_applyTag = tag;
|
||||
|
||||
anch.innerHTML = this.config.css_style[x];
|
||||
anch.href = 'javascript:void(0)';
|
||||
var editor = this;
|
||||
anch.onclick = function()
|
||||
{
|
||||
if(this._stylist_applied == true)
|
||||
{
|
||||
editor._stylistRemoveClasses(this._stylist_className, this._stylist_appliedTo);
|
||||
}
|
||||
else
|
||||
{
|
||||
editor._stylistAddClasses(this._stylist_applyTo, this._stylist_applyTag, this._stylist_className);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
anch.style.display = 'block';
|
||||
anch.style.paddingLeft = '3px';
|
||||
anch.style.paddingTop = '1px';
|
||||
anch.style.paddingBottom = '1px';
|
||||
anch.style.textDecoration = 'none';
|
||||
|
||||
if(applied)
|
||||
{
|
||||
anch.style.background = 'Highlight';
|
||||
anch.style.color = 'HighlightText';
|
||||
}
|
||||
|
||||
this._stylist.appendChild(anch);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Add the given classes (space seperated list) to the currently selected element
|
||||
* (will add a span if none selected)
|
||||
*/
|
||||
HTMLArea.prototype._stylistAddClasses = function(el, tag, classes)
|
||||
{
|
||||
if(el == 'new')
|
||||
{
|
||||
this.insertHTML('<' + tag + ' class="' + classes + '">' + this.getSelectedHTML() + '</' + tag + '>');
|
||||
}
|
||||
else
|
||||
{
|
||||
if(tag != null && el.tagName.toLowerCase() != tag)
|
||||
{
|
||||
// Have to change the tag!
|
||||
var new_el = this.switchElementTag(el, tag);
|
||||
|
||||
if(typeof el._stylist_usedToBe != 'undefined')
|
||||
{
|
||||
new_el._stylist_usedToBe = el._stylist_usedToBe;
|
||||
new_el._stylist_usedToBe[new_el._stylist_usedToBe.length] = {'tagName' : el.tagName, 'className' : el.getAttribute('class')};
|
||||
}
|
||||
else
|
||||
{
|
||||
new_el._stylist_usedToBe = [{'tagName' : el.tagName, 'className' : el.getAttribute('class')}];
|
||||
}
|
||||
|
||||
HTMLArea.addClasses(new_el, classes);
|
||||
}
|
||||
else
|
||||
{
|
||||
HTMLArea._addClasses(el, classes);
|
||||
}
|
||||
}
|
||||
this.focusEditor();
|
||||
this.updateToolbar();
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove the given classes (space seperated list) from the given elements (array of elements)
|
||||
*/
|
||||
HTMLArea.prototype._stylistRemoveClasses = function(classes, from)
|
||||
{
|
||||
for(var x = 0; x < from.length; x++)
|
||||
{
|
||||
this._stylistRemoveClassesFull(from[x], classes);
|
||||
}
|
||||
this.focusEditor();
|
||||
this.updateToolbar();
|
||||
};
|
||||
|
||||
HTMLArea.prototype._stylistRemoveClassesFull = function(el, classes)
|
||||
{
|
||||
if(el != null)
|
||||
{
|
||||
var thiers = el.className.trim().split(' ');
|
||||
var new_thiers = [ ];
|
||||
var ours = classes.split(' ');
|
||||
for(var x = 0; x < thiers.length; x++)
|
||||
{
|
||||
var exists = false;
|
||||
for(var i = 0; exists == false && i < ours.length; i++)
|
||||
{
|
||||
if(ours[i] == thiers[x])
|
||||
{
|
||||
exists = true;
|
||||
}
|
||||
}
|
||||
if(exists == false)
|
||||
{
|
||||
new_thiers[new_thiers.length] = thiers[x];
|
||||
}
|
||||
}
|
||||
|
||||
if(new_thiers.length == 0 && el._stylist_usedToBe && el._stylist_usedToBe.length > 0 && el._stylist_usedToBe[el._stylist_usedToBe.length - 1].className != null)
|
||||
{
|
||||
// Revert back to what we were IF the classes are identical
|
||||
var last_el = el._stylist_usedToBe[el._stylist_usedToBe.length - 1];
|
||||
var last_classes = HTMLArea.arrayFilter(last_el.className.trim().split(' '), function(c) { if (c == null || c.trim() == '') { return false;} return true; });
|
||||
|
||||
if(
|
||||
(new_thiers.length == 0)
|
||||
||
|
||||
(
|
||||
HTMLArea.arrayContainsArray(new_thiers, last_classes)
|
||||
&& HTMLArea.arrayContainsArray(last_classes, new_thiers)
|
||||
)
|
||||
)
|
||||
{
|
||||
el = this.switchElementTag(el, last_el.tagName);
|
||||
new_thiers = last_classes;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We can't rely on the remembered tags any more
|
||||
el._stylist_usedToBe = [ ];
|
||||
}
|
||||
}
|
||||
|
||||
if( new_thiers.length > 0
|
||||
|| el.tagName.toLowerCase() != 'span'
|
||||
|| (el.id && el.id != '')
|
||||
)
|
||||
{
|
||||
el.className = new_thiers.join(' ').trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Must be a span with no classes and no id, so we can splice it out
|
||||
var prnt = el.parentNode;
|
||||
var childs = el.childNodes;
|
||||
for(var x = 0; x < childs.length; x++)
|
||||
{
|
||||
prnt.insertBefore(childs[x], el);
|
||||
}
|
||||
prnt.removeChild(el);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Change the tag of an element
|
||||
*/
|
||||
HTMLArea.prototype.switchElementTag = function(el, tag)
|
||||
{
|
||||
var prnt = el.parentNode;
|
||||
var new_el = this._doc.createElement(tag);
|
||||
|
||||
if(HTMLArea.is_ie || el.hasAttribute('id')) new_el.setAttribute('id', el.getAttribute('id'));
|
||||
if(HTMLArea.is_ie || el.hasAttribute('style')) new_el.setAttribute('style', el.getAttribute('style'));
|
||||
|
||||
var childs = el.childNodes;
|
||||
for(var x = 0; x < childs.length; x++)
|
||||
{
|
||||
new_el.appendChild(childs[x].cloneNode(true));
|
||||
}
|
||||
|
||||
prnt.insertBefore(new_el, el);
|
||||
new_el._stylist_usedToBe = [el.tagName];
|
||||
prnt.removeChild(el);
|
||||
this.selectNodeContents(new_el);
|
||||
return new_el;
|
||||
};
|
||||
|
||||
HTMLArea.prototype._getAncestorsClassNames = function(sel)
|
||||
{
|
||||
// Scan upwards to find a block level element that we can change or apply to
|
||||
var prnt = this._activeElement(sel);
|
||||
if(prnt == null)
|
||||
{
|
||||
prnt = (HTMLArea.is_ie ? this._createRange(sel).parentElement() : this._createRange(sel).commonAncestorContainer);
|
||||
}
|
||||
|
||||
var classNames = [ ];
|
||||
while(prnt)
|
||||
{
|
||||
if(prnt.nodeType == 1)
|
||||
{
|
||||
var classes = prnt.className.trim().split(' ');
|
||||
for(var x = 0; x < classes.length; x++)
|
||||
{
|
||||
classNames[classNames.length] = classes[x];
|
||||
}
|
||||
|
||||
if(prnt.tagName.toLowerCase() == 'body') break;
|
||||
if(prnt.tagName.toLowerCase() == 'table' ) break;
|
||||
}
|
||||
prnt = prnt.parentNode;
|
||||
}
|
||||
|
||||
return classNames;
|
||||
};
|
||||
|
||||
HTMLArea.prototype._ancestorsWithClasses = function(sel, tag, classes)
|
||||
{
|
||||
var ancestors = [ ];
|
||||
var prnt = this._activeElement(sel);
|
||||
if(prnt == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
prnt = (HTMLArea.is_ie ? this._createRange(sel).parentElement() : this._createRange(sel).commonAncestorContainer);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
return ancestors;
|
||||
}
|
||||
}
|
||||
var search_classes = classes.trim().split(' ');
|
||||
|
||||
while(prnt)
|
||||
{
|
||||
if(prnt.nodeType == 1)
|
||||
{
|
||||
if(tag == null || prnt.tagName.toLowerCase() == tag)
|
||||
{
|
||||
var classes = prnt.className.trim().split(' ');
|
||||
var found_all = true;
|
||||
for(var i = 0; i < search_classes.length; i++)
|
||||
{
|
||||
var found_class = false;
|
||||
for(var x = 0; x < classes.length; x++)
|
||||
{
|
||||
if(search_classes[i] == classes[x])
|
||||
{
|
||||
found_class = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found_class)
|
||||
{
|
||||
found_all = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(found_all) ancestors[ancestors.length] = prnt;
|
||||
}
|
||||
if(prnt.tagName.toLowerCase() == 'body') break;
|
||||
if(prnt.tagName.toLowerCase() == 'table' ) break;
|
||||
}
|
||||
prnt = prnt.parentNode;
|
||||
}
|
||||
|
||||
return ancestors;
|
||||
};
|
||||
|
||||
|
||||
HTMLArea.ripStylesFromCSSFile = function(URL)
|
||||
{
|
||||
var css = HTMLArea._geturlcontent(URL);
|
||||
return HTMLArea.ripStylesFromCSSString(css);
|
||||
};
|
||||
|
||||
HTMLArea.ripStylesFromCSSString = function(css)
|
||||
{
|
||||
// We are only interested in the selectors, the rules are not important
|
||||
// so we'll drop out all coments and rules
|
||||
RE_comment = /\/\*(.|\r|\n)*?\*\//g;
|
||||
RE_rule = /\{(.|\r|\n)*?\}/g;
|
||||
css = css.replace(RE_comment, '');
|
||||
css = css.replace(RE_rule, ',');
|
||||
|
||||
// And split on commas
|
||||
css = css.split(',');
|
||||
|
||||
// And add those into our structure
|
||||
var selectors = { };
|
||||
for(var x = 0; x < css.length; x++)
|
||||
{
|
||||
if(css[x].trim())
|
||||
{
|
||||
selectors[css[x].trim()] = css[x].trim();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return selectors;
|
||||
};
|
||||
|
||||
// Make our right side panel and insert appropriatly
|
||||
function Stylist(editor, args)
|
||||
{
|
||||
this.editor = editor;
|
||||
editor._stylist = null; // This needs to be changes to be Stylist::_stylist sometime
|
||||
editor._stylist = editor.addPanel('right');
|
||||
HTMLArea.addClass(editor._stylist, 'stylist');
|
||||
|
||||
var stylist = this;
|
||||
editor.notifyOn('modechange',
|
||||
function(e,args)
|
||||
{
|
||||
switch(args.mode)
|
||||
{
|
||||
case 'text':
|
||||
{
|
||||
editor.hidePanel(editor._stylist);
|
||||
break;
|
||||
}
|
||||
case 'wysiwyg':
|
||||
{
|
||||
editor.showPanel(editor._stylist);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Xinha.Config.prototype.css_style={};
|
||||
Xinha.Config.prototype.stylistLoadStylesheet=function(_1,_2){
|
||||
if(!_2){
|
||||
_2={};
|
||||
}
|
||||
|
||||
Stylist._pluginInfo =
|
||||
{
|
||||
name : "Stylist",
|
||||
version : "1.0",
|
||||
developer: "James Sleeman",
|
||||
developer_url: "http://www.gogo.co.nz/",
|
||||
c_owner : "Gogo Internet Services",
|
||||
license : "htmlArea",
|
||||
sponsor : "Gogo Internet Services",
|
||||
sponsor_url : "http://www.gogo.co.nz/"
|
||||
var _3=Xinha.ripStylesFromCSSFile(_1);
|
||||
for(var i in _3){
|
||||
if(_2[i]){
|
||||
this.css_style[i]=_2[i];
|
||||
}else{
|
||||
this.css_style[i]=_3[i];
|
||||
}
|
||||
}
|
||||
this.pageStyleSheets[this.pageStyleSheets.length]=_1;
|
||||
};
|
||||
|
||||
Stylist.prototype.onGenerate = function()
|
||||
{
|
||||
var editor = this.editor;
|
||||
if(typeof editor.config.css_style == 'undefined' || HTMLArea.objectProperties(editor.config.css_style).length == 0)
|
||||
{
|
||||
editor.removePanel(editor._stylist);
|
||||
editor._stylist = null;
|
||||
}
|
||||
Xinha.Config.prototype.stylistLoadStyles=function(_5,_6){
|
||||
if(!_6){
|
||||
_6={};
|
||||
}
|
||||
var _7=Xinha.ripStylesFromCSSString(_5);
|
||||
for(var i in _7){
|
||||
if(_6[i]){
|
||||
this.css_style[i]=_6[i];
|
||||
}else{
|
||||
this.css_style[i]=_7[i];
|
||||
}
|
||||
}
|
||||
this.pageStyle+=_5;
|
||||
};
|
||||
|
||||
Stylist.prototype.onUpdateToolbar = function()
|
||||
{
|
||||
if(this.editor._stylist)
|
||||
{
|
||||
if(this._timeoutID)
|
||||
{
|
||||
window.clearTimeout(this._timeoutID);
|
||||
}
|
||||
|
||||
var e = this.editor;
|
||||
this._timeoutID = window.setTimeout(function() { e._fillStylist(); }, 250);
|
||||
}
|
||||
};
|
||||
Xinha.prototype._fillStylist=function(){
|
||||
if(!this._stylist){
|
||||
return false;
|
||||
}
|
||||
this.plugins.Stylist.instance.main.innerHTML="";
|
||||
var _9=true;
|
||||
var _a=this._getSelection();
|
||||
var _b=this._activeElement(_a);
|
||||
for(var x in this.config.css_style){
|
||||
var _d=null;
|
||||
var _e=x.trim();
|
||||
var _f=true;
|
||||
var _10=_b;
|
||||
if(_f&&/[^a-zA-Z0-9_.-]/.test(_e)){
|
||||
_f=false;
|
||||
}
|
||||
if(_e.indexOf(".")<0){
|
||||
_f=false;
|
||||
}
|
||||
if(_f&&(_e.indexOf(".")>0)){
|
||||
_d=_e.substring(0,_e.indexOf(".")).toLowerCase();
|
||||
_e=_e.substring(_e.indexOf("."),_e.length);
|
||||
if(_b!=null&&_b.tagName.toLowerCase()==_d){
|
||||
_f=true;
|
||||
_10=_b;
|
||||
}else{
|
||||
if(this._getFirstAncestor(this._getSelection(),[_d])!=null){
|
||||
_f=true;
|
||||
_10=this._getFirstAncestor(this._getSelection(),[_d]);
|
||||
}else{
|
||||
if((_d=="div"||_d=="span"||_d=="p"||(_d.substr(0,1)=="h"&&_d.length==2&&_d!="hr"))){
|
||||
if(!this._selectionEmpty(this._getSelection())){
|
||||
_f=true;
|
||||
_10="new";
|
||||
}else{
|
||||
_10=this._getFirstAncestor(_a,["p","h1","h2","h3","h4","h5","h6","h7"]);
|
||||
if(_10!=null){
|
||||
_f=true;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
_f=false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(_f){
|
||||
_e=_e.substring(_e.indexOf("."),_e.length);
|
||||
_e=_e.replace("."," ");
|
||||
if(_10==null){
|
||||
if(this._selectionEmpty(this._getSelection())){
|
||||
_10=this._getFirstAncestor(this._getSelection(),null);
|
||||
}else{
|
||||
_10="new";
|
||||
_d="span";
|
||||
}
|
||||
}
|
||||
}
|
||||
var _11=(this._ancestorsWithClasses(_a,_d,_e).length>0?true:false);
|
||||
var _12=this._ancestorsWithClasses(_a,_d,_e);
|
||||
if(_f){
|
||||
var _13=document.createElement("a");
|
||||
_13._stylist_className=_e.trim();
|
||||
_13._stylist_applied=_11;
|
||||
_13._stylist_appliedTo=_12;
|
||||
_13._stylist_applyTo=_10;
|
||||
_13._stylist_applyTag=_d;
|
||||
_13.innerHTML=this.config.css_style[x];
|
||||
_13.href="javascript:void(0)";
|
||||
var _14=this;
|
||||
_13.onclick=function(){
|
||||
if(this._stylist_applied==true){
|
||||
_14._stylistRemoveClasses(this._stylist_className,this._stylist_appliedTo);
|
||||
}else{
|
||||
_14._stylistAddClasses(this._stylist_applyTo,this._stylist_applyTag,this._stylist_className);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
_13.style.display="block";
|
||||
_13.style.paddingLeft="3px";
|
||||
_13.style.paddingTop="1px";
|
||||
_13.style.paddingBottom="1px";
|
||||
_13.style.textDecoration="none";
|
||||
if(_11){
|
||||
_13.style.background="Highlight";
|
||||
_13.style.color="HighlightText";
|
||||
}
|
||||
this.plugins.Stylist.instance.main.appendChild(_13);
|
||||
}
|
||||
}
|
||||
};
|
||||
Xinha.prototype._stylistAddClasses=function(el,tag,_17){
|
||||
if(el=="new"){
|
||||
this.insertHTML("<"+tag+" class=\""+_17+"\">"+this.getSelectedHTML()+"</"+tag+">");
|
||||
}else{
|
||||
if(tag!=null&&el.tagName.toLowerCase()!=tag){
|
||||
var _18=this.switchElementTag(el,tag);
|
||||
if(typeof el._stylist_usedToBe!="undefined"){
|
||||
_18._stylist_usedToBe=el._stylist_usedToBe;
|
||||
_18._stylist_usedToBe[_18._stylist_usedToBe.length]={"tagName":el.tagName,"className":el.getAttribute("class")};
|
||||
}else{
|
||||
_18._stylist_usedToBe=[{"tagName":el.tagName,"className":el.getAttribute("class")}];
|
||||
}
|
||||
Xinha.addClasses(_18,_17);
|
||||
}else{
|
||||
Xinha._addClasses(el,_17);
|
||||
}
|
||||
}
|
||||
this.focusEditor();
|
||||
this.updateToolbar();
|
||||
};
|
||||
Xinha.prototype._stylistRemoveClasses=function(_19,_1a){
|
||||
for(var x=0;x<_1a.length;x++){
|
||||
this._stylistRemoveClassesFull(_1a[x],_19);
|
||||
}
|
||||
this.focusEditor();
|
||||
this.updateToolbar();
|
||||
};
|
||||
Xinha.prototype._stylistRemoveClassesFull=function(el,_1d){
|
||||
if(el!=null){
|
||||
var _1e=el.className.trim().split(" ");
|
||||
var _1f=[];
|
||||
var _20=_1d.split(" ");
|
||||
for(var x=0;x<_1e.length;x++){
|
||||
var _22=false;
|
||||
for(var i=0;_22==false&&i<_20.length;i++){
|
||||
if(_20[i]==_1e[x]){
|
||||
_22=true;
|
||||
}
|
||||
}
|
||||
if(_22==false){
|
||||
_1f[_1f.length]=_1e[x];
|
||||
}
|
||||
}
|
||||
if(_1f.length==0&&el._stylist_usedToBe&&el._stylist_usedToBe.length>0&&el._stylist_usedToBe[el._stylist_usedToBe.length-1].className!=null){
|
||||
var _24=el._stylist_usedToBe[el._stylist_usedToBe.length-1];
|
||||
var _25=Xinha.arrayFilter(_24.className.trim().split(" "),function(c){
|
||||
if(c==null||c.trim()==""){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if((_1f.length==0)||(Xinha.arrayContainsArray(_1f,_25)&&Xinha.arrayContainsArray(_25,_1f))){
|
||||
el=this.switchElementTag(el,_24.tagName);
|
||||
_1f=_25;
|
||||
}else{
|
||||
el._stylist_usedToBe=[];
|
||||
}
|
||||
}
|
||||
if(_1f.length>0||el.tagName.toLowerCase()!="span"||(el.id&&el.id!="")){
|
||||
el.className=_1f.join(" ").trim();
|
||||
}else{
|
||||
var _27=el.parentNode;
|
||||
var _28=el.childNodes;
|
||||
for(var x=0;x<_28.length;x++){
|
||||
_27.insertBefore(_28[x],el);
|
||||
}
|
||||
_27.removeChild(el);
|
||||
}
|
||||
}
|
||||
};
|
||||
Xinha.prototype.switchElementTag=function(el,tag){
|
||||
var _2b=el.parentNode;
|
||||
var _2c=this._doc.createElement(tag);
|
||||
if(Xinha.is_ie||el.hasAttribute("id")){
|
||||
_2c.setAttribute("id",el.getAttribute("id"));
|
||||
}
|
||||
if(Xinha.is_ie||el.hasAttribute("style")){
|
||||
_2c.setAttribute("style",el.getAttribute("style"));
|
||||
}
|
||||
var _2d=el.childNodes;
|
||||
for(var x=0;x<_2d.length;x++){
|
||||
_2c.appendChild(_2d[x].cloneNode(true));
|
||||
}
|
||||
_2b.insertBefore(_2c,el);
|
||||
_2c._stylist_usedToBe=[el.tagName];
|
||||
_2b.removeChild(el);
|
||||
this.selectNodeContents(_2c);
|
||||
return _2c;
|
||||
};
|
||||
Xinha.prototype._getAncestorsClassNames=function(sel){
|
||||
var _30=this._activeElement(sel);
|
||||
if(_30==null){
|
||||
_30=(Xinha.is_ie?this._createRange(sel).parentElement():this._createRange(sel).commonAncestorContainer);
|
||||
}
|
||||
var _31=[];
|
||||
while(_30){
|
||||
if(_30.nodeType==1){
|
||||
var _32=_30.className.trim().split(" ");
|
||||
for(var x=0;x<_32.length;x++){
|
||||
_31[_31.length]=_32[x];
|
||||
}
|
||||
if(_30.tagName.toLowerCase()=="body"){
|
||||
break;
|
||||
}
|
||||
if(_30.tagName.toLowerCase()=="table"){
|
||||
break;
|
||||
}
|
||||
}
|
||||
_30=_30.parentNode;
|
||||
}
|
||||
return _31;
|
||||
};
|
||||
Xinha.prototype._ancestorsWithClasses=function(sel,tag,_36){
|
||||
var _37=[];
|
||||
var _38=this._activeElement(sel);
|
||||
if(_38==null){
|
||||
try{
|
||||
_38=(Xinha.is_ie?this._createRange(sel).parentElement():this._createRange(sel).commonAncestorContainer);
|
||||
}
|
||||
catch(e){
|
||||
return _37;
|
||||
}
|
||||
}
|
||||
var _39=_36.trim().split(" ");
|
||||
while(_38){
|
||||
if(_38.nodeType==1&&_38.className){
|
||||
if(tag==null||_38.tagName.toLowerCase()==tag){
|
||||
var _36=_38.className.trim().split(" ");
|
||||
var _3a=true;
|
||||
for(var i=0;i<_39.length;i++){
|
||||
var _3c=false;
|
||||
for(var x=0;x<_36.length;x++){
|
||||
if(_39[i]==_36[x]){
|
||||
_3c=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!_3c){
|
||||
_3a=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(_3a){
|
||||
_37[_37.length]=_38;
|
||||
}
|
||||
}
|
||||
if(_38.tagName.toLowerCase()=="body"){
|
||||
break;
|
||||
}
|
||||
if(_38.tagName.toLowerCase()=="table"){
|
||||
break;
|
||||
}
|
||||
}
|
||||
_38=_38.parentNode;
|
||||
}
|
||||
return _37;
|
||||
};
|
||||
Xinha.ripStylesFromCSSFile=function(URL){
|
||||
var css=Xinha._geturlcontent(URL);
|
||||
return Xinha.ripStylesFromCSSString(css);
|
||||
};
|
||||
Xinha.ripStylesFromCSSString=function(css){
|
||||
RE_comment=/\/\*(.|\r|\n)*?\*\//g;
|
||||
RE_rule=/\{(.|\r|\n)*?\}/g;
|
||||
css=css.replace(RE_comment,"");
|
||||
css=css.replace(RE_rule,",");
|
||||
css=css.split(",");
|
||||
var _41={};
|
||||
for(var x=0;x<css.length;x++){
|
||||
if(css[x].trim()){
|
||||
_41[css[x].trim()]=css[x].trim();
|
||||
}
|
||||
}
|
||||
return _41;
|
||||
};
|
||||
function Stylist(_43,_44){
|
||||
this.editor=_43;
|
||||
var _45=this;
|
||||
}
|
||||
Stylist._pluginInfo={name:"Stylist",version:"1.0",developer:"James Sleeman",developer_url:"http://www.gogo.co.nz/",c_owner:"Gogo Internet Services",license:"HTMLArea",sponsor:"Gogo Internet Services",sponsor_url:"http://www.gogo.co.nz/"};
|
||||
Stylist.prototype.onGenerateOnce=function(){
|
||||
var _46=this.editor;
|
||||
var _47=this;
|
||||
if(typeof _46.config.css_style!="undefined"&&Xinha.objectProperties(_46.config.css_style).length!=0){
|
||||
_46._stylist=null;
|
||||
_46._stylist=_46.addPanel("right");
|
||||
Xinha.addClass(_46._stylist,"stylist");
|
||||
this.caption=document.createElement("h1");
|
||||
this.caption.innerHTML=Xinha._lc("Styles","Stylist");
|
||||
_46._stylist.appendChild(this.caption);
|
||||
this.main=document.createElement("div");
|
||||
this.main.style.overflow="auto";
|
||||
this.main.style.height=this.editor._framework.ed_cell.offsetHeight-this.caption.offsetHeight+"px";
|
||||
_46._stylist.appendChild(this.main);
|
||||
Xinha.freeLater(this,"caption");
|
||||
Xinha.freeLater(this,"main");
|
||||
_46.notifyOn("modechange",function(e,_49){
|
||||
switch(_49.mode){
|
||||
case "text":
|
||||
_46.hidePanel(_46._stylist);
|
||||
break;
|
||||
case "wysiwyg":
|
||||
_46.showPanel(_46._stylist);
|
||||
break;
|
||||
}
|
||||
});
|
||||
_46.notifyOn("panel_change",function(e,_4b){
|
||||
switch(_4b.action){
|
||||
case "show":
|
||||
var _4c=_47.main.offsetHeight-_4b.panel.offsetHeight;
|
||||
_47.main.style.height=((_4c>0)?_47.main.offsetHeight-_4b.panel.offsetHeight:0)+"px";
|
||||
_46._stylist.style.height=_47.caption.offsetHeight+"px";
|
||||
_46.sizeEditor();
|
||||
break;
|
||||
case "hide":
|
||||
_47.resize();
|
||||
break;
|
||||
}
|
||||
});
|
||||
_46.notifyOn("before_resize",function(){
|
||||
_46._stylist.style.height=_47.caption.offsetHeight+"px";
|
||||
});
|
||||
_46.notifyOn("resize",function(){
|
||||
_47.resize();
|
||||
});
|
||||
}
|
||||
};
|
||||
Stylist.prototype.resize=function(){
|
||||
var _4d=this.editor;
|
||||
var _4e=_4d._stylist.parentNode;
|
||||
var _4f=_4e.offsetHeight;
|
||||
for(var i=0;i<_4e.childNodes.length;++i){
|
||||
if(_4e.childNodes[i]==_4d._stylist||!_4e.childNodes[i].offsetHeight){
|
||||
continue;
|
||||
}
|
||||
_4f-=_4e.childNodes[i].offsetHeight;
|
||||
}
|
||||
_4d._stylist.style.height=_4f+"px";
|
||||
this.main.style.height=_4f-this.caption.offsetHeight+"px";
|
||||
};
|
||||
Stylist.prototype.onUpdateToolbar=function(){
|
||||
if(this.editor._stylist){
|
||||
if(this._timeoutID){
|
||||
window.clearTimeout(this._timeoutID);
|
||||
}
|
||||
var e=this.editor;
|
||||
this._timeoutID=window.setTimeout(function(){
|
||||
e._fillStylist();
|
||||
},250);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user