wsc_ie.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. CKEDITOR.dialog.add( 'checkspell', function( editor ) {
  6. var number = CKEDITOR.tools.getNextNumber(),
  7. iframeId = 'cke_frame_' + number,
  8. textareaId = 'cke_data_' + number,
  9. errorBoxId = 'cke_error_' + number,
  10. interval,
  11. protocol = document.location.protocol || 'http:',
  12. errorMsg = editor.lang.wsc.notAvailable;
  13. var pasteArea =
  14. '<textarea' +
  15. ' style="display: none"' +
  16. ' id="' + textareaId + '"' +
  17. ' rows="10"' +
  18. ' cols="40">' +
  19. ' </textarea><div' +
  20. ' id="' + errorBoxId + '"' +
  21. ' style="display:none;color:red;font-size:16px;font-weight:bold;padding-top:160px;text-align:center;z-index:11;">' +
  22. '</div><iframe' +
  23. ' src=""' +
  24. ' style="width:100%;background-color:#f1f1e3;"' +
  25. ' frameborder="0"' +
  26. ' name="' + iframeId + '"' +
  27. ' id="' + iframeId + '"' +
  28. ' allowtransparency="1">' +
  29. '</iframe>';
  30. var wscCoreUrl = editor.config.wsc_customLoaderScript || ( protocol + '//loader.webspellchecker.net/sproxy_fck/sproxy.php' + '?plugin=fck2'
  31. + '&customerid=' + editor.config.wsc_customerId
  32. + '&cmd=script&doc=wsc&schema=22'
  33. );
  34. if ( editor.config.wsc_customLoaderScript ) {
  35. errorMsg += '<p style="color:#000;font-size:11px;font-weight: normal;text-align:center;padding-top:10px">' +
  36. editor.lang.wsc.errorLoading.replace( /%s/g, editor.config.wsc_customLoaderScript ) + '</p>';
  37. }
  38. function burnSpelling( dialog, errorMsg ) {
  39. var i = 0;
  40. return function() {
  41. if ( typeof( window.doSpell ) == 'function' ) {
  42. //Call from window.setInteval expected at once.
  43. if ( typeof( interval ) != 'undefined' )
  44. window.clearInterval( interval );
  45. initAndSpell( dialog );
  46. } else if ( i++ == 180 ) // Timeout: 180 * 250ms = 45s.
  47. window._cancelOnError( errorMsg );
  48. };
  49. }
  50. window._cancelOnError = function( m ) {
  51. if ( typeof( window.WSC_Error ) == 'undefined' ) {
  52. CKEDITOR.document.getById( iframeId ).setStyle( 'display', 'none' );
  53. var errorBox = CKEDITOR.document.getById( errorBoxId );
  54. errorBox.setStyle( 'display', 'block' );
  55. errorBox.setHtml( m || editor.lang.wsc.notAvailable );
  56. }
  57. };
  58. function initAndSpell( dialog ) {
  59. var LangComparer = new window._SP_FCK_LangCompare(),
  60. // Language abbr standarts comparer.
  61. pluginPath = CKEDITOR.getUrl( editor.plugins.wsc.path + 'dialogs/' ),
  62. // Service paths corecting/preparing.
  63. framesetPath = pluginPath + 'tmpFrameset.html';
  64. // global var is used in FCK specific core
  65. // change on equal var used in fckplugin.js
  66. window.gFCKPluginName = 'wsc';
  67. LangComparer.setDefaulLangCode( editor.config.defaultLanguage );
  68. window.doSpell({
  69. ctrl: textareaId,
  70. lang: editor.config.wsc_lang || LangComparer.getSPLangCode( editor.langCode ),
  71. intLang: editor.config.wsc_uiLang || LangComparer.getSPLangCode( editor.langCode ),
  72. winType: iframeId, // If not defined app will run on winpopup.
  73. // Callback binding section.
  74. onCancel: function() {
  75. dialog.hide();
  76. },
  77. onFinish: function( dT ) {
  78. editor.focus();
  79. dialog.getParentEditor().setData( dT.value );
  80. dialog.hide();
  81. },
  82. // Some manipulations with client static pages.
  83. staticFrame: framesetPath,
  84. framesetPath: framesetPath,
  85. iframePath: pluginPath + 'ciframe.html',
  86. // Styles defining.
  87. schemaURI: pluginPath + 'wsc.css',
  88. userDictionaryName: editor.config.wsc_userDictionaryName,
  89. customDictionaryName: editor.config.wsc_customDictionaryIds && editor.config.wsc_customDictionaryIds.split( "," ),
  90. domainName: editor.config.wsc_domainName
  91. });
  92. // Hide user message console (if application was loaded more then after timeout).
  93. CKEDITOR.document.getById( errorBoxId ).setStyle( 'display', 'none' );
  94. CKEDITOR.document.getById( iframeId ).setStyle( 'display', 'block' );
  95. }
  96. return {
  97. title: editor.config.wsc_dialogTitle || editor.lang.wsc.title,
  98. minWidth: 485,
  99. minHeight: 380,
  100. buttons: [ CKEDITOR.dialog.cancelButton ],
  101. onShow: function() {
  102. var contentArea = this.getContentElement( 'general', 'content' ).getElement();
  103. contentArea.setHtml( pasteArea );
  104. contentArea.getChild( 2 ).setStyle( 'height', this._.contentSize.height + 'px' );
  105. if ( typeof( window.doSpell ) != 'function' ) {
  106. // Load script.
  107. CKEDITOR.document.getHead().append( CKEDITOR.document.createElement( 'script', {
  108. attributes: {
  109. type: 'text/javascript',
  110. src: wscCoreUrl
  111. }
  112. }));
  113. }
  114. var sData = editor.getData(); // Get the data to be checked.
  115. CKEDITOR.document.getById( textareaId ).setValue( sData );
  116. interval = window.setInterval( burnSpelling( this, errorMsg ), 250 );
  117. },
  118. onHide: function() {
  119. window.ooo = undefined;
  120. window.int_framsetLoaded = undefined;
  121. window.framesetLoaded = undefined;
  122. window.is_window_opened = false;
  123. },
  124. contents: [
  125. {
  126. id: 'general',
  127. label: editor.config.wsc_dialogTitle || editor.lang.wsc.title,
  128. padding: 0,
  129. elements: [
  130. {
  131. type: 'html',
  132. id: 'content',
  133. html: ''
  134. }
  135. ]
  136. }
  137. ]
  138. };
  139. });
  140. // Expand the spell-check frame when dialog resized. (#6829)
  141. CKEDITOR.dialog.on( 'resize', function( evt ) {
  142. var data = evt.data,
  143. dialog = data.dialog;
  144. if ( dialog._.name == 'checkspell' ) {
  145. var content = dialog.getContentElement( 'general', 'content' ).getElement(),
  146. iframe = content && content.getChild( 2 );
  147. iframe && iframe.setSize( 'height', data.height );
  148. iframe && iframe.setSize( 'width', data.width );
  149. }
  150. });