source: [view]
var doc = this.editor.document;
if(!this._styled){
try{
//Attempt to inject our specialized style rules for doing this.
this._styled = true;
var style = "";
var blocks = ["div", "p", "ul", "ol", "table", "h1",
"h2", "h3", "h4", "h5", "h6", "pre", "dir", "center",
"blockquote", "form", "fieldset", "address", "object",
"pre", "hr", "ins", "noscript", "li", "map", "button",
"dd", "dt"];
var template = "@media screen {\n" +
"\t.editorShowBlocks {TAG} {\n" +
"\t\tbackground-image: url({MODURL}/images/blockelems/{TAG}.gif);\n" +
"\t\tbackground-repeat: no-repeat;\n" +
"\t\tbackground-position: top left;\n" +
"\t\tborder-width: 1px;\n" +
"\t\tborder-style: dashed;\n" +
"\t\tborder-color: #D0D0D0;\n" +
"\t\tpadding-top: 15px;\n" +
"\t\tpadding-left: 15px;\n" +
"\t}\n" +
"}\n";
dojo.forEach(blocks, function(tag){
style += template.replace(/\{TAG\}/gi, tag);
});
//Finally associate in the image locations based off the module url.
var modurl = dojo.moduleUrl(dojox._scopeName, "editor/plugins/resources").toString();
if(!(modurl.match(/^https?:\/\//i)) &&
!(modurl.match(/^file:\/\//i))){
// We have to root it to the page location on webkit for some nutball reason.
// Probably has to do with how iframe was loaded.
var bUrl;
if(modurl.charAt(0) === "/"){
//Absolute path on the server, so lets handle...
var proto = dojo.doc.location.protocol;
var hostn = dojo.doc.location.host;
bUrl = proto + "//" + hostn;
}else{
bUrl = this._calcBaseUrl(dojo.global.location.href);
}
if(bUrl[bUrl.length - 1] !== "/" && modurl.charAt(0) !== "/"){
bUrl += "/";
}
modurl = bUrl + modurl;
}
// Update all the urls.
style = style.replace(/\{MODURL\}/gi, modurl);
if(!dojo.isIE){
var sNode = doc.createElement("style");
sNode.appendChild(doc.createTextNode(style));
doc.getElementsByTagName("head")[0].appendChild(sNode);
}else{
var ss = doc.createStyleSheet("");
ss.cssText = style;
}
}catch(e){
console.warn(e);
}
}
// Apply/remove the classes based on state.
if(show){
dojo.addClass(this.editor.editNode, "editorShowBlocks");
}else{
dojo.removeClass(this.editor.editNode, "editorShowBlocks");
}