PageRenderTime 28ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/184.168.182.1/admin/old/ckeditor/_source/plugins/docprops/dialogs/docprops.js

https://gitlab.com/endomorphosis/falkenstein
JavaScript | 674 lines | 652 code | 15 blank | 7 comment | 59 complexity | e26138bb38f2d95c78b14807de28ffcd MD5 | raw file
  1. /*
  2. Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. CKEDITOR.dialog.add( 'docProps', function( editor )
  6. {
  7. var lang = editor.lang.docprops,
  8. langCommon = editor.lang.common,
  9. metaHash = {};
  10. function getDialogValue( dialogName, callback )
  11. {
  12. var onOk = function()
  13. {
  14. releaseHandlers( this );
  15. callback( this, this._.parentDialog );
  16. };
  17. var releaseHandlers = function( dialog )
  18. {
  19. dialog.removeListener( 'ok', onOk );
  20. dialog.removeListener( 'cancel', releaseHandlers );
  21. };
  22. var bindToDialog = function( dialog )
  23. {
  24. dialog.on( 'ok', onOk );
  25. dialog.on( 'cancel', releaseHandlers );
  26. };
  27. editor.execCommand( dialogName );
  28. if ( editor._.storedDialogs.colordialog )
  29. bindToDialog( editor._.storedDialogs.colordialog );
  30. else
  31. {
  32. CKEDITOR.on( 'dialogDefinition', function( e )
  33. {
  34. if ( e.data.name != dialogName )
  35. return;
  36. var definition = e.data.definition;
  37. e.removeListener();
  38. definition.onLoad = CKEDITOR.tools.override( definition.onLoad, function( orginal )
  39. {
  40. return function()
  41. {
  42. bindToDialog( this );
  43. definition.onLoad = orginal;
  44. if ( typeof orginal == 'function' )
  45. orginal.call( this );
  46. };
  47. });
  48. });
  49. }
  50. }
  51. function handleOther()
  52. {
  53. var dialog = this.getDialog(),
  54. other = dialog.getContentElement( 'general', this.id + 'Other' );
  55. if ( !other )
  56. return;
  57. if ( this.getValue() == 'other' )
  58. {
  59. other.getInputElement().removeAttribute( 'readOnly' );
  60. other.focus();
  61. other.getElement().removeClass( 'cke_disabled' );
  62. }
  63. else
  64. {
  65. other.getInputElement().setAttribute( 'readOnly', true );
  66. other.getElement().addClass( 'cke_disabled' );
  67. }
  68. }
  69. function commitMeta( name, isHttp, value )
  70. {
  71. return function( doc, html, head )
  72. {
  73. var hash = metaHash,
  74. val = typeof value != 'undefined' ? value : this.getValue();
  75. if ( !val && ( name in hash ) )
  76. hash[ name ].remove();
  77. else if ( val && ( name in hash ) )
  78. hash[ name ].setAttribute( 'content', val );
  79. else if ( val )
  80. {
  81. var meta = new CKEDITOR.dom.element( 'meta', editor.document );
  82. meta.setAttribute( isHttp ? 'http-equiv' : 'name', name );
  83. meta.setAttribute( 'content', val );
  84. head.append( meta );
  85. }
  86. };
  87. }
  88. function setupMeta( name, ret )
  89. {
  90. return function()
  91. {
  92. var hash = metaHash,
  93. result = ( name in hash ) ? hash[ name ].getAttribute( 'content' ) || '' : '';
  94. if ( ret )
  95. return result;
  96. this.setValue( result );
  97. return null;
  98. };
  99. }
  100. function commitMargin( name )
  101. {
  102. return function( doc, html, head, body )
  103. {
  104. body.removeAttribute( 'margin' + name );
  105. var val = this.getValue();
  106. if ( val !== '' )
  107. body.setStyle( 'margin-' + name, CKEDITOR.tools.cssLength( val ) );
  108. else
  109. body.removeStyle( 'margin-' + name );
  110. };
  111. }
  112. function createMetaHash( doc )
  113. {
  114. var hash = {},
  115. metas = doc.getElementsByTag( 'meta' ),
  116. count = metas.count();
  117. for ( var i = 0; i < count; i++ )
  118. {
  119. var meta = metas.getItem( i );
  120. hash[ meta.getAttribute( meta.hasAttribute( 'http-equiv' ) ? 'http-equiv' : 'name' ).toLowerCase() ] = meta;
  121. }
  122. return hash;
  123. }
  124. // We cannot just remove the style from the element, as it might be affected from non-inline stylesheets.
  125. // To get the proper result, we should manually set the inline style to its default value.
  126. function resetStyle( element, prop, resetVal )
  127. {
  128. element.removeStyle( prop );
  129. if ( element.getComputedStyle( prop ) != resetVal )
  130. element.setStyle( prop, resetVal );
  131. }
  132. // Utilty to shorten the creation of color fields in the dialog.
  133. var colorField = function( id, label, fieldProps )
  134. {
  135. return {
  136. type : 'hbox',
  137. padding : 0,
  138. widths : [ '60%', '40%' ],
  139. children : [
  140. CKEDITOR.tools.extend( {
  141. type : 'text',
  142. id : id,
  143. label : lang[ label ]
  144. }, fieldProps || {}, 1 ),
  145. {
  146. type : 'button',
  147. id : id + 'Choose',
  148. label : lang.chooseColor,
  149. className : 'colorChooser',
  150. onClick : function()
  151. {
  152. var self = this;
  153. getDialogValue( 'colordialog', function( colorDialog )
  154. {
  155. var dialog = self.getDialog();
  156. dialog.getContentElement( dialog._.currentTabId, id ).setValue( colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue() );
  157. });
  158. }
  159. }
  160. ]
  161. };
  162. };
  163. var previewSrc = 'javascript:' +
  164. 'void((function(){' +
  165. encodeURIComponent(
  166. 'document.open();' +
  167. ( CKEDITOR.env.isCustomDomain() ? 'document.domain=\'' + document.domain + '\';' : '' ) +
  168. 'document.write( \'<html style="background-color: #ffffff; height: 100%"><head></head><body style="width: 100%; height: 100%; margin: 0px">' + lang.previewHtml + '</body></html>\' );' +
  169. 'document.close();'
  170. ) +
  171. '})())';
  172. return {
  173. title : lang.title,
  174. minHeight: 330,
  175. minWidth: 500,
  176. onShow : function()
  177. {
  178. var doc = editor.document,
  179. html = doc.getElementsByTag( 'html' ).getItem( 0 ),
  180. head = doc.getHead(),
  181. body = doc.getBody();
  182. metaHash = createMetaHash( doc );
  183. this.setupContent( doc, html, head, body );
  184. },
  185. onHide : function()
  186. {
  187. metaHash = {};
  188. },
  189. onOk : function()
  190. {
  191. var doc = editor.document,
  192. html = doc.getElementsByTag( 'html' ).getItem( 0 ),
  193. head = doc.getHead(),
  194. body = doc.getBody();
  195. this.commitContent( doc, html, head, body );
  196. },
  197. contents : [
  198. {
  199. id : 'general',
  200. label : langCommon.generalTab,
  201. elements : [
  202. {
  203. type : 'text',
  204. id : 'title',
  205. label : lang.docTitle,
  206. setup : function( doc )
  207. {
  208. this.setValue( doc.getElementsByTag( 'title' ).getItem( 0 ).data( 'cke-title' ) );
  209. },
  210. commit : function( doc, html, head, body, isPreview )
  211. {
  212. if ( isPreview )
  213. return;
  214. doc.getElementsByTag( 'title' ).getItem( 0 ).data( 'cke-title', this.getValue() );
  215. }
  216. },
  217. {
  218. type : 'hbox',
  219. children : [
  220. {
  221. type : 'select',
  222. id : 'dir',
  223. label : langCommon.langDir,
  224. style : 'width: 100%',
  225. items : [
  226. [ langCommon.notSet , '' ],
  227. [ langCommon.langDirLtr, 'ltr' ],
  228. [ langCommon.langDirRtl, 'rtl' ]
  229. ],
  230. setup : function( doc, html, head, body )
  231. {
  232. this.setValue( body.getDirection() || '' );
  233. },
  234. commit : function( doc, html, head, body )
  235. {
  236. var val = this.getValue();
  237. if ( val )
  238. body.setAttribute( 'dir', val );
  239. else
  240. body.removeAttribute( 'dir' );
  241. body.removeStyle( 'direction' );
  242. }
  243. },
  244. {
  245. type : 'text',
  246. id : 'langCode',
  247. label : langCommon.langCode,
  248. setup : function( doc, html )
  249. {
  250. this.setValue( html.getAttribute( 'xml:lang' ) || html.getAttribute( 'lang' ) || '' );
  251. },
  252. commit : function( doc, html, head, body, isPreview )
  253. {
  254. if ( isPreview )
  255. return;
  256. var val = this.getValue();
  257. if ( val )
  258. html.setAttributes( { 'xml:lang' : val, lang : val } );
  259. else
  260. html.removeAttributes( { 'xml:lang' : 1, lang : 1 } );
  261. }
  262. }
  263. ]
  264. },
  265. {
  266. type : 'hbox',
  267. children : [
  268. {
  269. type : 'select',
  270. id : 'charset',
  271. label : lang.charset,
  272. style : 'width: 100%',
  273. items : [
  274. [ langCommon.notSet, '' ],
  275. [ lang.charsetASCII, 'us-ascii' ],
  276. [ lang.charsetCE, 'iso-8859-2' ],
  277. [ lang.charsetCT, 'big5' ],
  278. [ lang.charsetCR, 'iso-8859-5' ],
  279. [ lang.charsetGR, 'iso-8859-7' ],
  280. [ lang.charsetJP, 'iso-2022-jp' ],
  281. [ lang.charsetKR, 'iso-2022-kr' ],
  282. [ lang.charsetTR, 'iso-8859-9' ],
  283. [ lang.charsetUN, 'utf-8' ],
  284. [ lang.charsetWE, 'iso-8859-1' ],
  285. [ lang.other, 'other' ]
  286. ],
  287. 'default' : '',
  288. onChange : function()
  289. {
  290. this.getDialog().selectedCharset = this.getValue() != 'other' ? this.getValue() : '';
  291. handleOther.call( this );
  292. },
  293. setup : function()
  294. {
  295. this.metaCharset = ( 'charset' in metaHash );
  296. var func = setupMeta( this.metaCharset ? 'charset' : 'content-type', 1, 1 ),
  297. val = func.call( this );
  298. !this.metaCharset && val.match( /charset=[^=]+$/ ) && ( val = val.substring( val.indexOf( '=' ) + 1 ) );
  299. if ( val )
  300. {
  301. this.setValue( val.toLowerCase() );
  302. if ( !this.getValue() )
  303. {
  304. this.setValue( 'other' );
  305. var other = this.getDialog().getContentElement( 'general', 'charsetOther' );
  306. other && other.setValue( val );
  307. }
  308. this.getDialog().selectedCharset = val;
  309. }
  310. handleOther.call( this );
  311. },
  312. commit : function( doc, html, head, body, isPreview )
  313. {
  314. if ( isPreview )
  315. return;
  316. var value = this.getValue(),
  317. other = this.getDialog().getContentElement( 'general', 'charsetOther' );
  318. value == 'other' && ( value = other ? other.getValue() : '' );
  319. value && !this.metaCharset && ( value = ( metaHash[ 'content-type' ] ? metaHash[ 'content-type' ].getAttribute( 'content' ).split( ';' )[0] : 'text/html' ) + '; charset=' + value );
  320. var func = commitMeta( this.metaCharset ? 'charset' : 'content-type', 1, value );
  321. func.call( this, doc, html, head );
  322. }
  323. },
  324. {
  325. type : 'text',
  326. id : 'charsetOther',
  327. label : lang.charsetOther,
  328. onChange : function(){ this.getDialog().selectedCharset = this.getValue(); }
  329. }
  330. ]
  331. },
  332. {
  333. type : 'hbox',
  334. children : [
  335. {
  336. type : 'select',
  337. id : 'docType',
  338. label : lang.docType,
  339. style : 'width: 100%',
  340. items : [
  341. [ langCommon.notSet , '' ],
  342. [ 'XHTML 1.1', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' ],
  343. [ 'XHTML 1.0 Transitional', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' ],
  344. [ 'XHTML 1.0 Strict', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' ],
  345. [ 'XHTML 1.0 Frameset', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">' ],
  346. [ 'HTML 5', '<!DOCTYPE html>' ],
  347. [ 'HTML 4.01 Transitional', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' ],
  348. [ 'HTML 4.01 Strict', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' ],
  349. [ 'HTML 4.01 Frameset', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">' ],
  350. [ 'HTML 3.2', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">' ],
  351. [ 'HTML 2.0', '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">' ],
  352. [ lang.other, 'other' ]
  353. ],
  354. onChange : handleOther,
  355. setup : function()
  356. {
  357. if ( editor.docType )
  358. {
  359. this.setValue( editor.docType );
  360. if ( !this.getValue() )
  361. {
  362. this.setValue( 'other' );
  363. var other = this.getDialog().getContentElement( 'general', 'docTypeOther' );
  364. other && other.setValue( editor.docType );
  365. }
  366. }
  367. handleOther.call( this );
  368. },
  369. commit : function( doc, html, head, body, isPreview )
  370. {
  371. if ( isPreview )
  372. return;
  373. var value = this.getValue(),
  374. other = this.getDialog().getContentElement( 'general', 'docTypeOther' );
  375. editor.docType = value == 'other' ? ( other ? other.getValue() : '' ) : value;
  376. }
  377. },
  378. {
  379. type : 'text',
  380. id : 'docTypeOther',
  381. label : lang.docTypeOther
  382. }
  383. ]
  384. },
  385. {
  386. type : 'checkbox',
  387. id : 'xhtmlDec',
  388. label : lang.xhtmlDec,
  389. setup : function()
  390. {
  391. this.setValue( !!editor.xmlDeclaration );
  392. },
  393. commit : function( doc, html, head, body, isPreview )
  394. {
  395. if ( isPreview )
  396. return;
  397. if ( this.getValue() )
  398. {
  399. editor.xmlDeclaration = '<?xml version="1.0" encoding="' + ( this.getDialog().selectedCharset || 'utf-8' )+ '"?>' ;
  400. html.setAttribute( 'xmlns', 'http://www.w3.org/1999/xhtml' );
  401. }
  402. else
  403. {
  404. editor.xmlDeclaration = '';
  405. html.removeAttribute( 'xmlns' );
  406. }
  407. }
  408. }
  409. ]
  410. },
  411. {
  412. id : 'design',
  413. label : lang.design,
  414. elements : [
  415. {
  416. type : 'hbox',
  417. widths : [ '60%', '40%' ],
  418. children : [
  419. {
  420. type : 'vbox',
  421. children : [
  422. colorField( 'txtColor', 'txtColor',
  423. {
  424. setup : function( doc, html, head, body )
  425. {
  426. this.setValue( body.getComputedStyle( 'color' ) );
  427. },
  428. commit : function( doc, html, head, body, isPreview )
  429. {
  430. if ( this.isChanged() || isPreview )
  431. {
  432. body.removeAttribute( 'text' );
  433. var val = this.getValue();
  434. if ( val )
  435. body.setStyle( 'color', val );
  436. else
  437. body.removeStyle( 'color' );
  438. }
  439. }
  440. }),
  441. colorField( 'bgColor', 'bgColor', {
  442. setup : function( doc, html, head, body )
  443. {
  444. var val = body.getComputedStyle( 'background-color' ) || '';
  445. this.setValue( val == 'transparent' ? '' : val );
  446. },
  447. commit : function( doc, html, head, body, isPreview )
  448. {
  449. if ( this.isChanged() || isPreview )
  450. {
  451. body.removeAttribute( 'bgcolor' );
  452. var val = this.getValue();
  453. if ( val )
  454. body.setStyle( 'background-color', val );
  455. else
  456. resetStyle( body, 'background-color', 'transparent' );
  457. }
  458. }
  459. }),
  460. {
  461. type : 'hbox',
  462. widths : [ '60%', '40%' ],
  463. padding : 1,
  464. children : [
  465. {
  466. type : 'text',
  467. id : 'bgImage',
  468. label : lang.bgImage,
  469. setup : function( doc, html, head, body )
  470. {
  471. var val = body.getComputedStyle( 'background-image' ) || '';
  472. if ( val == 'none' )
  473. val = '';
  474. else
  475. {
  476. val = val.replace( /url\(\s*(["']?)\s*([^\)]*)\s*\1\s*\)/i, function( match, quote, url )
  477. {
  478. return url;
  479. });
  480. }
  481. this.setValue( val );
  482. },
  483. commit : function( doc, html, head, body )
  484. {
  485. body.removeAttribute( 'background' );
  486. var val = this.getValue();
  487. if ( val )
  488. body.setStyle( 'background-image', 'url(' + val + ')' );
  489. else
  490. resetStyle( body, 'background-image', 'none' );
  491. }
  492. },
  493. {
  494. type : 'button',
  495. id : 'bgImageChoose',
  496. label : langCommon.browseServer,
  497. style : 'display:inline-block;margin-top:10px;',
  498. hidden : true,
  499. filebrowser : 'design:bgImage'
  500. }
  501. ]
  502. },
  503. {
  504. type : 'checkbox',
  505. id : 'bgFixed',
  506. label : lang.bgFixed,
  507. setup : function( doc, html, head, body )
  508. {
  509. this.setValue( body.getComputedStyle( 'background-attachment' ) == 'fixed' );
  510. },
  511. commit : function( doc, html, head, body )
  512. {
  513. if ( this.getValue() )
  514. body.setStyle( 'background-attachment', 'fixed' );
  515. else
  516. resetStyle( body, 'background-attachment', 'scroll' );
  517. }
  518. }
  519. ]
  520. },
  521. {
  522. type : 'vbox',
  523. children : [
  524. {
  525. type : 'html',
  526. id : 'marginTitle',
  527. html : '<div style="text-align: center; margin: 0px auto; font-weight: bold">' + lang.margin + '</div>'
  528. },
  529. {
  530. type : 'text',
  531. id : 'marginTop',
  532. label : lang.marginTop,
  533. style : 'width: 80px; text-align: center',
  534. align : 'center',
  535. inputStyle : 'text-align: center',
  536. setup : function( doc, html, head, body )
  537. {
  538. this.setValue( body.getStyle( 'margin-top' ) || body.getAttribute( 'margintop' ) || '' );
  539. },
  540. commit : commitMargin( 'top' )
  541. },
  542. {
  543. type : 'hbox',
  544. children : [
  545. {
  546. type : 'text',
  547. id : 'marginLeft',
  548. label : lang.marginLeft,
  549. style : 'width: 80px; text-align: center',
  550. align : 'center',
  551. inputStyle : 'text-align: center',
  552. setup : function( doc, html, head, body )
  553. {
  554. this.setValue( body.getStyle( 'margin-left' ) || body.getAttribute( 'marginleft' ) || '' );
  555. },
  556. commit : commitMargin( 'left' )
  557. },
  558. {
  559. type : 'text',
  560. id : 'marginRight',
  561. label : lang.marginRight,
  562. style : 'width: 80px; text-align: center',
  563. align : 'center',
  564. inputStyle : 'text-align: center',
  565. setup : function( doc, html, head, body )
  566. {
  567. this.setValue( body.getStyle( 'margin-right' ) || body.getAttribute( 'marginright' ) || '' );
  568. },
  569. commit : commitMargin( 'right' )
  570. }
  571. ]
  572. },
  573. {
  574. type : 'text',
  575. id : 'marginBottom',
  576. label : lang.marginBottom,
  577. style : 'width: 80px; text-align: center',
  578. align : 'center',
  579. inputStyle : 'text-align: center',
  580. setup : function( doc, html, head, body )
  581. {
  582. this.setValue( body.getStyle( 'margin-bottom' ) || body.getAttribute( 'marginbottom' ) || '' );
  583. },
  584. commit : commitMargin( 'bottom' )
  585. }
  586. ]
  587. }
  588. ]
  589. }
  590. ]
  591. },
  592. {
  593. id : 'meta',
  594. label : lang.meta,
  595. elements : [
  596. {
  597. type : 'textarea',
  598. id : 'metaKeywords',
  599. label : lang.metaKeywords,
  600. setup : setupMeta( 'keywords' ),
  601. commit : commitMeta( 'keywords' )
  602. },
  603. {
  604. type : 'textarea',
  605. id : 'metaDescription',
  606. label : lang.metaDescription,
  607. setup : setupMeta( 'description' ),
  608. commit : commitMeta( 'description' )
  609. },
  610. {
  611. type : 'text',
  612. id : 'metaAuthor',
  613. label : lang.metaAuthor,
  614. setup : setupMeta( 'author' ),
  615. commit : commitMeta( 'author' )
  616. },
  617. {
  618. type : 'text',
  619. id : 'metaCopyright',
  620. label : lang.metaCopyright,
  621. setup : setupMeta( 'copyright' ),
  622. commit : commitMeta( 'copyright' )
  623. }
  624. ]
  625. },
  626. {
  627. id : 'preview',
  628. label : langCommon.preview,
  629. elements : [
  630. {
  631. type : 'html',
  632. id : 'previewHtml',
  633. html : '<iframe src="' + previewSrc + '" style="width: 100%; height: 310px" hidefocus="true" frameborder="0" ' +
  634. 'id="cke_docProps_preview_iframe"></iframe>',
  635. onLoad : function()
  636. {
  637. this.getDialog().on( 'selectPage', function( ev )
  638. {
  639. if ( ev.data.page == 'preview' )
  640. {
  641. var self = this;
  642. setTimeout( function()
  643. {
  644. var doc = CKEDITOR.document.getById( 'cke_docProps_preview_iframe' ).getFrameDocument(),
  645. html = doc.getElementsByTag( 'html' ).getItem( 0 ),
  646. head = doc.getHead(),
  647. body = doc.getBody();
  648. self.commitContent( doc, html, head, body, 1 );
  649. }, 50 );
  650. }
  651. });
  652. CKEDITOR.document.getById( 'cke_docProps_preview_iframe' ).getAscendant( 'table' ).setStyle( 'height', '100%' );
  653. }
  654. }
  655. ]
  656. }
  657. ]
  658. };
  659. });