-
Notifications
You must be signed in to change notification settings - Fork 2
/
editor_plugin.js
162 lines (128 loc) · 5.3 KB
/
editor_plugin.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
tinyMCE.importPluginLanguagePack('ecom');
var TinyMCE_ecom_Plugin = {
getInfo : function() {
return {
longname : 'e-Commerce',
author : 'Allen Han',
authorurl : 'http://www.instinct.co.nz',
infourl : 'http://www.instinct.co.nz',
version : "1.0"
};
},
// initInstance : function(inst) {
// inst.addShortcut('ctrl', 'p', 'lang_dd_code_desc', 'mcedd_code');
// },
getControlHTML : function(cn) {
switch (cn) {
case "ecom":
return tinyMCE.getButtonHTML(cn, 'lang_dd_code_desc', '{$pluginurl}/images/cart.png', 'mceecom_code', true);
}
return "";
},
execCommand : function(editor_id, element, command, user_interface, value) {
switch (command) {
case "mceecom_code":
var src = "", alt = "", border = "", hspace = "", vspace = "", width = "", height = "", align = "";
var title = "", onmouseover = "", onmouseout = "", action = "insert";
var img = tinyMCE.imgElement;
var inst = tinyMCE.getInstanceById(editor_id);
if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img") {
img = tinyMCE.selectedElement;
tinyMCE.imgElement = img;
}
if (img) {
// Is it a internal MCE visual aid image, then skip this one.
if (tinyMCE.getAttrib(img, 'name').indexOf('mce_') == 0)
return true;
src = tinyMCE.getAttrib(img, 'src');
alt = tinyMCE.getAttrib(img, 'alt');
// Try polling out the title
if (alt == "")
alt = tinyMCE.getAttrib(img, 'title');
// Fix width/height attributes if the styles is specified
if (tinyMCE.isGecko) {
var w = img.style.width;
if (w != null && w != "")
img.setAttribute("width", w);
var h = img.style.height;
if (h != null && h != "")
img.setAttribute("height", h);
}alert(src);
border = tinyMCE.getAttrib(img, 'border');
hspace = tinyMCE.getAttrib(img, 'hspace');
vspace = tinyMCE.getAttrib(img, 'vspace');
width = tinyMCE.getAttrib(img, 'width');
height = tinyMCE.getAttrib(img, 'height');
align = tinyMCE.getAttrib(img, 'align');
onmouseover = tinyMCE.getAttrib(img, 'onmouseover');
onmouseout = tinyMCE.getAttrib(img, 'onmouseout');
title = tinyMCE.getAttrib(img, 'title');
// Is realy specified?
if (tinyMCE.isMSIE) {
width = img.attributes['width'].specified ? width : "";
height = img.attributes['height'].specified ? height : "";
}
//onmouseover = tinyMCE.getImageSrc(tinyMCE.cleanupEventStr(onmouseover));
//onmouseout = tinyMCE.getImageSrc(tinyMCE.cleanupEventStr(onmouseout));
src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, img, true);");
// Use mce_src if defined
mceRealSrc = tinyMCE.getAttrib(img, 'mce_src');
if (mceRealSrc != "") {
src = mceRealSrc;
if (tinyMCE.getParam('convert_urls'))
src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, img, true);");
}
//if (onmouseover != "")
// onmouseover = eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseover, img, true);");
//if (onmouseout != "")
// onmouseout = eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseout, img, true);");
action = "update";
}
var template = new Array();
template['file'] = purl+'insertcate.php';
template['width'] = 300;
template['height'] = 200 + (tinyMCE.isMSIE ? 25 : 0);
// Language specific width and height addons
template['width'] += tinyMCE.getLang('lang_insert_image_delta_width', 0);
template['height'] += tinyMCE.getLang('lang_insert_image_delta_height', 0);
if (inst.settings['insertimage_callback']) {
var returnVal = eval(inst.settings['insertimage_callback'] + "(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout, action);");
if (returnVal && returnVal['src'])
TinyMCE_AdvancedTheme._insertImage(returnVal['src'], returnVal['alt'], returnVal['border'], returnVal['hspace'], returnVal['vspace'], returnVal['width'], returnVal['height'], returnVal['align'], returnVal['title'], returnVal['onmouseover'], returnVal['onmouseout']);
} else {
tinyMCE.openWindow(template, {src : src, alt : "asdfasdf", border : border, hspace : hspace, vspace : vspace, width : width, height : height, align : align, title : title, onmouseover : onmouseover, onmouseout : onmouseout, action : action, inline : "yes"});
}
return true;
}
return false;
},
handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
if ( (node.nodeName == "SPAN" || node.nodeName == "DIV") && tinyMCE.getAttrib(node, 'class') == "sfcode" ) {
tinyMCE.switchClass(editor_id + '_dd_code', 'mceButtonSelected');
return true;
}
else if ( any_selection == "" ) {
tinyMCE.switchClass(editor_id + '_dd_code', 'mceButtonDisabled');
return true;
}
else
tinyMCE.switchClass(editor_id + '_dd_code', 'mceButtonNormal');
},
cleanup : function(type, content, inst) {
switch (type) {
case "insert_to_editor_dom":
break;
case "insert_to_editor":
break;
case "get_from_editor":
break;
}
return content;
},
// Private plugin internal methods
_someInternalFunction : function(a, b) {
return 1;
}
};
// Add the plugin class to the list of available TinyMCE plugins
tinyMCE.addPlugin("ecom", TinyMCE_ecom_Plugin);