PageRenderTime 70ms CodeModel.GetById 51ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/table/js/row.js

#
JavaScript | 237 lines | 172 code | 51 blank | 14 comment | 36 complexity | 9c06d9dec390ebf1a36fb3452a21b1f8 MD5 | raw file
  1tinyMCEPopup.requireLangPack();
  2
  3function init() {
  4	tinyMCEPopup.resizeToInnerSize();
  5
  6	document.getElementById('backgroundimagebrowsercontainer').innerHTML = getBrowserHTML('backgroundimagebrowser','backgroundimage','image','table');
  7	document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor');
  8
  9	var inst = tinyMCEPopup.editor;
 10	var dom = inst.dom;
 11	var trElm = dom.getParent(inst.selection.getStart(), "tr");
 12	var formObj = document.forms[0];
 13	var st = dom.parseStyle(dom.getAttrib(trElm, "style"));
 14
 15	// Get table row data
 16	var rowtype = trElm.parentNode.nodeName.toLowerCase();
 17	var align = dom.getAttrib(trElm, 'align');
 18	var valign = dom.getAttrib(trElm, 'valign');
 19	var height = trimSize(getStyle(trElm, 'height', 'height'));
 20	var className = dom.getAttrib(trElm, 'class');
 21	var bgcolor = convertRGBToHex(getStyle(trElm, 'bgcolor', 'backgroundColor'));
 22	var backgroundimage = getStyle(trElm, 'background', 'backgroundImage').replace(new RegExp("url\\(['\"]?([^'\"]*)['\"]?\\)", 'gi'), "$1");
 23	var id = dom.getAttrib(trElm, 'id');
 24	var lang = dom.getAttrib(trElm, 'lang');
 25	var dir = dom.getAttrib(trElm, 'dir');
 26
 27	selectByValue(formObj, 'rowtype', rowtype);
 28
 29	// Any cells selected
 30	if (dom.select('td.mceSelected,th.mceSelected', trElm).length == 0) {
 31		// Setup form
 32		addClassesToList('class', 'table_row_styles');
 33		TinyMCE_EditableSelects.init();
 34
 35		formObj.bgcolor.value = bgcolor;
 36		formObj.backgroundimage.value = backgroundimage;
 37		formObj.height.value = height;
 38		formObj.id.value = id;
 39		formObj.lang.value = lang;
 40		formObj.style.value = dom.serializeStyle(st);
 41		selectByValue(formObj, 'align', align);
 42		selectByValue(formObj, 'valign', valign);
 43		selectByValue(formObj, 'class', className, true, true);
 44		selectByValue(formObj, 'dir', dir);
 45
 46		// Resize some elements
 47		if (isVisible('backgroundimagebrowser'))
 48			document.getElementById('backgroundimage').style.width = '180px';
 49
 50		updateColor('bgcolor_pick', 'bgcolor');
 51	} else
 52		tinyMCEPopup.dom.hide('action');
 53}
 54
 55function updateAction() {
 56	var inst = tinyMCEPopup.editor, dom = inst.dom, trElm, tableElm, formObj = document.forms[0];
 57	var action = getSelectValue(formObj, 'action');
 58
 59	if (!AutoValidator.validate(formObj)) {
 60		tinyMCEPopup.alert(AutoValidator.getErrorMessages(formObj).join('. ') + '.');
 61		return false;
 62	}
 63
 64	tinyMCEPopup.restoreSelection();
 65	trElm = dom.getParent(inst.selection.getStart(), "tr");
 66	tableElm = dom.getParent(inst.selection.getStart(), "table");
 67
 68	// Update all selected rows
 69	if (dom.select('td.mceSelected,th.mceSelected', trElm).length > 0) {
 70		tinymce.each(tableElm.rows, function(tr) {
 71			var i;
 72
 73			for (i = 0; i < tr.cells.length; i++) {
 74				if (dom.hasClass(tr.cells[i], 'mceSelected')) {
 75					updateRow(tr, true);
 76					return;
 77				}
 78			}
 79		});
 80
 81		inst.addVisual();
 82		inst.nodeChanged();
 83		inst.execCommand('mceEndUndoLevel');
 84		tinyMCEPopup.close();
 85		return;
 86	}
 87
 88	switch (action) {
 89		case "row":
 90			updateRow(trElm);
 91			break;
 92
 93		case "all":
 94			var rows = tableElm.getElementsByTagName("tr");
 95
 96			for (var i=0; i<rows.length; i++)
 97				updateRow(rows[i], true);
 98
 99			break;
100
101		case "odd":
102		case "even":
103			var rows = tableElm.getElementsByTagName("tr");
104
105			for (var i=0; i<rows.length; i++) {
106				if ((i % 2 == 0 && action == "odd") || (i % 2 != 0 && action == "even"))
107					updateRow(rows[i], true, true);
108			}
109
110			break;
111	}
112
113	inst.addVisual();
114	inst.nodeChanged();
115	inst.execCommand('mceEndUndoLevel');
116	tinyMCEPopup.close();
117}
118
119function updateRow(tr_elm, skip_id, skip_parent) {
120	var inst = tinyMCEPopup.editor;
121	var formObj = document.forms[0];
122	var dom = inst.dom;
123	var curRowType = tr_elm.parentNode.nodeName.toLowerCase();
124	var rowtype = getSelectValue(formObj, 'rowtype');
125	var doc = inst.getDoc();
126
127	// Update row element
128	if (!skip_id)
129		dom.setAttrib(tr_elm, 'id', formObj.id.value);
130
131	dom.setAttrib(tr_elm, 'align', getSelectValue(formObj, 'align'));
132	dom.setAttrib(tr_elm, 'vAlign', getSelectValue(formObj, 'valign'));
133	dom.setAttrib(tr_elm, 'lang', formObj.lang.value);
134	dom.setAttrib(tr_elm, 'dir', getSelectValue(formObj, 'dir'));
135	dom.setAttrib(tr_elm, 'style', dom.serializeStyle(dom.parseStyle(formObj.style.value)));
136	dom.setAttrib(tr_elm, 'class', getSelectValue(formObj, 'class'));
137
138	// Clear deprecated attributes
139	dom.setAttrib(tr_elm, 'background', '');
140	dom.setAttrib(tr_elm, 'bgColor', '');
141	dom.setAttrib(tr_elm, 'height', '');
142
143	// Set styles
144	tr_elm.style.height = getCSSSize(formObj.height.value);
145	tr_elm.style.backgroundColor = formObj.bgcolor.value;
146
147	if (formObj.backgroundimage.value != "")
148		tr_elm.style.backgroundImage = "url('" + formObj.backgroundimage.value + "')";
149	else
150		tr_elm.style.backgroundImage = '';
151
152	// Setup new rowtype
153	if (curRowType != rowtype && !skip_parent) {
154		// first, clone the node we are working on
155		var newRow = tr_elm.cloneNode(1);
156
157		// next, find the parent of its new destination (creating it if necessary)
158		var theTable = dom.getParent(tr_elm, "table");
159		var dest = rowtype;
160		var newParent = null;
161		for (var i = 0; i < theTable.childNodes.length; i++) {
162			if (theTable.childNodes[i].nodeName.toLowerCase() == dest)
163				newParent = theTable.childNodes[i];
164		}
165
166		if (newParent == null) {
167			newParent = doc.createElement(dest);
168
169			if (theTable.firstChild.nodeName == 'CAPTION')
170				inst.dom.insertAfter(newParent, theTable.firstChild);
171			else
172				theTable.insertBefore(newParent, theTable.firstChild);
173		}
174
175		// append the row to the new parent
176		newParent.appendChild(newRow);
177
178		// remove the original
179		tr_elm.parentNode.removeChild(tr_elm);
180
181		// set tr_elm to the new node
182		tr_elm = newRow;
183	}
184
185	dom.setAttrib(tr_elm, 'style', dom.serializeStyle(dom.parseStyle(tr_elm.style.cssText)));
186}
187
188function changedBackgroundImage() {
189	var formObj = document.forms[0], dom = tinyMCEPopup.editor.dom;
190	var st = dom.parseStyle(formObj.style.value);
191
192	st['background-image'] = "url('" + formObj.backgroundimage.value + "')";
193
194	formObj.style.value = dom.serializeStyle(st);
195}
196
197function changedStyle() {
198	var formObj = document.forms[0], dom = tinyMCEPopup.editor.dom;
199	var st = dom.parseStyle(formObj.style.value);
200
201	if (st['background-image'])
202		formObj.backgroundimage.value = st['background-image'].replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");
203	else
204		formObj.backgroundimage.value = '';
205
206	if (st['height'])
207		formObj.height.value = trimSize(st['height']);
208
209	if (st['background-color']) {
210		formObj.bgcolor.value = st['background-color'];
211		updateColor('bgcolor_pick','bgcolor');
212	}
213}
214
215function changedSize() {
216	var formObj = document.forms[0], dom = tinyMCEPopup.editor.dom;
217	var st = dom.parseStyle(formObj.style.value);
218
219	var height = formObj.height.value;
220	if (height != "")
221		st['height'] = getCSSSize(height);
222	else
223		st['height'] = "";
224
225	formObj.style.value = dom.serializeStyle(st);
226}
227
228function changedColor() {
229	var formObj = document.forms[0], dom = tinyMCEPopup.editor.dom;
230	var st = dom.parseStyle(formObj.style.value);
231
232	st['background-color'] = formObj.bgcolor.value;
233
234	formObj.style.value = dom.serializeStyle(st);
235}
236
237tinyMCEPopup.onInit.add(init);