props.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. tinyMCEPopup.requireLangPack();
  2. var defaultFonts = "" +
  3. "Arial, Helvetica, sans-serif=Arial, Helvetica, sans-serif;" +
  4. "Times New Roman, Times, serif=Times New Roman, Times, serif;" +
  5. "Courier New, Courier, mono=Courier New, Courier, mono;" +
  6. "Times New Roman, Times, serif=Times New Roman, Times, serif;" +
  7. "Georgia, Times New Roman, Times, serif=Georgia, Times New Roman, Times, serif;" +
  8. "Verdana, Arial, Helvetica, sans-serif=Verdana, Arial, Helvetica, sans-serif;" +
  9. "Geneva, Arial, Helvetica, sans-serif=Geneva, Arial, Helvetica, sans-serif";
  10. var defaultSizes = "9;10;12;14;16;18;24;xx-small;x-small;small;medium;large;x-large;xx-large;smaller;larger";
  11. var defaultMeasurement = "+pixels=px;points=pt;inches=in;centimetres=cm;millimetres=mm;picas=pc;ems=em;exs=ex;%";
  12. var defaultSpacingMeasurement = "pixels=px;points=pt;inches=in;centimetres=cm;millimetres=mm;picas=pc;+ems=em;exs=ex;%";
  13. var defaultIndentMeasurement = "pixels=px;+points=pt;inches=in;centimetres=cm;millimetres=mm;picas=pc;ems=em;exs=ex;%";
  14. var defaultWeight = "normal;bold;bolder;lighter;100;200;300;400;500;600;700;800;900";
  15. var defaultTextStyle = "normal;italic;oblique";
  16. var defaultVariant = "normal;small-caps";
  17. var defaultLineHeight = "normal";
  18. var defaultAttachment = "fixed;scroll";
  19. var defaultRepeat = "no-repeat;repeat;repeat-x;repeat-y";
  20. var defaultPosH = "left;center;right";
  21. var defaultPosV = "top;center;bottom";
  22. var defaultVAlign = "baseline;sub;super;top;text-top;middle;bottom;text-bottom";
  23. var defaultDisplay = "inline;block;list-item;run-in;compact;marker;table;inline-table;table-row-group;table-header-group;table-footer-group;table-row;table-column-group;table-column;table-cell;table-caption;none";
  24. var defaultBorderStyle = "none;solid;dashed;dotted;double;groove;ridge;inset;outset";
  25. var defaultBorderWidth = "thin;medium;thick";
  26. var defaultListType = "disc;circle;square;decimal;lower-roman;upper-roman;lower-alpha;upper-alpha;none";
  27. function aggregateStyles(allStyles) {
  28. var mergedStyles = {};
  29. tinymce.each(allStyles, function(style) {
  30. if (style !== '') {
  31. var parsedStyles = tinyMCEPopup.editor.dom.parseStyle(style);
  32. for (var name in parsedStyles) {
  33. if (parsedStyles.hasOwnProperty(name)) {
  34. if (mergedStyles[name] === undefined) {
  35. mergedStyles[name] = parsedStyles[name];
  36. }
  37. else if (name === 'text-decoration') {
  38. if (mergedStyles[name].indexOf(parsedStyles[name]) === -1) {
  39. mergedStyles[name] = mergedStyles[name] +' '+ parsedStyles[name];
  40. }
  41. }
  42. }
  43. }
  44. }
  45. });
  46. return mergedStyles;
  47. }
  48. var applyActionIsInsert;
  49. var existingStyles;
  50. function init(ed) {
  51. var ce = document.getElementById('container'), h;
  52. existingStyles = aggregateStyles(tinyMCEPopup.getWindowArg('styles'));
  53. ce.style.cssText = tinyMCEPopup.editor.dom.serializeStyle(existingStyles);
  54. applyActionIsInsert = ed.getParam("edit_css_style_insert_span", false);
  55. document.getElementById('toggle_insert_span').checked = applyActionIsInsert;
  56. h = getBrowserHTML('background_image_browser','background_image','image','advimage');
  57. document.getElementById("background_image_browser").innerHTML = h;
  58. document.getElementById('text_color_pickcontainer').innerHTML = getColorPickerHTML('text_color_pick','text_color');
  59. document.getElementById('background_color_pickcontainer').innerHTML = getColorPickerHTML('background_color_pick','background_color');
  60. document.getElementById('border_color_top_pickcontainer').innerHTML = getColorPickerHTML('border_color_top_pick','border_color_top');
  61. document.getElementById('border_color_right_pickcontainer').innerHTML = getColorPickerHTML('border_color_right_pick','border_color_right');
  62. document.getElementById('border_color_bottom_pickcontainer').innerHTML = getColorPickerHTML('border_color_bottom_pick','border_color_bottom');
  63. document.getElementById('border_color_left_pickcontainer').innerHTML = getColorPickerHTML('border_color_left_pick','border_color_left');
  64. fillSelect(0, 'text_font', 'style_font', defaultFonts, ';', true);
  65. fillSelect(0, 'text_size', 'style_font_size', defaultSizes, ';', true);
  66. fillSelect(0, 'text_size_measurement', 'style_font_size_measurement', defaultMeasurement, ';', true);
  67. fillSelect(0, 'text_case', 'style_text_case', "capitalize;uppercase;lowercase", ';', true);
  68. fillSelect(0, 'text_weight', 'style_font_weight', defaultWeight, ';', true);
  69. fillSelect(0, 'text_style', 'style_font_style', defaultTextStyle, ';', true);
  70. fillSelect(0, 'text_variant', 'style_font_variant', defaultVariant, ';', true);
  71. fillSelect(0, 'text_lineheight', 'style_font_line_height', defaultLineHeight, ';', true);
  72. fillSelect(0, 'text_lineheight_measurement', 'style_font_line_height_measurement', defaultMeasurement, ';', true);
  73. fillSelect(0, 'background_attachment', 'style_background_attachment', defaultAttachment, ';', true);
  74. fillSelect(0, 'background_repeat', 'style_background_repeat', defaultRepeat, ';', true);
  75. fillSelect(0, 'background_hpos_measurement', 'style_background_hpos_measurement', defaultMeasurement, ';', true);
  76. fillSelect(0, 'background_vpos_measurement', 'style_background_vpos_measurement', defaultMeasurement, ';', true);
  77. fillSelect(0, 'background_hpos', 'style_background_hpos', defaultPosH, ';', true);
  78. fillSelect(0, 'background_vpos', 'style_background_vpos', defaultPosV, ';', true);
  79. fillSelect(0, 'block_wordspacing', 'style_wordspacing', 'normal', ';', true);
  80. fillSelect(0, 'block_wordspacing_measurement', 'style_wordspacing_measurement', defaultSpacingMeasurement, ';', true);
  81. fillSelect(0, 'block_letterspacing', 'style_letterspacing', 'normal', ';', true);
  82. fillSelect(0, 'block_letterspacing_measurement', 'style_letterspacing_measurement', defaultSpacingMeasurement, ';', true);
  83. fillSelect(0, 'block_vertical_alignment', 'style_vertical_alignment', defaultVAlign, ';', true);
  84. fillSelect(0, 'block_text_align', 'style_text_align', "left;right;center;justify", ';', true);
  85. fillSelect(0, 'block_whitespace', 'style_whitespace', "normal;pre;nowrap", ';', true);
  86. fillSelect(0, 'block_display', 'style_display', defaultDisplay, ';', true);
  87. fillSelect(0, 'block_text_indent_measurement', 'style_text_indent_measurement', defaultIndentMeasurement, ';', true);
  88. fillSelect(0, 'box_width_measurement', 'style_box_width_measurement', defaultMeasurement, ';', true);
  89. fillSelect(0, 'box_height_measurement', 'style_box_height_measurement', defaultMeasurement, ';', true);
  90. fillSelect(0, 'box_float', 'style_float', 'left;right;none', ';', true);
  91. fillSelect(0, 'box_clear', 'style_clear', 'left;right;both;none', ';', true);
  92. fillSelect(0, 'box_padding_left_measurement', 'style_padding_left_measurement', defaultMeasurement, ';', true);
  93. fillSelect(0, 'box_padding_top_measurement', 'style_padding_top_measurement', defaultMeasurement, ';', true);
  94. fillSelect(0, 'box_padding_bottom_measurement', 'style_padding_bottom_measurement', defaultMeasurement, ';', true);
  95. fillSelect(0, 'box_padding_right_measurement', 'style_padding_right_measurement', defaultMeasurement, ';', true);
  96. fillSelect(0, 'box_margin_left_measurement', 'style_margin_left_measurement', defaultMeasurement, ';', true);
  97. fillSelect(0, 'box_margin_top_measurement', 'style_margin_top_measurement', defaultMeasurement, ';', true);
  98. fillSelect(0, 'box_margin_bottom_measurement', 'style_margin_bottom_measurement', defaultMeasurement, ';', true);
  99. fillSelect(0, 'box_margin_right_measurement', 'style_margin_right_measurement', defaultMeasurement, ';', true);
  100. fillSelect(0, 'border_style_top', 'style_border_style_top', defaultBorderStyle, ';', true);
  101. fillSelect(0, 'border_style_right', 'style_border_style_right', defaultBorderStyle, ';', true);
  102. fillSelect(0, 'border_style_bottom', 'style_border_style_bottom', defaultBorderStyle, ';', true);
  103. fillSelect(0, 'border_style_left', 'style_border_style_left', defaultBorderStyle, ';', true);
  104. fillSelect(0, 'border_width_top', 'style_border_width_top', defaultBorderWidth, ';', true);
  105. fillSelect(0, 'border_width_right', 'style_border_width_right', defaultBorderWidth, ';', true);
  106. fillSelect(0, 'border_width_bottom', 'style_border_width_bottom', defaultBorderWidth, ';', true);
  107. fillSelect(0, 'border_width_left', 'style_border_width_left', defaultBorderWidth, ';', true);
  108. fillSelect(0, 'border_width_top_measurement', 'style_border_width_top_measurement', defaultMeasurement, ';', true);
  109. fillSelect(0, 'border_width_right_measurement', 'style_border_width_right_measurement', defaultMeasurement, ';', true);
  110. fillSelect(0, 'border_width_bottom_measurement', 'style_border_width_bottom_measurement', defaultMeasurement, ';', true);
  111. fillSelect(0, 'border_width_left_measurement', 'style_border_width_left_measurement', defaultMeasurement, ';', true);
  112. fillSelect(0, 'list_type', 'style_list_type', defaultListType, ';', true);
  113. fillSelect(0, 'list_position', 'style_list_position', "inside;outside", ';', true);
  114. fillSelect(0, 'positioning_type', 'style_positioning_type', "absolute;relative;static", ';', true);
  115. fillSelect(0, 'positioning_visibility', 'style_positioning_visibility', "inherit;visible;hidden", ';', true);
  116. fillSelect(0, 'positioning_width_measurement', 'style_positioning_width_measurement', defaultMeasurement, ';', true);
  117. fillSelect(0, 'positioning_height_measurement', 'style_positioning_height_measurement', defaultMeasurement, ';', true);
  118. fillSelect(0, 'positioning_overflow', 'style_positioning_overflow', "visible;hidden;scroll;auto", ';', true);
  119. fillSelect(0, 'positioning_placement_top_measurement', 'style_positioning_placement_top_measurement', defaultMeasurement, ';', true);
  120. fillSelect(0, 'positioning_placement_right_measurement', 'style_positioning_placement_right_measurement', defaultMeasurement, ';', true);
  121. fillSelect(0, 'positioning_placement_bottom_measurement', 'style_positioning_placement_bottom_measurement', defaultMeasurement, ';', true);
  122. fillSelect(0, 'positioning_placement_left_measurement', 'style_positioning_placement_left_measurement', defaultMeasurement, ';', true);
  123. fillSelect(0, 'positioning_clip_top_measurement', 'style_positioning_clip_top_measurement', defaultMeasurement, ';', true);
  124. fillSelect(0, 'positioning_clip_right_measurement', 'style_positioning_clip_right_measurement', defaultMeasurement, ';', true);
  125. fillSelect(0, 'positioning_clip_bottom_measurement', 'style_positioning_clip_bottom_measurement', defaultMeasurement, ';', true);
  126. fillSelect(0, 'positioning_clip_left_measurement', 'style_positioning_clip_left_measurement', defaultMeasurement, ';', true);
  127. TinyMCE_EditableSelects.init();
  128. setupFormData();
  129. showDisabledControls();
  130. }
  131. function setupFormData() {
  132. var ce = document.getElementById('container'), f = document.forms[0], s, b, i;
  133. // Setup text fields
  134. selectByValue(f, 'text_font', ce.style.fontFamily, true, true);
  135. selectByValue(f, 'text_size', getNum(ce.style.fontSize), true, true);
  136. selectByValue(f, 'text_size_measurement', getMeasurement(ce.style.fontSize));
  137. selectByValue(f, 'text_weight', ce.style.fontWeight, true, true);
  138. selectByValue(f, 'text_style', ce.style.fontStyle, true, true);
  139. selectByValue(f, 'text_lineheight', getNum(ce.style.lineHeight), true, true);
  140. selectByValue(f, 'text_lineheight_measurement', getMeasurement(ce.style.lineHeight));
  141. selectByValue(f, 'text_case', ce.style.textTransform, true, true);
  142. selectByValue(f, 'text_variant', ce.style.fontVariant, true, true);
  143. f.text_color.value = tinyMCEPopup.editor.dom.toHex(ce.style.color);
  144. updateColor('text_color_pick', 'text_color');
  145. f.text_underline.checked = inStr(ce.style.textDecoration, 'underline');
  146. f.text_overline.checked = inStr(ce.style.textDecoration, 'overline');
  147. f.text_linethrough.checked = inStr(ce.style.textDecoration, 'line-through');
  148. f.text_blink.checked = inStr(ce.style.textDecoration, 'blink');
  149. f.text_none.checked = inStr(ce.style.textDecoration, 'none');
  150. updateTextDecorations();
  151. // Setup background fields
  152. f.background_color.value = tinyMCEPopup.editor.dom.toHex(ce.style.backgroundColor);
  153. updateColor('background_color_pick', 'background_color');
  154. f.background_image.value = ce.style.backgroundImage.replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");
  155. selectByValue(f, 'background_repeat', ce.style.backgroundRepeat, true, true);
  156. selectByValue(f, 'background_attachment', ce.style.backgroundAttachment, true, true);
  157. selectByValue(f, 'background_hpos', getNum(getVal(ce.style.backgroundPosition, 0)), true, true);
  158. selectByValue(f, 'background_hpos_measurement', getMeasurement(getVal(ce.style.backgroundPosition, 0)));
  159. selectByValue(f, 'background_vpos', getNum(getVal(ce.style.backgroundPosition, 1)), true, true);
  160. selectByValue(f, 'background_vpos_measurement', getMeasurement(getVal(ce.style.backgroundPosition, 1)));
  161. // Setup block fields
  162. selectByValue(f, 'block_wordspacing', getNum(ce.style.wordSpacing), true, true);
  163. selectByValue(f, 'block_wordspacing_measurement', getMeasurement(ce.style.wordSpacing));
  164. selectByValue(f, 'block_letterspacing', getNum(ce.style.letterSpacing), true, true);
  165. selectByValue(f, 'block_letterspacing_measurement', getMeasurement(ce.style.letterSpacing));
  166. selectByValue(f, 'block_vertical_alignment', ce.style.verticalAlign, true, true);
  167. selectByValue(f, 'block_text_align', ce.style.textAlign, true, true);
  168. f.block_text_indent.value = getNum(ce.style.textIndent);
  169. selectByValue(f, 'block_text_indent_measurement', getMeasurement(ce.style.textIndent));
  170. selectByValue(f, 'block_whitespace', ce.style.whiteSpace, true, true);
  171. selectByValue(f, 'block_display', ce.style.display, true, true);
  172. // Setup box fields
  173. f.box_width.value = getNum(ce.style.width);
  174. selectByValue(f, 'box_width_measurement', getMeasurement(ce.style.width));
  175. f.box_height.value = getNum(ce.style.height);
  176. selectByValue(f, 'box_height_measurement', getMeasurement(ce.style.height));
  177. selectByValue(f, 'box_float', ce.style.cssFloat || ce.style.styleFloat, true, true);
  178. selectByValue(f, 'box_clear', ce.style.clear, true, true);
  179. setupBox(f, ce, 'box_padding', 'padding', '');
  180. setupBox(f, ce, 'box_margin', 'margin', '');
  181. // Setup border fields
  182. setupBox(f, ce, 'border_style', 'border', 'Style');
  183. setupBox(f, ce, 'border_width', 'border', 'Width');
  184. setupBox(f, ce, 'border_color', 'border', 'Color');
  185. updateColor('border_color_top_pick', 'border_color_top');
  186. updateColor('border_color_right_pick', 'border_color_right');
  187. updateColor('border_color_bottom_pick', 'border_color_bottom');
  188. updateColor('border_color_left_pick', 'border_color_left');
  189. f.elements.border_color_top.value = tinyMCEPopup.editor.dom.toHex(f.elements.border_color_top.value);
  190. f.elements.border_color_right.value = tinyMCEPopup.editor.dom.toHex(f.elements.border_color_right.value);
  191. f.elements.border_color_bottom.value = tinyMCEPopup.editor.dom.toHex(f.elements.border_color_bottom.value);
  192. f.elements.border_color_left.value = tinyMCEPopup.editor.dom.toHex(f.elements.border_color_left.value);
  193. // Setup list fields
  194. selectByValue(f, 'list_type', ce.style.listStyleType, true, true);
  195. selectByValue(f, 'list_position', ce.style.listStylePosition, true, true);
  196. f.list_bullet_image.value = ce.style.listStyleImage.replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");
  197. // Setup box fields
  198. selectByValue(f, 'positioning_type', ce.style.position, true, true);
  199. selectByValue(f, 'positioning_visibility', ce.style.visibility, true, true);
  200. selectByValue(f, 'positioning_overflow', ce.style.overflow, true, true);
  201. f.positioning_zindex.value = ce.style.zIndex ? ce.style.zIndex : "";
  202. f.positioning_width.value = getNum(ce.style.width);
  203. selectByValue(f, 'positioning_width_measurement', getMeasurement(ce.style.width));
  204. f.positioning_height.value = getNum(ce.style.height);
  205. selectByValue(f, 'positioning_height_measurement', getMeasurement(ce.style.height));
  206. setupBox(f, ce, 'positioning_placement', '', '', ['top', 'right', 'bottom', 'left']);
  207. s = ce.style.clip.replace(new RegExp("rect\\('?([^']*)'?\\)", 'gi'), "$1");
  208. s = s.replace(/,/g, ' ');
  209. if (!hasEqualValues([getVal(s, 0), getVal(s, 1), getVal(s, 2), getVal(s, 3)])) {
  210. f.positioning_clip_top.value = getNum(getVal(s, 0));
  211. selectByValue(f, 'positioning_clip_top_measurement', getMeasurement(getVal(s, 0)));
  212. f.positioning_clip_right.value = getNum(getVal(s, 1));
  213. selectByValue(f, 'positioning_clip_right_measurement', getMeasurement(getVal(s, 1)));
  214. f.positioning_clip_bottom.value = getNum(getVal(s, 2));
  215. selectByValue(f, 'positioning_clip_bottom_measurement', getMeasurement(getVal(s, 2)));
  216. f.positioning_clip_left.value = getNum(getVal(s, 3));
  217. selectByValue(f, 'positioning_clip_left_measurement', getMeasurement(getVal(s, 3)));
  218. } else {
  219. f.positioning_clip_top.value = getNum(getVal(s, 0));
  220. selectByValue(f, 'positioning_clip_top_measurement', getMeasurement(getVal(s, 0)));
  221. f.positioning_clip_right.value = f.positioning_clip_bottom.value = f.positioning_clip_left.value;
  222. }
  223. // setupBox(f, ce, '', 'border', 'Color');
  224. }
  225. function getMeasurement(s) {
  226. return s.replace(/^([0-9.]+)(.*)$/, "$2");
  227. }
  228. function getNum(s) {
  229. if (new RegExp('^(?:[0-9.]+)(?:[a-z%]+)$', 'gi').test(s))
  230. return s.replace(/[^0-9.]/g, '');
  231. return s;
  232. }
  233. function inStr(s, n) {
  234. return new RegExp(n, 'gi').test(s);
  235. }
  236. function getVal(s, i) {
  237. var a = s.split(' ');
  238. if (a.length > 1)
  239. return a[i];
  240. return "";
  241. }
  242. function setValue(f, n, v) {
  243. if (f.elements[n].type == "text")
  244. f.elements[n].value = v;
  245. else
  246. selectByValue(f, n, v, true, true);
  247. }
  248. function setupBox(f, ce, fp, pr, sf, b) {
  249. if (typeof(b) == "undefined")
  250. b = ['Top', 'Right', 'Bottom', 'Left'];
  251. if (isSame(ce, pr, sf, b)) {
  252. f.elements[fp + "_same"].checked = true;
  253. setValue(f, fp + "_top", getNum(ce.style[pr + b[0] + sf]));
  254. f.elements[fp + "_top"].disabled = false;
  255. f.elements[fp + "_right"].value = "";
  256. f.elements[fp + "_right"].disabled = true;
  257. f.elements[fp + "_bottom"].value = "";
  258. f.elements[fp + "_bottom"].disabled = true;
  259. f.elements[fp + "_left"].value = "";
  260. f.elements[fp + "_left"].disabled = true;
  261. if (f.elements[fp + "_top_measurement"]) {
  262. selectByValue(f, fp + '_top_measurement', getMeasurement(ce.style[pr + b[0] + sf]));
  263. f.elements[fp + "_left_measurement"].disabled = true;
  264. f.elements[fp + "_bottom_measurement"].disabled = true;
  265. f.elements[fp + "_right_measurement"].disabled = true;
  266. }
  267. } else {
  268. f.elements[fp + "_same"].checked = false;
  269. setValue(f, fp + "_top", getNum(ce.style[pr + b[0] + sf]));
  270. f.elements[fp + "_top"].disabled = false;
  271. setValue(f, fp + "_right", getNum(ce.style[pr + b[1] + sf]));
  272. f.elements[fp + "_right"].disabled = false;
  273. setValue(f, fp + "_bottom", getNum(ce.style[pr + b[2] + sf]));
  274. f.elements[fp + "_bottom"].disabled = false;
  275. setValue(f, fp + "_left", getNum(ce.style[pr + b[3] + sf]));
  276. f.elements[fp + "_left"].disabled = false;
  277. if (f.elements[fp + "_top_measurement"]) {
  278. selectByValue(f, fp + '_top_measurement', getMeasurement(ce.style[pr + b[0] + sf]));
  279. selectByValue(f, fp + '_right_measurement', getMeasurement(ce.style[pr + b[1] + sf]));
  280. selectByValue(f, fp + '_bottom_measurement', getMeasurement(ce.style[pr + b[2] + sf]));
  281. selectByValue(f, fp + '_left_measurement', getMeasurement(ce.style[pr + b[3] + sf]));
  282. f.elements[fp + "_left_measurement"].disabled = false;
  283. f.elements[fp + "_bottom_measurement"].disabled = false;
  284. f.elements[fp + "_right_measurement"].disabled = false;
  285. }
  286. }
  287. }
  288. function isSame(e, pr, sf, b) {
  289. var a = [], i, x;
  290. if (typeof(b) == "undefined")
  291. b = ['Top', 'Right', 'Bottom', 'Left'];
  292. if (typeof(sf) == "undefined" || sf == null)
  293. sf = "";
  294. a[0] = e.style[pr + b[0] + sf];
  295. a[1] = e.style[pr + b[1] + sf];
  296. a[2] = e.style[pr + b[2] + sf];
  297. a[3] = e.style[pr + b[3] + sf];
  298. for (i=0; i<a.length; i++) {
  299. if (a[i] == null)
  300. return false;
  301. for (x=0; x<a.length; x++) {
  302. if (a[x] != a[i])
  303. return false;
  304. }
  305. }
  306. return true;
  307. };
  308. function hasEqualValues(a) {
  309. var i, x;
  310. for (i=0; i<a.length; i++) {
  311. if (a[i] == null)
  312. return false;
  313. for (x=0; x<a.length; x++) {
  314. if (a[x] != a[i])
  315. return false;
  316. }
  317. }
  318. return true;
  319. }
  320. function toggleApplyAction() {
  321. applyActionIsInsert = ! applyActionIsInsert;
  322. }
  323. function applyAction() {
  324. var ce = document.getElementById('container'), ed = tinyMCEPopup.editor;
  325. generateCSS();
  326. tinyMCEPopup.restoreSelection();
  327. var newStyles = tinyMCEPopup.editor.dom.parseStyle(ce.style.cssText);
  328. if (applyActionIsInsert) {
  329. ed.formatter.register('plugin_style', {
  330. inline: 'span', styles: existingStyles
  331. });
  332. ed.formatter.remove('plugin_style');
  333. ed.formatter.register('plugin_style', {
  334. inline: 'span', styles: newStyles
  335. });
  336. ed.formatter.apply('plugin_style');
  337. } else {
  338. var nodes;
  339. if (tinyMCEPopup.getWindowArg('applyStyleToBlocks')) {
  340. nodes = ed.selection.getSelectedBlocks();
  341. }
  342. else {
  343. nodes = ed.selection.getNode();
  344. }
  345. ed.dom.setAttrib(nodes, 'style', tinyMCEPopup.editor.dom.serializeStyle(newStyles));
  346. }
  347. }
  348. function updateAction() {
  349. applyAction();
  350. tinyMCEPopup.close();
  351. }
  352. function generateCSS() {
  353. var ce = document.getElementById('container'), f = document.forms[0], num = new RegExp('[0-9]+', 'g'), s, t;
  354. ce.style.cssText = "";
  355. // Build text styles
  356. ce.style.fontFamily = f.text_font.value;
  357. ce.style.fontSize = f.text_size.value + (isNum(f.text_size.value) ? (f.text_size_measurement.value || 'px') : "");
  358. ce.style.fontStyle = f.text_style.value;
  359. ce.style.lineHeight = f.text_lineheight.value + (isNum(f.text_lineheight.value) ? f.text_lineheight_measurement.value : "");
  360. ce.style.textTransform = f.text_case.value;
  361. ce.style.fontWeight = f.text_weight.value;
  362. ce.style.fontVariant = f.text_variant.value;
  363. ce.style.color = f.text_color.value;
  364. s = "";
  365. s += f.text_underline.checked ? " underline" : "";
  366. s += f.text_overline.checked ? " overline" : "";
  367. s += f.text_linethrough.checked ? " line-through" : "";
  368. s += f.text_blink.checked ? " blink" : "";
  369. s = s.length > 0 ? s.substring(1) : s;
  370. if (f.text_none.checked)
  371. s = "none";
  372. ce.style.textDecoration = s;
  373. // Build background styles
  374. ce.style.backgroundColor = f.background_color.value;
  375. ce.style.backgroundImage = f.background_image.value != "" ? "url(" + f.background_image.value + ")" : "";
  376. ce.style.backgroundRepeat = f.background_repeat.value;
  377. ce.style.backgroundAttachment = f.background_attachment.value;
  378. if (f.background_hpos.value != "") {
  379. s = "";
  380. s += f.background_hpos.value + (isNum(f.background_hpos.value) ? f.background_hpos_measurement.value : "") + " ";
  381. s += f.background_vpos.value + (isNum(f.background_vpos.value) ? f.background_vpos_measurement.value : "");
  382. ce.style.backgroundPosition = s;
  383. }
  384. // Build block styles
  385. ce.style.wordSpacing = f.block_wordspacing.value + (isNum(f.block_wordspacing.value) ? f.block_wordspacing_measurement.value : "");
  386. ce.style.letterSpacing = f.block_letterspacing.value + (isNum(f.block_letterspacing.value) ? f.block_letterspacing_measurement.value : "");
  387. ce.style.verticalAlign = f.block_vertical_alignment.value;
  388. ce.style.textAlign = f.block_text_align.value;
  389. ce.style.textIndent = f.block_text_indent.value + (isNum(f.block_text_indent.value) ? f.block_text_indent_measurement.value : "");
  390. ce.style.whiteSpace = f.block_whitespace.value;
  391. ce.style.display = f.block_display.value;
  392. // Build box styles
  393. ce.style.width = f.box_width.value + (isNum(f.box_width.value) ? f.box_width_measurement.value : "");
  394. ce.style.height = f.box_height.value + (isNum(f.box_height.value) ? f.box_height_measurement.value : "");
  395. ce.style.styleFloat = f.box_float.value;
  396. ce.style.cssFloat = f.box_float.value;
  397. ce.style.clear = f.box_clear.value;
  398. if (!f.box_padding_same.checked) {
  399. ce.style.paddingTop = f.box_padding_top.value + (isNum(f.box_padding_top.value) ? f.box_padding_top_measurement.value : "");
  400. ce.style.paddingRight = f.box_padding_right.value + (isNum(f.box_padding_right.value) ? f.box_padding_right_measurement.value : "");
  401. ce.style.paddingBottom = f.box_padding_bottom.value + (isNum(f.box_padding_bottom.value) ? f.box_padding_bottom_measurement.value : "");
  402. ce.style.paddingLeft = f.box_padding_left.value + (isNum(f.box_padding_left.value) ? f.box_padding_left_measurement.value : "");
  403. } else
  404. ce.style.padding = f.box_padding_top.value + (isNum(f.box_padding_top.value) ? f.box_padding_top_measurement.value : "");
  405. if (!f.box_margin_same.checked) {
  406. ce.style.marginTop = f.box_margin_top.value + (isNum(f.box_margin_top.value) ? f.box_margin_top_measurement.value : "");
  407. ce.style.marginRight = f.box_margin_right.value + (isNum(f.box_margin_right.value) ? f.box_margin_right_measurement.value : "");
  408. ce.style.marginBottom = f.box_margin_bottom.value + (isNum(f.box_margin_bottom.value) ? f.box_margin_bottom_measurement.value : "");
  409. ce.style.marginLeft = f.box_margin_left.value + (isNum(f.box_margin_left.value) ? f.box_margin_left_measurement.value : "");
  410. } else
  411. ce.style.margin = f.box_margin_top.value + (isNum(f.box_margin_top.value) ? f.box_margin_top_measurement.value : "");
  412. // Build border styles
  413. if (!f.border_style_same.checked) {
  414. ce.style.borderTopStyle = f.border_style_top.value;
  415. ce.style.borderRightStyle = f.border_style_right.value;
  416. ce.style.borderBottomStyle = f.border_style_bottom.value;
  417. ce.style.borderLeftStyle = f.border_style_left.value;
  418. } else
  419. ce.style.borderStyle = f.border_style_top.value;
  420. if (!f.border_width_same.checked) {
  421. ce.style.borderTopWidth = f.border_width_top.value + (isNum(f.border_width_top.value) ? f.border_width_top_measurement.value : "");
  422. ce.style.borderRightWidth = f.border_width_right.value + (isNum(f.border_width_right.value) ? f.border_width_right_measurement.value : "");
  423. ce.style.borderBottomWidth = f.border_width_bottom.value + (isNum(f.border_width_bottom.value) ? f.border_width_bottom_measurement.value : "");
  424. ce.style.borderLeftWidth = f.border_width_left.value + (isNum(f.border_width_left.value) ? f.border_width_left_measurement.value : "");
  425. } else
  426. ce.style.borderWidth = f.border_width_top.value + (isNum(f.border_width_top.value) ? f.border_width_top_measurement.value : "");
  427. if (!f.border_color_same.checked) {
  428. ce.style.borderTopColor = f.border_color_top.value;
  429. ce.style.borderRightColor = f.border_color_right.value;
  430. ce.style.borderBottomColor = f.border_color_bottom.value;
  431. ce.style.borderLeftColor = f.border_color_left.value;
  432. } else
  433. ce.style.borderColor = f.border_color_top.value;
  434. // Build list styles
  435. ce.style.listStyleType = f.list_type.value;
  436. ce.style.listStylePosition = f.list_position.value;
  437. ce.style.listStyleImage = f.list_bullet_image.value != "" ? "url(" + f.list_bullet_image.value + ")" : "";
  438. // Build positioning styles
  439. ce.style.position = f.positioning_type.value;
  440. ce.style.visibility = f.positioning_visibility.value;
  441. if (ce.style.width == "")
  442. ce.style.width = f.positioning_width.value + (isNum(f.positioning_width.value) ? f.positioning_width_measurement.value : "");
  443. if (ce.style.height == "")
  444. ce.style.height = f.positioning_height.value + (isNum(f.positioning_height.value) ? f.positioning_height_measurement.value : "");
  445. ce.style.zIndex = f.positioning_zindex.value;
  446. ce.style.overflow = f.positioning_overflow.value;
  447. if (!f.positioning_placement_same.checked) {
  448. ce.style.top = f.positioning_placement_top.value + (isNum(f.positioning_placement_top.value) ? f.positioning_placement_top_measurement.value : "");
  449. ce.style.right = f.positioning_placement_right.value + (isNum(f.positioning_placement_right.value) ? f.positioning_placement_right_measurement.value : "");
  450. ce.style.bottom = f.positioning_placement_bottom.value + (isNum(f.positioning_placement_bottom.value) ? f.positioning_placement_bottom_measurement.value : "");
  451. ce.style.left = f.positioning_placement_left.value + (isNum(f.positioning_placement_left.value) ? f.positioning_placement_left_measurement.value : "");
  452. } else {
  453. s = f.positioning_placement_top.value + (isNum(f.positioning_placement_top.value) ? f.positioning_placement_top_measurement.value : "");
  454. ce.style.top = s;
  455. ce.style.right = s;
  456. ce.style.bottom = s;
  457. ce.style.left = s;
  458. }
  459. if (!f.positioning_clip_same.checked) {
  460. s = "rect(";
  461. s += (isNum(f.positioning_clip_top.value) ? f.positioning_clip_top.value + f.positioning_clip_top_measurement.value : "auto") + " ";
  462. s += (isNum(f.positioning_clip_right.value) ? f.positioning_clip_right.value + f.positioning_clip_right_measurement.value : "auto") + " ";
  463. s += (isNum(f.positioning_clip_bottom.value) ? f.positioning_clip_bottom.value + f.positioning_clip_bottom_measurement.value : "auto") + " ";
  464. s += (isNum(f.positioning_clip_left.value) ? f.positioning_clip_left.value + f.positioning_clip_left_measurement.value : "auto");
  465. s += ")";
  466. if (s != "rect(auto auto auto auto)")
  467. ce.style.clip = s;
  468. } else {
  469. s = "rect(";
  470. t = isNum(f.positioning_clip_top.value) ? f.positioning_clip_top.value + f.positioning_clip_top_measurement.value : "auto";
  471. s += t + " ";
  472. s += t + " ";
  473. s += t + " ";
  474. s += t + ")";
  475. if (s != "rect(auto auto auto auto)")
  476. ce.style.clip = s;
  477. }
  478. ce.style.cssText = ce.style.cssText;
  479. }
  480. function isNum(s) {
  481. return new RegExp('[0-9]+', 'g').test(s);
  482. }
  483. function showDisabledControls() {
  484. var f = document.forms, i, a;
  485. for (i=0; i<f.length; i++) {
  486. for (a=0; a<f[i].elements.length; a++) {
  487. if (f[i].elements[a].disabled)
  488. tinyMCEPopup.editor.dom.addClass(f[i].elements[a], "disabled");
  489. else
  490. tinyMCEPopup.editor.dom.removeClass(f[i].elements[a], "disabled");
  491. }
  492. }
  493. }
  494. function fillSelect(f, s, param, dval, sep, em) {
  495. var i, ar, p, se;
  496. f = document.forms[f];
  497. sep = typeof(sep) == "undefined" ? ";" : sep;
  498. if (em)
  499. addSelectValue(f, s, "", "");
  500. ar = tinyMCEPopup.getParam(param, dval).split(sep);
  501. for (i=0; i<ar.length; i++) {
  502. se = false;
  503. if (ar[i].charAt(0) == '+') {
  504. ar[i] = ar[i].substring(1);
  505. se = true;
  506. }
  507. p = ar[i].split('=');
  508. if (p.length > 1) {
  509. addSelectValue(f, s, p[0], p[1]);
  510. if (se)
  511. selectByValue(f, s, p[1]);
  512. } else {
  513. addSelectValue(f, s, p[0], p[0]);
  514. if (se)
  515. selectByValue(f, s, p[0]);
  516. }
  517. }
  518. }
  519. function toggleSame(ce, pre) {
  520. var el = document.forms[0].elements, i;
  521. if (ce.checked) {
  522. el[pre + "_top"].disabled = false;
  523. el[pre + "_right"].disabled = true;
  524. el[pre + "_bottom"].disabled = true;
  525. el[pre + "_left"].disabled = true;
  526. if (el[pre + "_top_measurement"]) {
  527. el[pre + "_top_measurement"].disabled = false;
  528. el[pre + "_right_measurement"].disabled = true;
  529. el[pre + "_bottom_measurement"].disabled = true;
  530. el[pre + "_left_measurement"].disabled = true;
  531. }
  532. } else {
  533. el[pre + "_top"].disabled = false;
  534. el[pre + "_right"].disabled = false;
  535. el[pre + "_bottom"].disabled = false;
  536. el[pre + "_left"].disabled = false;
  537. if (el[pre + "_top_measurement"]) {
  538. el[pre + "_top_measurement"].disabled = false;
  539. el[pre + "_right_measurement"].disabled = false;
  540. el[pre + "_bottom_measurement"].disabled = false;
  541. el[pre + "_left_measurement"].disabled = false;
  542. }
  543. }
  544. showDisabledControls();
  545. }
  546. function synch(fr, to) {
  547. var f = document.forms[0];
  548. f.elements[to].value = f.elements[fr].value;
  549. if (f.elements[fr + "_measurement"])
  550. selectByValue(f, to + "_measurement", f.elements[fr + "_measurement"].value);
  551. }
  552. function updateTextDecorations(){
  553. var el = document.forms[0].elements;
  554. var textDecorations = ["text_underline", "text_overline", "text_linethrough", "text_blink"];
  555. var noneChecked = el["text_none"].checked;
  556. tinymce.each(textDecorations, function(id) {
  557. el[id].disabled = noneChecked;
  558. if (noneChecked) {
  559. el[id].checked = false;
  560. }
  561. });
  562. }
  563. tinyMCEPopup.onInit.add(init);