PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/fullpage/js/fullpage.js

#
JavaScript | 232 lines | 162 code | 50 blank | 20 comment | 39 complexity | a7913b6b1a1ae634a509c3db9faf381a MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. /**
  2. * fullpage.js
  3. *
  4. * Copyright 2009, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://tinymce.moxiecode.com/license
  8. * Contributing: http://tinymce.moxiecode.com/contributing
  9. */
  10. (function() {
  11. tinyMCEPopup.requireLangPack();
  12. var defaultDocTypes =
  13. 'XHTML 1.0 Transitional=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">,' +
  14. 'XHTML 1.0 Frameset=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">,' +
  15. 'XHTML 1.0 Strict=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">,' +
  16. 'XHTML 1.1=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">,' +
  17. 'HTML 4.01 Transitional=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">,' +
  18. 'HTML 4.01 Strict=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">,' +
  19. 'HTML 4.01 Frameset=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">';
  20. var defaultEncodings =
  21. 'Western european (iso-8859-1)=iso-8859-1,' +
  22. 'Central European (iso-8859-2)=iso-8859-2,' +
  23. 'Unicode (UTF-8)=utf-8,' +
  24. 'Chinese traditional (Big5)=big5,' +
  25. 'Cyrillic (iso-8859-5)=iso-8859-5,' +
  26. 'Japanese (iso-2022-jp)=iso-2022-jp,' +
  27. 'Greek (iso-8859-7)=iso-8859-7,' +
  28. 'Korean (iso-2022-kr)=iso-2022-kr,' +
  29. 'ASCII (us-ascii)=us-ascii';
  30. var defaultFontNames = 'Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact;WingDings=wingdings';
  31. var defaultFontSizes = '10px,11px,12px,13px,14px,15px,16px';
  32. function setVal(id, value) {
  33. var elm = document.getElementById(id);
  34. if (elm) {
  35. value = value || '';
  36. if (elm.nodeName == "SELECT")
  37. selectByValue(document.forms[0], id, value);
  38. else if (elm.type == "checkbox")
  39. elm.checked = !!value;
  40. else
  41. elm.value = value;
  42. }
  43. };
  44. function getVal(id) {
  45. var elm = document.getElementById(id);
  46. if (elm.nodeName == "SELECT")
  47. return elm.options[elm.selectedIndex].value;
  48. if (elm.type == "checkbox")
  49. return elm.checked;
  50. return elm.value;
  51. };
  52. window.FullPageDialog = {
  53. changedStyle : function() {
  54. var val, styles = tinyMCEPopup.editor.dom.parseStyle(getVal('style'));
  55. setVal('fontface', styles['font-face']);
  56. setVal('fontsize', styles['font-size']);
  57. setVal('textcolor', styles['color']);
  58. if (val = styles['background-image'])
  59. setVal('bgimage', val.replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1"));
  60. else
  61. setVal('bgimage', '');
  62. setVal('bgcolor', styles['background-color']);
  63. // Reset margin form elements
  64. setVal('topmargin', '');
  65. setVal('rightmargin', '');
  66. setVal('bottommargin', '');
  67. setVal('leftmargin', '');
  68. // Expand margin
  69. if (val = styles['margin']) {
  70. val = val.split(' ');
  71. styles['margin-top'] = val[0] || '';
  72. styles['margin-right'] = val[1] || val[0] || '';
  73. styles['margin-bottom'] = val[2] || val[0] || '';
  74. styles['margin-left'] = val[3] || val[0] || '';
  75. }
  76. if (val = styles['margin-top'])
  77. setVal('topmargin', val.replace(/px/, ''));
  78. if (val = styles['margin-right'])
  79. setVal('rightmargin', val.replace(/px/, ''));
  80. if (val = styles['margin-bottom'])
  81. setVal('bottommargin', val.replace(/px/, ''));
  82. if (val = styles['margin-left'])
  83. setVal('leftmargin', val.replace(/px/, ''));
  84. updateColor('bgcolor_pick', 'bgcolor');
  85. updateColor('textcolor_pick', 'textcolor');
  86. },
  87. changedStyleProp : function() {
  88. var val, dom = tinyMCEPopup.editor.dom, styles = dom.parseStyle(getVal('style'));
  89. styles['font-face'] = getVal('fontface');
  90. styles['font-size'] = getVal('fontsize');
  91. styles['color'] = getVal('textcolor');
  92. styles['background-color'] = getVal('bgcolor');
  93. if (val = getVal('bgimage'))
  94. styles['background-image'] = "url('" + val + "')";
  95. else
  96. styles['background-image'] = '';
  97. delete styles['margin'];
  98. if (val = getVal('topmargin'))
  99. styles['margin-top'] = val + "px";
  100. else
  101. styles['margin-top'] = '';
  102. if (val = getVal('rightmargin'))
  103. styles['margin-right'] = val + "px";
  104. else
  105. styles['margin-right'] = '';
  106. if (val = getVal('bottommargin'))
  107. styles['margin-bottom'] = val + "px";
  108. else
  109. styles['margin-bottom'] = '';
  110. if (val = getVal('leftmargin'))
  111. styles['margin-left'] = val + "px";
  112. else
  113. styles['margin-left'] = '';
  114. // Serialize, parse and reserialize this will compress redundant styles
  115. setVal('style', dom.serializeStyle(dom.parseStyle(dom.serializeStyle(styles))));
  116. this.changedStyle();
  117. },
  118. update : function() {
  119. var data = {};
  120. tinymce.each(tinyMCEPopup.dom.select('select,input,textarea'), function(node) {
  121. data[node.id] = getVal(node.id);
  122. });
  123. tinyMCEPopup.editor.plugins.fullpage._dataToHtml(data);
  124. tinyMCEPopup.close();
  125. }
  126. };
  127. function init() {
  128. var form = document.forms[0], i, item, list, editor = tinyMCEPopup.editor;
  129. // Setup doctype select box
  130. list = editor.getParam("fullpage_doctypes", defaultDocTypes).split(',');
  131. for (i = 0; i < list.length; i++) {
  132. item = list[i].split('=');
  133. if (item.length > 1)
  134. addSelectValue(form, 'doctype', item[0], item[1]);
  135. }
  136. // Setup fonts select box
  137. list = editor.getParam("fullpage_fonts", defaultFontNames).split(';');
  138. for (i = 0; i < list.length; i++) {
  139. item = list[i].split('=');
  140. if (item.length > 1)
  141. addSelectValue(form, 'fontface', item[0], item[1]);
  142. }
  143. // Setup fontsize select box
  144. list = editor.getParam("fullpage_fontsizes", defaultFontSizes).split(',');
  145. for (i = 0; i < list.length; i++)
  146. addSelectValue(form, 'fontsize', list[i], list[i]);
  147. // Setup encodings select box
  148. list = editor.getParam("fullpage_encodings", defaultEncodings).split(',');
  149. for (i = 0; i < list.length; i++) {
  150. item = list[i].split('=');
  151. if (item.length > 1)
  152. addSelectValue(form, 'docencoding', item[0], item[1]);
  153. }
  154. // Setup color pickers
  155. document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor');
  156. document.getElementById('link_color_pickcontainer').innerHTML = getColorPickerHTML('link_color_pick','link_color');
  157. document.getElementById('visited_color_pickcontainer').innerHTML = getColorPickerHTML('visited_color_pick','visited_color');
  158. document.getElementById('active_color_pickcontainer').innerHTML = getColorPickerHTML('active_color_pick','active_color');
  159. document.getElementById('textcolor_pickcontainer').innerHTML = getColorPickerHTML('textcolor_pick','textcolor');
  160. document.getElementById('stylesheet_browsercontainer').innerHTML = getBrowserHTML('stylesheetbrowser','stylesheet','file','fullpage');
  161. document.getElementById('bgimage_pickcontainer').innerHTML = getBrowserHTML('bgimage_browser','bgimage','image','fullpage');
  162. // Resize some elements
  163. if (isVisible('stylesheetbrowser'))
  164. document.getElementById('stylesheet').style.width = '220px';
  165. if (isVisible('link_href_browser'))
  166. document.getElementById('element_link_href').style.width = '230px';
  167. if (isVisible('bgimage_browser'))
  168. document.getElementById('bgimage').style.width = '210px';
  169. // Update form
  170. tinymce.each(tinyMCEPopup.getWindowArg('data'), function(value, key) {
  171. setVal(key, value);
  172. });
  173. FullPageDialog.changedStyle();
  174. // Update colors
  175. updateColor('textcolor_pick', 'textcolor');
  176. updateColor('bgcolor_pick', 'bgcolor');
  177. updateColor('visited_color_pick', 'visited_color');
  178. updateColor('active_color_pick', 'active_color');
  179. updateColor('link_color_pick', 'link_color');
  180. };
  181. tinyMCEPopup.onInit.add(init);
  182. })();