4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
11 tinyMCEPopup
.requireLangPack();
13 function initCommonAttributes(elm
) {
14 var formObj
= document
.forms
[0], dom
= tinyMCEPopup
.editor
.dom
;
16 // Setup form data for common element attributes
17 setFormValue('title', dom
.getAttrib(elm
, 'title'));
18 setFormValue('id', dom
.getAttrib(elm
, 'id'));
19 selectByValue(formObj
, 'class', dom
.getAttrib(elm
, 'class'), true);
20 setFormValue('style', dom
.getAttrib(elm
, 'style'));
21 selectByValue(formObj
, 'dir', dom
.getAttrib(elm
, 'dir'));
22 setFormValue('lang', dom
.getAttrib(elm
, 'lang'));
23 setFormValue('onfocus', dom
.getAttrib(elm
, 'onfocus'));
24 setFormValue('onblur', dom
.getAttrib(elm
, 'onblur'));
25 setFormValue('onclick', dom
.getAttrib(elm
, 'onclick'));
26 setFormValue('ondblclick', dom
.getAttrib(elm
, 'ondblclick'));
27 setFormValue('onmousedown', dom
.getAttrib(elm
, 'onmousedown'));
28 setFormValue('onmouseup', dom
.getAttrib(elm
, 'onmouseup'));
29 setFormValue('onmouseover', dom
.getAttrib(elm
, 'onmouseover'));
30 setFormValue('onmousemove', dom
.getAttrib(elm
, 'onmousemove'));
31 setFormValue('onmouseout', dom
.getAttrib(elm
, 'onmouseout'));
32 setFormValue('onkeypress', dom
.getAttrib(elm
, 'onkeypress'));
33 setFormValue('onkeydown', dom
.getAttrib(elm
, 'onkeydown'));
34 setFormValue('onkeyup', dom
.getAttrib(elm
, 'onkeyup'));
37 function setFormValue(name
, value
) {
38 if(document
.forms
[0].elements
[name
]) document
.forms
[0].elements
[name
].value
= value
;
41 function insertDateTime(id
) {
42 document
.getElementById(id
).value
= getDateTime(new Date(), "%Y-%m-%dT%H:%M:%S");
45 function getDateTime(d
, fmt
) {
46 fmt
= fmt
.replace("%D", "%m/%d/%y");
47 fmt
= fmt
.replace("%r", "%I:%M:%S %p");
48 fmt
= fmt
.replace("%Y", "" + d
.getFullYear());
49 fmt
= fmt
.replace("%y", "" + d
.getYear());
50 fmt
= fmt
.replace("%m", addZeros(d
.getMonth()+1, 2));
51 fmt
= fmt
.replace("%d", addZeros(d
.getDate(), 2));
52 fmt
= fmt
.replace("%H", "" + addZeros(d
.getHours(), 2));
53 fmt
= fmt
.replace("%M", "" + addZeros(d
.getMinutes(), 2));
54 fmt
= fmt
.replace("%S", "" + addZeros(d
.getSeconds(), 2));
55 fmt
= fmt
.replace("%I", "" + ((d
.getHours() + 11) % 12 + 1));
56 fmt
= fmt
.replace("%p", "" + (d
.getHours() < 12 ? "AM" : "PM"));
57 fmt
= fmt
.replace("%%", "%");
62 function addZeros(value
, len
) {
67 if (value
.length
< len
) {
68 for (i
=0; i
<(len
-value
.length
); i
++)
75 function selectByValue(form_obj
, field_name
, value
, add_custom
, ignore_case
) {
76 if (!form_obj
|| !form_obj
.elements
[field_name
])
79 var sel
= form_obj
.elements
[field_name
];
82 for (var i
=0; i
<sel
.options
.length
; i
++) {
83 var option
= sel
.options
[i
];
85 if (option
.value
== value
|| (ignore_case
&& option
.value
.toLowerCase() == value
.toLowerCase())) {
86 option
.selected
= true;
89 option
.selected
= false;
92 if (!found
&& add_custom
&& value
!= '') {
93 var option
= new Option('Value: ' + value
, value
);
94 option
.selected
= true;
95 sel
.options
[sel
.options
.length
] = option
;
101 function setAttrib(elm
, attrib
, value
) {
102 var formObj
= document
.forms
[0];
103 var valueElm
= formObj
.elements
[attrib
.toLowerCase()];
104 tinyMCEPopup
.editor
.dom
.setAttrib(elm
, attrib
, value
|| valueElm
.value
);
107 function setAllCommonAttribs(elm
) {
108 setAttrib(elm
, 'title');
109 setAttrib(elm
, 'id');
110 setAttrib(elm
, 'class');
111 setAttrib(elm
, 'style');
112 setAttrib(elm
, 'dir');
113 setAttrib(elm
, 'lang');
114 /*setAttrib(elm, 'onfocus');
115 setAttrib(elm, 'onblur');
116 setAttrib(elm, 'onclick');
117 setAttrib(elm, 'ondblclick');
118 setAttrib(elm, 'onmousedown');
119 setAttrib(elm, 'onmouseup');
120 setAttrib(elm, 'onmouseover');
121 setAttrib(elm, 'onmousemove');
122 setAttrib(elm, 'onmouseout');
123 setAttrib(elm, 'onkeypress');
124 setAttrib(elm, 'onkeydown');
125 setAttrib(elm, 'onkeyup');*/
129 currentAction
: "insert",
130 inst
: tinyMCEPopup
.editor
,
134 SXE
.focusElement
= SXE
.inst
.selection
.getNode();
136 SXE
.initElementDialog = function(element_name
) {
137 addClassesToList('class', 'xhtmlxtras_styles');
138 TinyMCE_EditableSelects
.init();
140 element_name
= element_name
.toLowerCase();
141 var elm
= SXE
.inst
.dom
.getParent(SXE
.focusElement
, element_name
.toUpperCase());
142 if (elm
!= null && elm
.nodeName
.toUpperCase() == element_name
.toUpperCase()) {
143 SXE
.currentAction
= "update";
146 if (SXE
.currentAction
== "update") {
147 initCommonAttributes(elm
);
148 SXE
.updateElement
= elm
;
151 document
.forms
[0].insert
.value
= tinyMCEPopup
.getLang(SXE
.currentAction
, 'Insert', true);
154 SXE
.insertElement = function(element_name
) {
155 var elm
= SXE
.inst
.dom
.getParent(SXE
.focusElement
, element_name
.toUpperCase()), h
, tagName
;
158 var s
= SXE
.inst
.selection
.getContent();
160 tagName
= element_name
;
162 insertInlineElement(element_name
);
163 var elementArray
= tinymce
.grep(SXE
.inst
.dom
.select(element_name
));
164 for (var i
=0; i
<elementArray
.length
; i
++) {
165 var elm
= elementArray
[i
];
167 if (SXE
.inst
.dom
.getAttrib(elm
, 'data-mce-new')) {
169 elm
.setAttribute('id', '');
170 elm
.removeAttribute('id');
171 elm
.removeAttribute('data-mce-new');
173 setAllCommonAttribs(elm
);
178 setAllCommonAttribs(elm
);
180 SXE
.inst
.nodeChanged();
181 tinyMCEPopup
.execCommand('mceEndUndoLevel');
184 SXE
.removeElement = function(element_name
){
185 element_name
= element_name
.toLowerCase();
186 elm
= SXE
.inst
.dom
.getParent(SXE
.focusElement
, element_name
.toUpperCase());
187 if(elm
&& elm
.nodeName
.toUpperCase() == element_name
.toUpperCase()){
188 tinyMCE
.execCommand('mceRemoveNode', false, elm
);
189 SXE
.inst
.nodeChanged();
190 tinyMCEPopup
.execCommand('mceEndUndoLevel');
194 SXE
.showRemoveButton = function() {
195 document
.getElementById("remove").style
.display
= '';
198 SXE
.containsClass = function(elm
,cl
) {
199 return (elm
.className
.indexOf(cl
) > -1) ? true : false;
202 SXE
.removeClass = function(elm
,cl
) {
203 if(elm
.className
== null || elm
.className
== "" || !SXE
.containsClass(elm
,cl
)) {
206 var classNames
= elm
.className
.split(" ");
207 var newClassNames
= "";
208 for (var x
= 0, cnl
= classNames
.length
; x
< cnl
; x
++) {
209 if (classNames
[x
] != cl
) {
210 newClassNames
+= (classNames
[x
] + " ");
213 elm
.className
= newClassNames
.substring(0,newClassNames
.length
-1); //removes extra space at the end
216 SXE
.addClass = function(elm
,cl
) {
217 if(!SXE
.containsClass(elm
,cl
)) elm
.className
? elm
.className
+= " " + cl
: elm
.className
= cl
;
221 function insertInlineElement(en
) {
222 var ed
= tinyMCEPopup
.editor
, dom
= ed
.dom
;
224 ed
.getDoc().execCommand('FontName', false, 'mceinline');
225 tinymce
.each(dom
.select('span,font'), function(n
) {
226 if (n
.style
.fontFamily
== 'mceinline' || n
.face
== 'mceinline')
227 dom
.replace(dom
.create(en
, {'data-mce-new' : 1}), n
, 1);