template.js
1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Created with JetBrains PhpStorm.
* User: xuheng
* Date: 12-8-8
* Time: 下午2:09
* To change this template use File | Settings | File Templates.
*/
(function () {
var me = editor,
preview = $G( "preview" ),
preitem = $G( "preitem" ),
tmps = templates,
currentTmp;
var initPre = function () {
var str = "";
for ( var i = 0, tmp; tmp = tmps[i++]; ) {
str += '<div class="preitem" onclick="pre(' + i + ')"><img src="' + "images/" + tmp.pre + '" ' + (tmp.title ? "alt=" + tmp.title + " title=" + tmp.title + "" : "") + '></div>';
}
preitem.innerHTML = str;
};
var pre = function ( n ) {
var tmp = tmps[n - 1];
currentTmp = tmp;
clearItem();
domUtils.setStyles( preitem.childNodes[n - 1], {
"background-color":"lemonChiffon",
"border":"#ccc 1px solid"
} );
preview.innerHTML = tmp.preHtml ? tmp.preHtml : "";
};
var clearItem = function () {
var items = preitem.children;
for ( var i = 0, item; item = items[i++]; ) {
domUtils.setStyles( item, {
"background-color":"",
"border":"white 1px solid"
} );
}
};
dialog.onok = function () {
if ( !$G( "issave" ).checked ){
me.execCommand( "cleardoc" );
}
var obj = {
html:currentTmp && currentTmp.html
};
me.execCommand( "template", obj );
};
initPre();
window.pre = pre;
pre(2)
})();