fullpage.js
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:18k
源码类别:

OA系统

开发平台:

Java

  1. //
  2. var defaultDocTypes = 
  3. 'XHTML 1.0 Transitional=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">,' +
  4. 'XHTML 1.0 Frameset=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">,' +
  5. 'XHTML 1.0 Strict=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">,' +
  6. 'XHTML 1.1=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">">,' +
  7. 'HTML 4.01 Transitional=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">,' +
  8. 'HTML 4.01 Strict=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">,' +
  9. 'HTML 4.01 Frameset=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">';
  10. var defaultEncodings = 
  11. 'Western european (iso-8859-1)=iso-8859-1,' +
  12. 'Central European (iso-8859-2)=iso-8859-2,' +
  13. 'Unicode (UTF-8)=utf-8,' +
  14. 'Chinese traditional (Big5)=big5,' +
  15. 'Cyrillic (iso-8859-5)=iso-8859-5,' +
  16. 'Japanese (iso-2022-jp)=iso-2022-jp,' +
  17. 'Greek (iso-8859-7)=iso-8859-7,' +
  18. 'Korean (iso-2022-kr)=iso-2022-kr,' +
  19. 'ASCII (us-ascii)=us-ascii';
  20. var defaultMediaTypes = 
  21. 'all=all,' +
  22. 'screen=screen,' +
  23. 'print=print,' +
  24. 'tty=tty,' +
  25. 'tv=tv,' +
  26. 'projection=projection,' +
  27. 'handheld=handheld,' +
  28. 'braille=braille,' +
  29. 'aural=aural';
  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. var addMenuLayer = new MCLayer("addmenu");
  33. var lastElementType = null;
  34. var topDoc;
  35. function init() {
  36. var f = document.forms['fullpage'];
  37. var i, p, doctypes, encodings, mediaTypes, fonts;
  38. var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
  39. // Setup doctype select box
  40. doctypes = tinyMCE.getParam("fullpage_doctypes", defaultDocTypes).split(',');
  41. for (i=0; i<doctypes.length; i++) {
  42. p = doctypes[i].split('=');
  43. if (p.length > 1)
  44. addSelectValue(f, 'doctypes', p[0], p[1]);
  45. }
  46. // Setup fonts select box
  47. fonts = tinyMCE.getParam("fullpage_fonts", defaultFontNames).split(';');
  48. for (i=0; i<fonts.length; i++) {
  49. p = fonts[i].split('=');
  50. if (p.length > 1)
  51. addSelectValue(f, 'fontface', p[0], p[1]);
  52. }
  53. // Setup fontsize select box
  54. fonts = tinyMCE.getParam("fullpage_fontsizes", defaultFontSizes).split(',');
  55. for (i=0; i<fonts.length; i++)
  56. addSelectValue(f, 'fontsize', fonts[i], fonts[i]);
  57. // Setup mediatype select boxs
  58. mediaTypes = tinyMCE.getParam("fullpage_media_types", defaultMediaTypes).split(',');
  59. for (i=0; i<mediaTypes.length; i++) {
  60. p = mediaTypes[i].split('=');
  61. if (p.length > 1) {
  62. addSelectValue(f, 'element_style_media', p[0], p[1]);
  63. addSelectValue(f, 'element_link_media', p[0], p[1]);
  64. }
  65. }
  66. // Setup encodings select box
  67. encodings = tinyMCE.getParam("fullpage_encodings", defaultEncodings).split(',');
  68. for (i=0; i<encodings.length; i++) {
  69. p = encodings[i].split('=');
  70. if (p.length > 1) {
  71. addSelectValue(f, 'docencoding', p[0], p[1]);
  72. addSelectValue(f, 'element_script_charset', p[0], p[1]);
  73. addSelectValue(f, 'element_link_charset', p[0], p[1]);
  74. }
  75. }
  76. document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor');
  77. document.getElementById('link_color_pickcontainer').innerHTML = getColorPickerHTML('link_color_pick','link_color');
  78. //document.getElementById('hover_color_pickcontainer').innerHTML = getColorPickerHTML('hover_color_pick','hover_color');
  79. document.getElementById('visited_color_pickcontainer').innerHTML = getColorPickerHTML('visited_color_pick','visited_color');
  80. document.getElementById('active_color_pickcontainer').innerHTML = getColorPickerHTML('active_color_pick','active_color');
  81. document.getElementById('textcolor_pickcontainer').innerHTML = getColorPickerHTML('textcolor_pick','textcolor');
  82. document.getElementById('stylesheet_browsercontainer').innerHTML = getBrowserHTML('stylesheetbrowser','stylesheet','file','fullpage');
  83. document.getElementById('link_href_pickcontainer').innerHTML = getBrowserHTML('link_href_browser','element_link_href','file','fullpage');
  84. document.getElementById('script_src_pickcontainer').innerHTML = getBrowserHTML('script_src_browser','element_script_src','file','fullpage');
  85. document.getElementById('bgimage_pickcontainer').innerHTML = getBrowserHTML('bgimage_browser','bgimage','image','fullpage');
  86. // Resize some elements
  87. if (isVisible('stylesheetbrowser'))
  88. document.getElementById('stylesheet').style.width = '220px';
  89. if (isVisible('link_href_browser'))
  90. document.getElementById('element_link_href').style.width = '230px';
  91. if (isVisible('bgimage_browser'))
  92. document.getElementById('bgimage').style.width = '210px';
  93. // Create iframe
  94. var iframe = document.createElement('iframe');
  95. iframe.id = 'tempFrame';
  96. iframe.style.display = 'none';
  97. iframe.src = tinyMCE.baseURL + "/plugins/fullpage/blank.htm";
  98. document.body.appendChild(iframe);
  99. tinyMCEPopup.resizeToInnerSize();
  100. }
  101. function setupIframe(doc) {
  102. var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
  103. var hc = inst.fullpageTopContent;
  104. var f = document.forms[0];
  105. var xmlVer, xmlEnc, docType;
  106. var nodes, i, x, name, value, tmp, l;
  107. // Keep it from not loading/executing stuff
  108. hc = hc.replace(/<script>/gi, '<script type="text/javascript">');
  109. hc = hc.replace(/ssrc=/gi, " mce_src=");
  110. hc = hc.replace(/shref=/gi, " mce_href=");
  111. hc = hc.replace(/stype=/gi, " mce_type=");
  112. hc = hc.replace(/<script/gi, '<script type="text/unknown" ');
  113. // Add end to make it DOM parseable
  114. hc += '</body></html>';
  115. topDoc = doc;
  116. doc.open();
  117. doc.write(hc);
  118. doc.close();
  119. // ------- Setup options for genral tab
  120. // Parse xml and doctype
  121. xmlVer = getReItem(/<?s*?xml.*?versions*?=s*?"(.*?)".*??>/gi, hc, 1);
  122. xmlEnc = getReItem(/<?s*?xml.*?encodings*?=s*?"(.*?)".*??>/gi, hc, 1);
  123. docType = getReItem(/<!DOCTYPE.*?>/gi, hc, 0);
  124. f.langcode.value = getReItem(/lang="(.*?)"/gi, hc, 1);
  125. // Get title
  126. f.metatitle.value = tinyMCE.entityDecode(getReItem(/<title>(.*?)</title>/gi, hc, 1));
  127. // Check for meta encoding
  128. nodes = doc.getElementsByTagName("meta");
  129. for (i=0; i<nodes.length; i++) {
  130. name = tinyMCE.getAttrib(nodes[i], 'name');
  131. value = tinyMCE.getAttrib(nodes[i], 'content');
  132. httpEquiv = tinyMCE.getAttrib(nodes[i], 'httpEquiv');
  133. switch (name.toLowerCase()) {
  134. case "keywords":
  135. f.metakeywords.value = value;
  136. break;
  137. case "description":
  138. f.metadescription.value = value;
  139. break;
  140. case "author":
  141. f.metaauthor.value = value;
  142. break;
  143. case "copyright":
  144. f.metacopyright.value = value;
  145. break;
  146. case "robots":
  147. selectByValue(f, 'metarobots', value, true, true);
  148. break;
  149. }
  150. switch (httpEquiv.toLowerCase()) {
  151. case "content-type":
  152. tmp = getReItem(/charsets*=s*(.*)s*/gi, value, 1);
  153. // Override XML encoding
  154. if (tmp != "")
  155. xmlEnc = tmp;
  156. break;
  157. }
  158. }
  159. selectByValue(f, 'doctypes', docType, true, true);
  160. selectByValue(f, 'docencoding', xmlEnc, true, true);
  161. selectByValue(f, 'langdir', tinyMCE.getAttrib(doc.body, 'dir'), true, true);
  162. if (xmlVer != '')
  163. f.xml_pi.checked = true;
  164. // ------- Setup options for appearance tab
  165. // Get primary stylesheet
  166. nodes = doc.getElementsByTagName("link");
  167. for (i=0; i<nodes.length; i++) {
  168. l = nodes[i];
  169. tmp = tinyMCE.getAttrib(l, 'media');
  170. if (tinyMCE.getAttrib(l, 'mce_type') == "text/css" && (tmp == "" || tmp == "screen" || tmp == "all") && tinyMCE.getAttrib(l, 'rel') == "stylesheet") {
  171. f.stylesheet.value = tinyMCE.getAttrib(l, 'mce_href');
  172. break;
  173. }
  174. }
  175. // Get from style elements
  176. nodes = doc.getElementsByTagName("style");
  177. for (i=0; i<nodes.length; i++) {
  178. tmp = parseStyleElement(nodes[i]);
  179. for (x=0; x<tmp.length; x++) {
  180. // if (tmp[x].rule.indexOf('a:hover') != -1 && tmp[x].data['color'])
  181. // f.hover_color.value = tmp[x].data['color'];
  182. if (tmp[x].rule.indexOf('a:visited') != -1 && tmp[x].data['color'])
  183. f.visited_color.value = tmp[x].data['color'];
  184. if (tmp[x].rule.indexOf('a:link') != -1 && tmp[x].data['color'])
  185. f.link_color.value = tmp[x].data['color'];
  186. if (tmp[x].rule.indexOf('a:active') != -1 && tmp[x].data['color'])
  187. f.active_color.value = tmp[x].data['color'];
  188. }
  189. }
  190. // Get from body attribs
  191. /* f.leftmargin.value = tinyMCE.getAttrib(doc.body, "leftmargin");
  192. f.rightmargin.value = tinyMCE.getAttrib(doc.body, "rightmargin");
  193. f.topmargin.value = tinyMCE.getAttrib(doc.body, "topmargin");
  194. f.bottommargin.value = tinyMCE.getAttrib(doc.body, "bottommargin");*/
  195. f.textcolor.value = convertRGBToHex(tinyMCE.getAttrib(doc.body, "text"));
  196. f.active_color.value = convertRGBToHex(tinyMCE.getAttrib(doc.body, "alink"));
  197. f.link_color.value = convertRGBToHex(tinyMCE.getAttrib(doc.body, "link"));
  198. f.visited_color.value = convertRGBToHex(tinyMCE.getAttrib(doc.body, "vlink"));
  199. f.bgcolor.value = convertRGBToHex(tinyMCE.getAttrib(doc.body, "bgcolor"));
  200. f.bgimage.value = convertRGBToHex(tinyMCE.getAttrib(doc.body, "background"));
  201. // Get from style info
  202. var style = tinyMCE.parseStyle(tinyMCE.getAttrib(doc.body, 'style'));
  203. if (style['font-family'])
  204. selectByValue(f, 'fontface', style['font-family'], true, true);
  205. else
  206. selectByValue(f, 'fontface', tinyMCE.getParam("fullpage_default_fontface", ""), true, true);
  207. if (style['font-size'])
  208. selectByValue(f, 'fontsize', style['font-size'], true, true);
  209. else
  210. selectByValue(f, 'fontsize', tinyMCE.getParam("fullpage_default_fontsize", ""), true, true);
  211. if (style['color'])
  212. f.textcolor.value = convertRGBToHex(style['color']);
  213. if (style['background-image'])
  214. f.bgimage.value = style['background-image'].replace(new RegExp("url\('?([^']*)'?\)", 'gi'), "$1");
  215. if (style['background-color'])
  216. f.bgcolor.value = convertRGBToHex(style['background-color']);
  217. if (style['margin']) {
  218. tmp = style['margin'].replace(/[^0-9 ]/g, '');
  219. tmp = tmp.split(/ +/);
  220. f.topmargin.value = tmp.length > 0 ? tmp[0] : '';
  221. f.rightmargin.value = tmp.length > 1 ? tmp[1] : tmp[0];
  222. f.bottommargin.value = tmp.length > 2 ? tmp[2] : tmp[0];
  223. f.leftmargin.value = tmp.length > 3 ? tmp[3] : tmp[0];
  224. }
  225. if (style['margin-left'])
  226. f.leftmargin.value = style['margin-left'].replace(/[^0-9]/g, '');
  227. if (style['margin-right'])
  228. f.rightmargin.value = style['margin-right'].replace(/[^0-9]/g, '');
  229. if (style['margin-top'])
  230. f.topmargin.value = style['margin-top'].replace(/[^0-9]/g, '');
  231. if (style['margin-bottom'])
  232. f.bottommargin.value = style['margin-bottom'].replace(/[^0-9]/g, '');
  233. f.style.value = tinyMCE.serializeStyle(style);
  234. updateColor('textcolor_pick', 'textcolor');
  235. updateColor('bgcolor_pick', 'bgcolor');
  236. updateColor('visited_color_pick', 'visited_color');
  237. updateColor('active_color_pick', 'active_color');
  238. updateColor('link_color_pick', 'link_color');
  239. //updateColor('hover_color_pick', 'hover_color');
  240. }
  241. function updateAction() {
  242. var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
  243. var f = document.forms[0];
  244. var nl, i, h, v, s, head, html, l, tmp, addlink = true;
  245. head = topDoc.getElementsByTagName('head')[0];
  246. // Fix scripts without a type
  247. nl = topDoc.getElementsByTagName('script');
  248. for (i=0; i<nl.length; i++) {
  249. if (tinyMCE.getAttrib(nl[i], 'mce_type') == '')
  250. nl[i].setAttribute('mce_type', 'text/javascript');
  251. }
  252. // Get primary stylesheet
  253. nl = topDoc.getElementsByTagName("link");
  254. for (i=0; i<nl.length; i++) {
  255. l = nl[i];
  256. tmp = tinyMCE.getAttrib(l, 'media');
  257. if (tinyMCE.getAttrib(l, 'mce_type') == "text/css" && (tmp == "" || tmp == "screen" || tmp == "all") && tinyMCE.getAttrib(l, 'rel') == "stylesheet") {
  258. addlink = false;
  259. if (f.stylesheet.value == '')
  260. l.parentNode.removeChild(l);
  261. else
  262. l.setAttribute('mce_href', f.stylesheet.value);
  263. break;
  264. }
  265. }
  266. // Add new link
  267. if (f.stylesheet.value != '') {
  268. l = topDoc.createElement('link');
  269. l.setAttribute('mce_type', 'text/css');
  270. l.setAttribute('mce_href', f.stylesheet.value);
  271. l.setAttribute('rel', 'stylesheet');
  272. head.appendChild(l);
  273. }
  274. setMeta(head, 'keywords', f.metakeywords.value);
  275. setMeta(head, 'description', f.metadescription.value);
  276. setMeta(head, 'author', f.metaauthor.value);
  277. setMeta(head, 'copyright', f.metacopyright.value);
  278. setMeta(head, 'robots', getSelectValue(f, 'metarobots'));
  279. setMeta(head, 'Content-Type', getSelectValue(f, 'docencoding'));
  280. topDoc.body.dir = getSelectValue(f, 'langdir');
  281. topDoc.body.style.cssText = f.style.value;
  282. topDoc.body.setAttribute('vLink', f.visited_color.value);
  283. topDoc.body.setAttribute('link', f.link_color.value);
  284. topDoc.body.setAttribute('text', f.textcolor.value);
  285. topDoc.body.setAttribute('aLink', f.active_color.value);
  286. topDoc.body.style.fontFamily = getSelectValue(f, 'fontface');
  287. topDoc.body.style.fontSize = getSelectValue(f, 'fontsize');
  288. topDoc.body.style.backgroundColor = f.bgcolor.value;
  289. if (f.leftmargin.value != '')
  290. topDoc.body.style.marginLeft = f.leftmargin.value + 'px';
  291. if (f.rightmargin.value != '')
  292. topDoc.body.style.marginRight = f.rightmargin.value + 'px';
  293. if (f.bottommargin.value != '')
  294. topDoc.body.style.marginBottom = f.bottommargin.value + 'px';
  295. if (f.topmargin.value != '')
  296. topDoc.body.style.marginTop = f.topmargin.value + 'px';
  297. html = topDoc.getElementsByTagName('html')[0];
  298. html.setAttribute('lang', f.langcode.value);
  299. html.setAttribute('xml:lang', f.langcode.value);
  300. if (f.bgimage.value != '')
  301. topDoc.body.style.backgroundImage = "url('" + f.bgimage.value + "')";
  302. else
  303. topDoc.body.style.backgroundImage = '';
  304. inst.cleanup.addRuleStr('-title,meta[http-equiv|name|content],base[href|target],link[href|rel|type|title|media],style[type],script[type|language|src],html[lang|xml:lang|xmlns],body[style|dir|vlink|link|text|alink],head');
  305. h = inst.cleanup.serializeNodeAsHTML(topDoc.documentElement);
  306. h = h.substring(0, h.lastIndexOf('</body>'));
  307. if (h.indexOf('<title>') == -1)
  308. h = h.replace(/<head.*?>/, '$&n' + '<title>' + inst.cleanup.xmlEncode(f.metatitle.value) + '</title>');
  309. else
  310. h = h.replace(/<title>(.*?)</title>/, '<title>' + inst.cleanup.xmlEncode(f.metatitle.value) + '</title>');
  311. if ((v = getSelectValue(f, 'doctypes')) != '')
  312. h = v + 'n' + h;
  313. if (f.xml_pi.checked) {
  314. s = '<?xml version="1.0"';
  315. if ((v = getSelectValue(f, 'docencoding')) != '')
  316. s += ' encoding="' + v + '"';
  317. s += '?>n';
  318. h = s + h;
  319. }
  320. inst.fullpageTopContent = h;
  321. tinyMCEPopup.execCommand('mceFullPageUpdate', false, '');
  322. tinyMCEPopup.close();
  323. }
  324. function setMeta(he, k, v) {
  325. var nl, i, m;
  326. nl = he.getElementsByTagName('meta');
  327. for (i=0; i<nl.length; i++) {
  328. if (k == 'Content-Type' && tinyMCE.getAttrib(nl[i], 'http-equiv') == k) {
  329. if (v == '')
  330. nl[i].parentNode.removeChild(nl[i]);
  331. else
  332. nl[i].setAttribute('content', "text/html; charset=" + v);
  333. return;
  334. }
  335. if (tinyMCE.getAttrib(nl[i], 'name') == k) {
  336. if (v == '')
  337. nl[i].parentNode.removeChild(nl[i]);
  338. else
  339. nl[i].setAttribute('content', v);
  340. return;
  341. }
  342. }
  343. if (v == '')
  344. return;
  345. m = topDoc.createElement('meta');
  346. if (k == 'Content-Type')
  347. m.httpEquiv = k;
  348. else
  349. m.setAttribute('name', k);
  350. m.setAttribute('content', v);
  351. he.appendChild(m);
  352. }
  353. function parseStyleElement(e) {
  354. var v = e.innerHTML;
  355. var p, i, r;
  356. v = v.replace(/<!--/gi, '');
  357. v = v.replace(/-->/gi, '');
  358. v = v.replace(/[nr]/gi, '');
  359. v = v.replace(/s+/gi, ' ');
  360. r = new Array();
  361. p = v.split(/{|}/);
  362. for (i=0; i<p.length; i+=2) {
  363. if (p[i] != "")
  364. r[r.length] = {rule : tinyMCE.trim(p[i]), data : tinyMCE.parseStyle(p[i+1])};
  365. }
  366. return r;
  367. }
  368. function serializeStyleElement(d) {
  369. var i, s, st;
  370. s = '<!--n';
  371. for (i=0; i<d.length; i++) {
  372. s += d[i].rule + ' {n';
  373. st = tinyMCE.serializeStyle(d[i].data);
  374. if (st != '')
  375. st += ';';
  376. s += st.replace(/;/g, ';n');
  377. s += '}n';
  378. if (i != d.length - 1)
  379. s += 'n';
  380. }
  381. s += 'n-->';
  382. return s;
  383. }
  384. function getReItem(r, s, i) {
  385. var c = r.exec(s);
  386. if (c && c.length > i)
  387. return c[i];
  388. return '';
  389. }
  390. function changedStyleField(field) {
  391. //alert(field.id);
  392. }
  393. function showAddMenu() {
  394. var re = document.getElementById('addbutton');
  395. addMenuLayer.moveRelativeTo(re, 'tr');
  396. if (addMenuLayer.isMSIE)
  397. addMenuLayer.moveBy(2, 0);
  398. addMenuLayer.show();
  399. addMenuLayer.setAutoHide(true, hideAddMenu);
  400. addMenuLayer.addCSSClass(re, 'selected');
  401. }
  402. function hideAddMenu(l, e, mx, my) {
  403. var re = document.getElementById('addbutton');
  404. addMenuLayer.removeCSSClass(re, 'selected');
  405. }
  406. function addHeadElm(type) {
  407. var le = document.getElementById('headlist');
  408. var re = document.getElementById('addbutton');
  409. var te = document.getElementById(type + '_element');
  410. if (lastElementType)
  411. lastElementType.style.display = 'none';
  412. te.style.display = 'block';
  413. lastElementType = te;
  414. addMenuLayer.hide();
  415. addMenuLayer.removeCSSClass(re, 'selected');
  416. document.getElementById(type + '_updateelement').value = tinyMCE.getLang('lang_insert', 'Insert', true);
  417. le.size = 10;
  418. }
  419. function updateHeadElm(item) {
  420. var type = item.substring(0, item.indexOf('_'));
  421. var le = document.getElementById('headlist');
  422. var re = document.getElementById('addbutton');
  423. var te = document.getElementById(type + '_element');
  424. if (lastElementType)
  425. lastElementType.style.display = 'none';
  426. te.style.display = 'block';
  427. lastElementType = te;
  428. addMenuLayer.hide();
  429. addMenuLayer.removeCSSClass(re, 'selected');
  430. document.getElementById(type + '_updateelement').value = tinyMCE.getLang('lang_update', 'Update', true);
  431. le.size = 10;
  432. }
  433. function cancelElementUpdate() {
  434. var le = document.getElementById('headlist');
  435. if (lastElementType)
  436. lastElementType.style.display = 'none';
  437. le.size = 26;
  438. }