国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1294 lines
46KB

  1. /**
  2. * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. ( function() {
  6. var imageDialog = function( editor, dialogType ) {
  7. // Load image preview.
  8. var IMAGE = 1,
  9. LINK = 2,
  10. PREVIEW = 4,
  11. CLEANUP = 8,
  12. regexGetSize = /^\s*(\d+)((px)|\%)?\s*$/i,
  13. regexGetSizeOrEmpty = /(^\s*(\d+)((px)|\%)?\s*$)|^$/i,
  14. pxLengthRegex = /^\d+px$/;
  15. var onSizeChange = function() {
  16. var value = this.getValue(),
  17. // This = input element.
  18. dialog = this.getDialog(),
  19. aMatch = value.match( regexGetSize ); // Check value
  20. if ( aMatch ) {
  21. if ( aMatch[ 2 ] == '%' ) // % is allowed - > unlock ratio.
  22. switchLockRatio( dialog, false ); // Unlock.
  23. value = aMatch[ 1 ];
  24. }
  25. // Only if ratio is locked
  26. if ( dialog.lockRatio ) {
  27. var oImageOriginal = dialog.originalElement;
  28. if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' ) {
  29. if ( this.id == 'txtHeight' ) {
  30. if ( value && value != '0' )
  31. value = Math.round( oImageOriginal.$.width * ( value / oImageOriginal.$.height ) );
  32. if ( !isNaN( value ) )
  33. dialog.setValueOf( 'info', 'txtWidth', value );
  34. }
  35. // this.id = txtWidth.
  36. else {
  37. if ( value && value != '0' )
  38. value = Math.round( oImageOriginal.$.height * ( value / oImageOriginal.$.width ) );
  39. if ( !isNaN( value ) )
  40. dialog.setValueOf( 'info', 'txtHeight', value );
  41. }
  42. }
  43. }
  44. updatePreview( dialog );
  45. };
  46. var updatePreview = function( dialog ) {
  47. //Don't load before onShow.
  48. if ( !dialog.originalElement || !dialog.preview )
  49. return 1;
  50. // Read attributes and update imagePreview;
  51. dialog.commitContent( PREVIEW, dialog.preview );
  52. return 0;
  53. };
  54. // Custom commit dialog logic, where we're intended to give inline style
  55. // field (txtdlgGenStyle) higher priority to avoid overwriting styles contribute
  56. // by other fields.
  57. function commitContent() {
  58. var args = arguments;
  59. var inlineStyleField = this.getContentElement( 'advanced', 'txtdlgGenStyle' );
  60. inlineStyleField && inlineStyleField.commit.apply( inlineStyleField, args );
  61. this.foreach( function( widget ) {
  62. if ( widget.commit && widget.id != 'txtdlgGenStyle' )
  63. widget.commit.apply( widget, args );
  64. } );
  65. }
  66. // Avoid recursions.
  67. var incommit;
  68. // Synchronous field values to other impacted fields is required, e.g. border
  69. // size change should alter inline-style text as well.
  70. function commitInternally( targetFields ) {
  71. if ( incommit )
  72. return;
  73. incommit = 1;
  74. var dialog = this.getDialog(),
  75. element = dialog.imageElement;
  76. if ( element ) {
  77. // Commit this field and broadcast to target fields.
  78. this.commit( IMAGE, element );
  79. targetFields = [].concat( targetFields );
  80. var length = targetFields.length,
  81. field;
  82. for ( var i = 0; i < length; i++ ) {
  83. field = dialog.getContentElement.apply( dialog, targetFields[ i ].split( ':' ) );
  84. // May cause recursion.
  85. field && field.setup( IMAGE, element );
  86. }
  87. }
  88. incommit = 0;
  89. }
  90. var switchLockRatio = function( dialog, value ) {
  91. if ( !dialog.getContentElement( 'info', 'ratioLock' ) )
  92. return null;
  93. var oImageOriginal = dialog.originalElement;
  94. // Dialog may already closed. (https://dev.ckeditor.com/ticket/5505)
  95. if ( !oImageOriginal )
  96. return null;
  97. // Check image ratio and original image ratio, but respecting user's preference.
  98. if ( value == 'check' ) {
  99. if ( !dialog.userlockRatio && oImageOriginal.getCustomData( 'isReady' ) == 'true' ) {
  100. var width = dialog.getValueOf( 'info', 'txtWidth' ),
  101. height = dialog.getValueOf( 'info', 'txtHeight' ),
  102. originalRatio = oImageOriginal.$.width / oImageOriginal.$.height,
  103. thisRatio = width / height;
  104. dialog.lockRatio = false; // Default: unlock ratio
  105. if ( !width && !height ) {
  106. dialog.lockRatio = true;
  107. } else {
  108. // Round ratio to two decimal places so ratio locking will be less precise (#2254).
  109. var ratioComparison = Math.round( ( originalRatio / thisRatio ) * 100 ) / 100;
  110. if ( ratioComparison == 1 ) {
  111. dialog.lockRatio = true;
  112. }
  113. }
  114. }
  115. } else if ( value !== undefined ) {
  116. dialog.lockRatio = value;
  117. } else {
  118. dialog.userlockRatio = 1;
  119. dialog.lockRatio = !dialog.lockRatio;
  120. }
  121. var ratioButton = CKEDITOR.document.getById( btnLockSizesId );
  122. if ( dialog.lockRatio )
  123. ratioButton.removeClass( 'cke_btn_unlocked' );
  124. else
  125. ratioButton.addClass( 'cke_btn_unlocked' );
  126. ratioButton.setAttribute( 'aria-checked', dialog.lockRatio );
  127. // Ratio button hc presentation - WHITE SQUARE / BLACK SQUARE
  128. if ( CKEDITOR.env.hc ) {
  129. var icon = ratioButton.getChild( 0 );
  130. icon.setHtml( dialog.lockRatio ? CKEDITOR.env.ie ? '\u25A0' : '\u25A3' : CKEDITOR.env.ie ? '\u25A1' : '\u25A2' );
  131. }
  132. return dialog.lockRatio;
  133. };
  134. var resetSize = function( dialog, emptyValues ) {
  135. var oImageOriginal = dialog.originalElement,
  136. ready = oImageOriginal.getCustomData( 'isReady' ) == 'true';
  137. if ( ready ) {
  138. var widthField = dialog.getContentElement( 'info', 'txtWidth' ),
  139. heightField = dialog.getContentElement( 'info', 'txtHeight' ),
  140. widthValue, heightValue;
  141. if ( emptyValues ) {
  142. widthValue = 0;
  143. heightValue = 0;
  144. } else {
  145. widthValue = oImageOriginal.$.width;
  146. heightValue = oImageOriginal.$.height;
  147. }
  148. widthField && widthField.setValue( widthValue );
  149. heightField && heightField.setValue( heightValue );
  150. }
  151. updatePreview( dialog );
  152. };
  153. var setupDimension = function( type, element ) {
  154. if ( type != IMAGE )
  155. return;
  156. function checkDimension( size, defaultValue ) {
  157. var aMatch = size.match( regexGetSize );
  158. if ( aMatch ) {
  159. // % is allowed.
  160. if ( aMatch[ 2 ] == '%' ) {
  161. aMatch[ 1 ] += '%';
  162. switchLockRatio( dialog, false ); // Unlock ratio
  163. }
  164. return aMatch[ 1 ];
  165. }
  166. return defaultValue;
  167. }
  168. var dialog = this.getDialog(),
  169. value = '',
  170. dimension = this.id == 'txtWidth' ? 'width' : 'height',
  171. size = element.getAttribute( dimension );
  172. if ( size )
  173. value = checkDimension( size, value );
  174. value = checkDimension( element.getStyle( dimension ), value );
  175. this.setValue( value );
  176. };
  177. var previewPreloader;
  178. var onImgLoadEvent = function() {
  179. // Image is ready.
  180. var original = this.originalElement,
  181. loader = CKEDITOR.document.getById( imagePreviewLoaderId );
  182. original.setCustomData( 'isReady', 'true' );
  183. original.removeListener( 'load', onImgLoadEvent );
  184. original.removeListener( 'error', onImgLoadErrorEvent );
  185. original.removeListener( 'abort', onImgLoadErrorEvent );
  186. // Hide loader.
  187. if ( loader )
  188. loader.setStyle( 'display', 'none' );
  189. // New image -> new dimensions
  190. if ( !this.dontResetSize ) {
  191. resetSize( this, editor.config.image_prefillDimensions === false );
  192. }
  193. if ( this.firstLoad ) {
  194. CKEDITOR.tools.setTimeout( function() {
  195. switchLockRatio( this, 'check' );
  196. }, 0, this );
  197. }
  198. this.firstLoad = false;
  199. this.dontResetSize = false;
  200. // Possible fix for https://dev.ckeditor.com/ticket/12818.
  201. updatePreview( this );
  202. };
  203. var onImgLoadErrorEvent = function() {
  204. // Error. Image is not loaded.
  205. var original = this.originalElement,
  206. loader = CKEDITOR.document.getById( imagePreviewLoaderId );
  207. original.removeListener( 'load', onImgLoadEvent );
  208. original.removeListener( 'error', onImgLoadErrorEvent );
  209. original.removeListener( 'abort', onImgLoadErrorEvent );
  210. // Set Error image.
  211. var noimage = CKEDITOR.getUrl( CKEDITOR.plugins.get( 'image' ).path + 'images/noimage.png' );
  212. if ( this.preview )
  213. this.preview.setAttribute( 'src', noimage );
  214. // Hide loader.
  215. if ( loader )
  216. loader.setStyle( 'display', 'none' );
  217. switchLockRatio( this, false ); // Unlock.
  218. };
  219. var numbering = function( id ) {
  220. return CKEDITOR.tools.getNextId() + '_' + id;
  221. },
  222. btnLockSizesId = numbering( 'btnLockSizes' ),
  223. btnResetSizeId = numbering( 'btnResetSize' ),
  224. imagePreviewLoaderId = numbering( 'ImagePreviewLoader' ),
  225. previewLinkId = numbering( 'previewLink' ),
  226. previewImageId = numbering( 'previewImage' );
  227. return {
  228. title: editor.lang.image[ dialogType == 'image' ? 'title' : 'titleButton' ],
  229. minWidth: ( CKEDITOR.skinName || editor.config.skin ) == 'moono-lisa' ? 500 : 420,
  230. minHeight: 360,
  231. getModel: function( editor ) {
  232. var element = editor.getSelection().getSelectedElement(),
  233. isImage = element && element.getName() === 'img',
  234. isImageInput = element && element.getName() === 'input' &&
  235. element.getAttribute( 'type' ) === 'image';
  236. if ( isImage ||isImageInput ) {
  237. return element;
  238. }
  239. return null;
  240. },
  241. onShow: function() {
  242. this.imageElement = false;
  243. this.linkElement = false;
  244. // Default: create a new element.
  245. this.imageEditMode = false;
  246. this.linkEditMode = false;
  247. this.lockRatio = true;
  248. this.userlockRatio = 0;
  249. this.dontResetSize = false;
  250. this.firstLoad = true;
  251. this.addLink = false;
  252. var editor = this.getParentEditor(),
  253. sel = editor.getSelection(),
  254. element = sel && sel.getSelectedElement(),
  255. link = element && editor.elementPath( element ).contains( 'a', 1 ),
  256. loader = CKEDITOR.document.getById( imagePreviewLoaderId );
  257. // Hide loader.
  258. if ( loader )
  259. loader.setStyle( 'display', 'none' );
  260. // Create the preview before setup the dialog contents.
  261. previewPreloader = new CKEDITOR.dom.element( 'img', editor.document );
  262. this.preview = CKEDITOR.document.getById( previewImageId );
  263. // Copy of the image
  264. this.originalElement = editor.document.createElement( 'img' );
  265. this.originalElement.setAttribute( 'alt', '' );
  266. this.originalElement.setCustomData( 'isReady', 'false' );
  267. if ( link ) {
  268. this.linkElement = link;
  269. this.linkEditMode = true;
  270. // If there is an existing link, by default keep it (true).
  271. // It will be removed if certain conditions are met and Link tab is enabled. (https://dev.ckeditor.com/ticket/13351)
  272. this.addLink = true;
  273. // Look for Image element.
  274. var linkChildren = link.getChildren();
  275. if ( linkChildren.count() == 1 ) {
  276. var childTag = linkChildren.getItem( 0 );
  277. if ( childTag.type == CKEDITOR.NODE_ELEMENT ) {
  278. if ( childTag.is( 'img' ) || childTag.is( 'input' ) ) {
  279. this.imageElement = linkChildren.getItem( 0 );
  280. if ( this.imageElement.is( 'img' ) )
  281. this.imageEditMode = 'img';
  282. else if ( this.imageElement.is( 'input' ) )
  283. this.imageEditMode = 'input';
  284. }
  285. }
  286. }
  287. // Fill out all fields.
  288. if ( dialogType == 'image' )
  289. this.setupContent( LINK, link );
  290. }
  291. // Edit given image element instead the one from selection.
  292. if ( this.customImageElement ) {
  293. this.imageEditMode = 'img';
  294. this.imageElement = this.customImageElement;
  295. delete this.customImageElement;
  296. }
  297. else if ( element && element.getName() == 'img' && !element.data( 'cke-realelement' ) ||
  298. element && element.getName() == 'input' && element.getAttribute( 'type' ) == 'image' ) {
  299. this.imageEditMode = element.getName();
  300. this.imageElement = element;
  301. }
  302. if ( this.imageEditMode ) {
  303. // Use the original element as a buffer from since we don't want
  304. // temporary changes to be committed, e.g. if the dialog is canceled.
  305. this.cleanImageElement = this.imageElement;
  306. this.imageElement = this.cleanImageElement.clone( true, true );
  307. // Fill out all fields.
  308. this.setupContent( IMAGE, this.imageElement );
  309. }
  310. // Refresh LockRatio button
  311. switchLockRatio( this, true );
  312. // Dont show preview if no URL given.
  313. if ( !CKEDITOR.tools.trim( this.getValueOf( 'info', 'txtUrl' ) ) ) {
  314. this.preview.removeAttribute( 'src' );
  315. this.preview.setStyle( 'display', 'none' );
  316. }
  317. },
  318. onOk: function() {
  319. // Edit existing Image.
  320. if ( this.imageEditMode ) {
  321. var imgTagName = this.imageEditMode;
  322. // Image dialog and Input element.
  323. if ( dialogType == 'image' && imgTagName == 'input' && confirm( editor.lang.image.button2Img ) ) { // jshint ignore:line
  324. // Replace INPUT-> IMG
  325. imgTagName = 'img';
  326. this.imageElement = editor.document.createElement( 'img' );
  327. this.imageElement.setAttribute( 'alt', '' );
  328. editor.insertElement( this.imageElement );
  329. }
  330. // ImageButton dialog and Image element.
  331. else if ( dialogType != 'image' && imgTagName == 'img' && confirm( editor.lang.image.img2Button ) ) { // jshint ignore:line
  332. // Replace IMG -> INPUT
  333. imgTagName = 'input';
  334. this.imageElement = editor.document.createElement( 'input' );
  335. this.imageElement.setAttributes( {
  336. type: 'image',
  337. alt: ''
  338. } );
  339. editor.insertElement( this.imageElement );
  340. } else {
  341. // Restore the original element before all commits.
  342. this.imageElement = this.cleanImageElement;
  343. delete this.cleanImageElement;
  344. }
  345. }
  346. // Create a new image.
  347. else {
  348. // Image dialog -> create IMG element.
  349. if ( dialogType == 'image' )
  350. this.imageElement = editor.document.createElement( 'img' );
  351. else {
  352. this.imageElement = editor.document.createElement( 'input' );
  353. this.imageElement.setAttribute( 'type', 'image' );
  354. }
  355. this.imageElement.setAttribute( 'alt', '' );
  356. }
  357. // Create a new link.
  358. if ( !this.linkEditMode )
  359. this.linkElement = editor.document.createElement( 'a' );
  360. // Set attributes.
  361. this.commitContent( IMAGE, this.imageElement );
  362. this.commitContent( LINK, this.linkElement );
  363. // Remove empty style attribute.
  364. if ( !this.imageElement.getAttribute( 'style' ) )
  365. this.imageElement.removeAttribute( 'style' );
  366. // Insert a new Image.
  367. if ( !this.imageEditMode ) {
  368. if ( this.addLink ) {
  369. if ( !this.linkEditMode ) {
  370. // Insert a new link.
  371. editor.insertElement( this.linkElement );
  372. this.linkElement.append( this.imageElement, false );
  373. } else {
  374. // We already have a link in editor.
  375. if ( this.linkElement.equals( editor.getSelection().getSelectedElement() ) ) {
  376. // If the link is selected outside, replace it's content rather than the link itself. ([<a>foo</a>])
  377. this.linkElement.setHtml( '' );
  378. this.linkElement.append( this.imageElement, false );
  379. } else {
  380. // Only inside of the link is selected, so replace it with image. (<a>[foo]</a>, <a>[f]oo</a>)
  381. editor.insertElement( this.imageElement );
  382. }
  383. }
  384. } else {
  385. editor.insertElement( this.imageElement );
  386. }
  387. }
  388. // Image already exists.
  389. else {
  390. // Add a new link element.
  391. if ( !this.linkEditMode && this.addLink ) {
  392. editor.insertElement( this.linkElement );
  393. this.imageElement.appendTo( this.linkElement );
  394. }
  395. // Remove Link, Image exists.
  396. else if ( this.linkEditMode && !this.addLink ) {
  397. editor.getSelection().selectElement( this.linkElement );
  398. editor.insertElement( this.imageElement );
  399. }
  400. }
  401. },
  402. onLoad: function() {
  403. if ( dialogType != 'image' )
  404. this.hidePage( 'Link' ); //Hide Link tab.
  405. var doc = this._.element.getDocument();
  406. if ( this.getContentElement( 'info', 'ratioLock' ) ) {
  407. this.addFocusable( doc.getById( btnResetSizeId ), 5 );
  408. this.addFocusable( doc.getById( btnLockSizesId ), 5 );
  409. }
  410. this.commitContent = commitContent;
  411. },
  412. onHide: function() {
  413. if ( this.preview )
  414. this.commitContent( CLEANUP, this.preview );
  415. if ( this.originalElement ) {
  416. this.originalElement.removeListener( 'load', onImgLoadEvent );
  417. this.originalElement.removeListener( 'error', onImgLoadErrorEvent );
  418. this.originalElement.removeListener( 'abort', onImgLoadErrorEvent );
  419. this.originalElement.remove();
  420. this.originalElement = false; // Dialog is closed.
  421. }
  422. delete this.imageElement;
  423. },
  424. contents: [ {
  425. id: 'info',
  426. label: editor.lang.image.infoTab,
  427. accessKey: 'I',
  428. elements: [ {
  429. type: 'vbox',
  430. padding: 0,
  431. children: [ {
  432. type: 'hbox',
  433. widths: [ '280px', '110px' ],
  434. align: 'right',
  435. className: 'cke_dialog_image_url',
  436. children: [ {
  437. id: 'txtUrl',
  438. type: 'text',
  439. label: editor.lang.common.url,
  440. required: true,
  441. onChange: function() {
  442. var dialog = this.getDialog(),
  443. newUrl = this.getValue();
  444. // Update original image.
  445. // Prevent from load before onShow.
  446. if ( newUrl.length > 0 ) {
  447. dialog = this.getDialog();
  448. var original = dialog.originalElement;
  449. if ( dialog.preview ) {
  450. dialog.preview.removeStyle( 'display' );
  451. }
  452. original.setCustomData( 'isReady', 'false' );
  453. // Show loader.
  454. var loader = CKEDITOR.document.getById( imagePreviewLoaderId );
  455. if ( loader )
  456. loader.setStyle( 'display', '' );
  457. original.on( 'load', onImgLoadEvent, dialog );
  458. original.on( 'error', onImgLoadErrorEvent, dialog );
  459. original.on( 'abort', onImgLoadErrorEvent, dialog );
  460. original.setAttribute( 'src', newUrl );
  461. if ( dialog.preview ) {
  462. // Query the preloader to figure out the url impacted by based href.
  463. previewPreloader.setAttribute( 'src', newUrl );
  464. dialog.preview.setAttribute( 'src', previewPreloader.$.src );
  465. updatePreview( dialog );
  466. }
  467. }
  468. // Dont show preview if no URL given.
  469. else if ( dialog.preview ) {
  470. dialog.preview.removeAttribute( 'src' );
  471. dialog.preview.setStyle( 'display', 'none' );
  472. }
  473. },
  474. setup: function( type, element ) {
  475. if ( type == IMAGE ) {
  476. var url = element.data( 'cke-saved-src' ) || element.getAttribute( 'src' );
  477. var field = this;
  478. this.getDialog().dontResetSize = true;
  479. field.setValue( url ); // And call this.onChange()
  480. // Manually set the initial value.(https://dev.ckeditor.com/ticket/4191)
  481. field.setInitValue();
  482. }
  483. },
  484. commit: function( type, element ) {
  485. if ( type == IMAGE && ( this.getValue() || this.isChanged() ) ) {
  486. element.data( 'cke-saved-src', this.getValue() );
  487. element.setAttribute( 'src', this.getValue() );
  488. } else if ( type == CLEANUP ) {
  489. element.setAttribute( 'src', '' ); // If removeAttribute doesn't work.
  490. element.removeAttribute( 'src' );
  491. }
  492. },
  493. validate: CKEDITOR.dialog.validate.notEmpty( editor.lang.image.urlMissing )
  494. },
  495. {
  496. type: 'button',
  497. id: 'browse',
  498. // v-align with the 'txtUrl' field.
  499. // TODO: We need something better than a fixed size here.
  500. style: 'display:inline-block;margin-top:14px;',
  501. align: 'center',
  502. label: editor.lang.common.browseServer,
  503. hidden: true,
  504. filebrowser: 'info:txtUrl'
  505. } ]
  506. } ]
  507. },
  508. {
  509. id: 'txtAlt',
  510. type: 'text',
  511. label: editor.lang.image.alt,
  512. accessKey: 'T',
  513. 'default': '',
  514. onChange: function() {
  515. updatePreview( this.getDialog() );
  516. },
  517. setup: function( type, element ) {
  518. if ( type == IMAGE )
  519. this.setValue( element.getAttribute( 'alt' ) );
  520. },
  521. commit: function( type, element ) {
  522. if ( type == IMAGE ) {
  523. if ( this.getValue() || this.isChanged() )
  524. element.setAttribute( 'alt', this.getValue() );
  525. } else if ( type == PREVIEW )
  526. element.setAttribute( 'alt', this.getValue() );
  527. else if ( type == CLEANUP ) {
  528. element.removeAttribute( 'alt' );
  529. }
  530. }
  531. },
  532. {
  533. type: 'hbox',
  534. children: [ {
  535. id: 'basic',
  536. type: 'vbox',
  537. children: [ {
  538. type: 'hbox',
  539. requiredContent: 'img{width,height}',
  540. widths: [ '50%', '50%' ],
  541. children: [ {
  542. type: 'vbox',
  543. padding: 1,
  544. children: [ {
  545. type: 'text',
  546. width: '45px',
  547. id: 'txtWidth',
  548. label: editor.lang.common.width,
  549. onKeyUp: onSizeChange,
  550. onChange: function() {
  551. commitInternally.call( this, 'advanced:txtdlgGenStyle' );
  552. },
  553. validate: function() {
  554. var aMatch = this.getValue().match( regexGetSizeOrEmpty ),
  555. isValid = !!( aMatch && parseInt( aMatch[ 1 ], 10 ) !== 0 );
  556. if ( !isValid )
  557. alert( editor.lang.common.invalidLength.replace( '%1', editor.lang.common.width ).replace( '%2', 'px, %' ) ); // jshint ignore:line
  558. return isValid;
  559. },
  560. setup: setupDimension,
  561. commit: function( type, element ) {
  562. var value = this.getValue();
  563. if ( type == IMAGE ) {
  564. if ( value && editor.activeFilter.check( 'img{width,height}' ) )
  565. element.setStyle( 'width', CKEDITOR.tools.cssLength( value ) );
  566. else
  567. element.removeStyle( 'width' );
  568. element.removeAttribute( 'width' );
  569. } else if ( type == PREVIEW ) {
  570. var aMatch = value.match( regexGetSize );
  571. if ( !aMatch ) {
  572. var oImageOriginal = this.getDialog().originalElement;
  573. if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' )
  574. element.setStyle( 'width', oImageOriginal.$.width + 'px' );
  575. } else {
  576. element.setStyle( 'width', CKEDITOR.tools.cssLength( value ) );
  577. }
  578. } else if ( type == CLEANUP ) {
  579. element.removeAttribute( 'width' );
  580. element.removeStyle( 'width' );
  581. }
  582. }
  583. },
  584. {
  585. type: 'text',
  586. id: 'txtHeight',
  587. width: '45px',
  588. label: editor.lang.common.height,
  589. onKeyUp: onSizeChange,
  590. onChange: function() {
  591. commitInternally.call( this, 'advanced:txtdlgGenStyle' );
  592. },
  593. validate: function() {
  594. var aMatch = this.getValue().match( regexGetSizeOrEmpty ),
  595. isValid = !!( aMatch && parseInt( aMatch[ 1 ], 10 ) !== 0 );
  596. if ( !isValid )
  597. alert( editor.lang.common.invalidLength.replace( '%1', editor.lang.common.height ).replace( '%2', 'px, %' ) ); // jshint ignore:line
  598. return isValid;
  599. },
  600. setup: setupDimension,
  601. commit: function( type, element ) {
  602. var value = this.getValue();
  603. if ( type == IMAGE ) {
  604. if ( value && editor.activeFilter.check( 'img{width,height}' ) )
  605. element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) );
  606. else
  607. element.removeStyle( 'height' );
  608. element.removeAttribute( 'height' );
  609. } else if ( type == PREVIEW ) {
  610. var aMatch = value.match( regexGetSize );
  611. if ( !aMatch ) {
  612. var oImageOriginal = this.getDialog().originalElement;
  613. if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' )
  614. element.setStyle( 'height', oImageOriginal.$.height + 'px' );
  615. } else {
  616. element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) );
  617. }
  618. } else if ( type == CLEANUP ) {
  619. element.removeAttribute( 'height' );
  620. element.removeStyle( 'height' );
  621. }
  622. }
  623. } ]
  624. },
  625. {
  626. id: 'ratioLock',
  627. type: 'html',
  628. className: 'cke_dialog_image_ratiolock',
  629. style: 'margin-top:30px;width:40px;height:40px;',
  630. onLoad: function() {
  631. // Activate Reset button
  632. var resetButton = CKEDITOR.document.getById( btnResetSizeId ),
  633. ratioButton = CKEDITOR.document.getById( btnLockSizesId );
  634. if ( resetButton ) {
  635. resetButton.on( 'click', function( evt ) {
  636. resetSize( this );
  637. evt.data && evt.data.preventDefault();
  638. }, this.getDialog() );
  639. resetButton.on( 'mouseover', function() {
  640. this.addClass( 'cke_btn_over' );
  641. }, resetButton );
  642. resetButton.on( 'mouseout', function() {
  643. this.removeClass( 'cke_btn_over' );
  644. }, resetButton );
  645. }
  646. // Activate (Un)LockRatio button
  647. if ( ratioButton ) {
  648. ratioButton.on( 'click', function( evt ) {
  649. switchLockRatio( this );
  650. var oImageOriginal = this.originalElement,
  651. width = this.getValueOf( 'info', 'txtWidth' );
  652. if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' && width ) {
  653. var height = oImageOriginal.$.height / oImageOriginal.$.width * width;
  654. if ( !isNaN( height ) ) {
  655. this.setValueOf( 'info', 'txtHeight', Math.round( height ) );
  656. updatePreview( this );
  657. }
  658. }
  659. evt.data && evt.data.preventDefault();
  660. }, this.getDialog() );
  661. ratioButton.on( 'mouseover', function() {
  662. this.addClass( 'cke_btn_over' );
  663. }, ratioButton );
  664. ratioButton.on( 'mouseout', function() {
  665. this.removeClass( 'cke_btn_over' );
  666. }, ratioButton );
  667. }
  668. },
  669. html: '<div>' +
  670. '<a href="javascript:void(0)" tabindex="-1" title="' + editor.lang.image.lockRatio +
  671. '" class="cke_btn_locked" id="' + btnLockSizesId + '" role="checkbox"><span class="cke_icon"></span><span class="cke_label">' + editor.lang.image.lockRatio + '</span></a>' +
  672. '<a href="javascript:void(0)" tabindex="-1" title="' + editor.lang.image.resetSize +
  673. '" class="cke_btn_reset" id="' + btnResetSizeId + '" role="button"><span class="cke_label">' + editor.lang.image.resetSize + '</span></a>' +
  674. '</div>'
  675. } ]
  676. },
  677. {
  678. type: 'vbox',
  679. padding: 1,
  680. children: [ {
  681. type: 'text',
  682. id: 'txtBorder',
  683. requiredContent: 'img{border-width}',
  684. width: '60px',
  685. label: editor.lang.image.border,
  686. 'default': '',
  687. onKeyUp: function() {
  688. updatePreview( this.getDialog() );
  689. },
  690. onChange: function() {
  691. commitInternally.call( this, 'advanced:txtdlgGenStyle' );
  692. },
  693. validate: CKEDITOR.dialog.validate.integer( editor.lang.image.validateBorder ),
  694. setup: function( type, element ) {
  695. if ( type == IMAGE ) {
  696. var value,
  697. borderStyle = element.getStyle( 'border-width' );
  698. borderStyle = borderStyle && borderStyle.match( /^(\d+px)(?: \1 \1 \1)?$/ );
  699. value = borderStyle && parseInt( borderStyle[ 1 ], 10 );
  700. isNaN( parseInt( value, 10 ) ) && ( value = element.getAttribute( 'border' ) );
  701. this.setValue( value );
  702. }
  703. },
  704. commit: function( type, element ) {
  705. var value = parseInt( this.getValue(), 10 );
  706. if ( type == IMAGE || type == PREVIEW ) {
  707. if ( !isNaN( value ) ) {
  708. element.setStyle( 'border-width', CKEDITOR.tools.cssLength( value ) );
  709. element.setStyle( 'border-style', 'solid' );
  710. } else if ( !value && this.isChanged() ) {
  711. element.removeStyle( 'border' );
  712. }
  713. if ( type == IMAGE )
  714. element.removeAttribute( 'border' );
  715. } else if ( type == CLEANUP ) {
  716. element.removeAttribute( 'border' );
  717. element.removeStyle( 'border-width' );
  718. element.removeStyle( 'border-style' );
  719. element.removeStyle( 'border-color' );
  720. }
  721. }
  722. },
  723. {
  724. type: 'text',
  725. id: 'txtHSpace',
  726. requiredContent: 'img{margin-left,margin-right}',
  727. width: '60px',
  728. label: editor.lang.image.hSpace,
  729. 'default': '',
  730. onKeyUp: function() {
  731. updatePreview( this.getDialog() );
  732. },
  733. onChange: function() {
  734. commitInternally.call( this, 'advanced:txtdlgGenStyle' );
  735. },
  736. validate: CKEDITOR.dialog.validate.integer( editor.lang.image.validateHSpace ),
  737. setup: function( type, element ) {
  738. if ( type == IMAGE ) {
  739. var value, marginLeftPx, marginRightPx,
  740. marginLeftStyle = element.getStyle( 'margin-left' ),
  741. marginRightStyle = element.getStyle( 'margin-right' );
  742. marginLeftStyle = marginLeftStyle && marginLeftStyle.match( pxLengthRegex );
  743. marginRightStyle = marginRightStyle && marginRightStyle.match( pxLengthRegex );
  744. marginLeftPx = parseInt( marginLeftStyle, 10 );
  745. marginRightPx = parseInt( marginRightStyle, 10 );
  746. value = ( marginLeftPx == marginRightPx ) && marginLeftPx;
  747. isNaN( parseInt( value, 10 ) ) && ( value = element.getAttribute( 'hspace' ) );
  748. this.setValue( value );
  749. }
  750. },
  751. commit: function( type, element ) {
  752. var value = parseInt( this.getValue(), 10 );
  753. if ( type == IMAGE || type == PREVIEW ) {
  754. if ( !isNaN( value ) ) {
  755. element.setStyle( 'margin-left', CKEDITOR.tools.cssLength( value ) );
  756. element.setStyle( 'margin-right', CKEDITOR.tools.cssLength( value ) );
  757. } else if ( !value && this.isChanged() ) {
  758. element.removeStyle( 'margin-left' );
  759. element.removeStyle( 'margin-right' );
  760. }
  761. if ( type == IMAGE )
  762. element.removeAttribute( 'hspace' );
  763. } else if ( type == CLEANUP ) {
  764. element.removeAttribute( 'hspace' );
  765. element.removeStyle( 'margin-left' );
  766. element.removeStyle( 'margin-right' );
  767. }
  768. }
  769. },
  770. {
  771. type: 'text',
  772. id: 'txtVSpace',
  773. requiredContent: 'img{margin-top,margin-bottom}',
  774. width: '60px',
  775. label: editor.lang.image.vSpace,
  776. 'default': '',
  777. onKeyUp: function() {
  778. updatePreview( this.getDialog() );
  779. },
  780. onChange: function() {
  781. commitInternally.call( this, 'advanced:txtdlgGenStyle' );
  782. },
  783. validate: CKEDITOR.dialog.validate.integer( editor.lang.image.validateVSpace ),
  784. setup: function( type, element ) {
  785. if ( type == IMAGE ) {
  786. var value, marginTopPx, marginBottomPx,
  787. marginTopStyle = element.getStyle( 'margin-top' ),
  788. marginBottomStyle = element.getStyle( 'margin-bottom' );
  789. marginTopStyle = marginTopStyle && marginTopStyle.match( pxLengthRegex );
  790. marginBottomStyle = marginBottomStyle && marginBottomStyle.match( pxLengthRegex );
  791. marginTopPx = parseInt( marginTopStyle, 10 );
  792. marginBottomPx = parseInt( marginBottomStyle, 10 );
  793. value = ( marginTopPx == marginBottomPx ) && marginTopPx;
  794. isNaN( parseInt( value, 10 ) ) && ( value = element.getAttribute( 'vspace' ) );
  795. this.setValue( value );
  796. }
  797. },
  798. commit: function( type, element ) {
  799. var value = parseInt( this.getValue(), 10 );
  800. if ( type == IMAGE || type == PREVIEW ) {
  801. if ( !isNaN( value ) ) {
  802. element.setStyle( 'margin-top', CKEDITOR.tools.cssLength( value ) );
  803. element.setStyle( 'margin-bottom', CKEDITOR.tools.cssLength( value ) );
  804. } else if ( !value && this.isChanged() ) {
  805. element.removeStyle( 'margin-top' );
  806. element.removeStyle( 'margin-bottom' );
  807. }
  808. if ( type == IMAGE )
  809. element.removeAttribute( 'vspace' );
  810. } else if ( type == CLEANUP ) {
  811. element.removeAttribute( 'vspace' );
  812. element.removeStyle( 'margin-top' );
  813. element.removeStyle( 'margin-bottom' );
  814. }
  815. }
  816. },
  817. {
  818. id: 'cmbAlign',
  819. requiredContent: 'img{float}',
  820. type: 'select',
  821. widths: [ '35%', '65%' ],
  822. style: 'width:90px',
  823. label: editor.lang.common.align,
  824. 'default': '',
  825. items: [
  826. [ editor.lang.common.notSet, '' ],
  827. [ editor.lang.common.left, 'left' ],
  828. [ editor.lang.common.right, 'right' ]
  829. // Backward compatible with v2 on setup when specified as attribute value,
  830. // while these values are no more available as select options.
  831. // [ editor.lang.image.alignAbsBottom , 'absBottom'],
  832. // [ editor.lang.image.alignAbsMiddle , 'absMiddle'],
  833. // [ editor.lang.image.alignBaseline , 'baseline'],
  834. // [ editor.lang.image.alignTextTop , 'text-top'],
  835. // [ editor.lang.image.alignBottom , 'bottom'],
  836. // [ editor.lang.image.alignMiddle , 'middle'],
  837. // [ editor.lang.image.alignTop , 'top']
  838. ],
  839. onChange: function() {
  840. updatePreview( this.getDialog() );
  841. commitInternally.call( this, 'advanced:txtdlgGenStyle' );
  842. },
  843. setup: function( type, element ) {
  844. if ( type == IMAGE ) {
  845. var value = element.getStyle( 'float' );
  846. switch ( value ) {
  847. // Ignore those unrelated values.
  848. case 'inherit':
  849. case 'none':
  850. value = '';
  851. }
  852. !value && ( value = ( element.getAttribute( 'align' ) || '' ).toLowerCase() );
  853. this.setValue( value );
  854. }
  855. },
  856. commit: function( type, element ) {
  857. var value = this.getValue();
  858. if ( type == IMAGE || type == PREVIEW ) {
  859. if ( value )
  860. element.setStyle( 'float', value );
  861. else
  862. element.removeStyle( 'float' );
  863. if ( type == IMAGE ) {
  864. value = ( element.getAttribute( 'align' ) || '' ).toLowerCase();
  865. switch ( value ) {
  866. // we should remove it only if it matches "left" or "right",
  867. // otherwise leave it intact.
  868. case 'left':
  869. case 'right':
  870. element.removeAttribute( 'align' );
  871. }
  872. }
  873. } else if ( type == CLEANUP ) {
  874. element.removeStyle( 'float' );
  875. }
  876. }
  877. } ]
  878. } ]
  879. },
  880. {
  881. type: 'vbox',
  882. height: '250px',
  883. children: [ {
  884. type: 'html',
  885. id: 'htmlPreview',
  886. style: 'width:95%;',
  887. html: '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.common.preview ) + '<br>' +
  888. '<div id="' + imagePreviewLoaderId + '" class="ImagePreviewLoader" style="display:none"><div class="loading"></div></div>' +
  889. '<div class="ImagePreviewBox"><table><tr><td>' +
  890. '<a href="javascript:void(0)" target="_blank" onclick="return false;" id="' + previewLinkId + '">' +
  891. '<img id="' + previewImageId + '" alt="" /></a>' +
  892. // jscs:disable maximumLineLength
  893. ( editor.config.image_previewText || 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ' +
  894. 'Maecenas feugiat consequat diam. Maecenas metus. Vivamus diam purus, cursus a, commodo non, facilisis vitae, ' +
  895. 'nulla. Aenean dictum lacinia tortor. Nunc iaculis, nibh non iaculis aliquam, orci felis euismod neque, sed ornare massa mauris sed velit. Nulla pretium mi et risus. Fusce mi pede, tempor id, cursus ac, ullamcorper nec, enim. Sed tortor. Curabitur molestie. Duis velit augue, condimentum at, ultrices a, luctus ut, orci. Donec pellentesque egestas eros. Integer cursus, augue in cursus faucibus, eros pede bibendum sem, in tempus tellus justo quis ligula. Etiam eget tortor. Vestibulum rutrum, est ut placerat elementum, lectus nisl aliquam velit, tempor aliquam eros nunc nonummy metus. In eros metus, gravida a, gravida sed, lobortis id, turpis. Ut ultrices, ipsum at venenatis fringilla, sem nulla lacinia tellus, eget aliquet turpis mauris non enim. Nam turpis. Suspendisse lacinia. Curabitur ac tortor ut ipsum egestas elementum. Nunc imperdiet gravida mauris.' ) +
  896. // jscs:enable maximumLineLength
  897. '</td></tr></table></div></div>'
  898. } ]
  899. } ]
  900. } ]
  901. },
  902. {
  903. id: 'Link',
  904. requiredContent: 'a[href]',
  905. label: editor.lang.image.linkTab,
  906. padding: 0,
  907. elements: [ {
  908. id: 'txtUrl',
  909. type: 'text',
  910. label: editor.lang.common.url,
  911. style: 'width: 100%',
  912. 'default': '',
  913. setup: function( type, element ) {
  914. if ( type == LINK ) {
  915. var href = element.data( 'cke-saved-href' );
  916. if ( !href )
  917. href = element.getAttribute( 'href' );
  918. this.setValue( href );
  919. }
  920. },
  921. commit: function( type, element ) {
  922. if ( type == LINK ) {
  923. if ( this.getValue() || this.isChanged() ) {
  924. var url = this.getValue();
  925. element.data( 'cke-saved-href', url );
  926. element.setAttribute( 'href', url );
  927. if ( this.getValue() || !editor.config.image_removeLinkByEmptyURL )
  928. this.getDialog().addLink = true;
  929. else
  930. this.getDialog().addLink = false;
  931. }
  932. }
  933. }
  934. },
  935. {
  936. type: 'button',
  937. id: 'browse',
  938. className: 'cke_dialog_image_browse',
  939. filebrowser: {
  940. action: 'Browse',
  941. target: 'Link:txtUrl',
  942. url: editor.config.filebrowserImageBrowseLinkUrl
  943. },
  944. style: 'float:right',
  945. hidden: true,
  946. label: editor.lang.common.browseServer
  947. },
  948. {
  949. id: 'cmbTarget',
  950. type: 'select',
  951. requiredContent: 'a[target]',
  952. label: editor.lang.common.target,
  953. 'default': '',
  954. items: [
  955. [ editor.lang.common.notSet, '' ],
  956. [ editor.lang.common.targetNew, '_blank' ],
  957. [ editor.lang.common.targetTop, '_top' ],
  958. [ editor.lang.common.targetSelf, '_self' ],
  959. [ editor.lang.common.targetParent, '_parent' ]
  960. ],
  961. setup: function( type, element ) {
  962. if ( type == LINK )
  963. this.setValue( element.getAttribute( 'target' ) || '' );
  964. },
  965. commit: function( type, element ) {
  966. if ( type == LINK ) {
  967. if ( this.getValue() || this.isChanged() )
  968. element.setAttribute( 'target', this.getValue() );
  969. }
  970. }
  971. } ]
  972. },
  973. {
  974. id: 'Upload',
  975. hidden: true,
  976. filebrowser: 'uploadButton',
  977. label: editor.lang.image.upload,
  978. elements: [
  979. {
  980. type: 'file',
  981. id: 'upload',
  982. label: editor.lang.image.btnUpload,
  983. style: 'height:40px',
  984. size: 38
  985. },
  986. {
  987. type: 'fileButton',
  988. id: 'uploadButton',
  989. filebrowser: 'info:txtUrl',
  990. label: editor.lang.image.btnUpload,
  991. 'for': [ 'Upload', 'upload' ]
  992. },
  993. {
  994. type: 'button',
  995. id: 'selectfile',
  996. label: '选择服务器文件',
  997. size: 38,
  998. onClick: function () {
  999. var w = 800;
  1000. var h = 600;
  1001. var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
  1002. var dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
  1003. var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
  1004. var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
  1005. var systemZoom = width / window.screen.availWidth;
  1006. var posLeft = (width - w) / 2 / systemZoom + dualScreenLeft;
  1007. var posTop = (height - h) / 2 / systemZoom + dualScreenTop;
  1008. window.open("./dialog/select_images.php?iseditor=1&f="+editor.name, "popUpImagesWin", "scrollbars=yes,resizable=yes,statebar=no,width=800,height=600,left=" + posLeft + ", top=" + posTop);
  1009. CKEDITOR.dialog.getCurrent().hide();
  1010. }
  1011. },
  1012. ]
  1013. },
  1014. {
  1015. id: 'advanced',
  1016. label: editor.lang.common.advancedTab,
  1017. elements: [ {
  1018. type: 'hbox',
  1019. widths: [ '50%', '25%', '25%' ],
  1020. children: [ {
  1021. type: 'text',
  1022. id: 'linkId',
  1023. requiredContent: 'img[id]',
  1024. label: editor.lang.common.id,
  1025. setup: function( type, element ) {
  1026. if ( type == IMAGE )
  1027. this.setValue( element.getAttribute( 'id' ) );
  1028. },
  1029. commit: function( type, element ) {
  1030. if ( type == IMAGE ) {
  1031. if ( this.getValue() || this.isChanged() )
  1032. element.setAttribute( 'id', this.getValue() );
  1033. }
  1034. }
  1035. },
  1036. {
  1037. id: 'cmbLangDir',
  1038. type: 'select',
  1039. requiredContent: 'img[dir]',
  1040. style: 'width : 100px;',
  1041. label: editor.lang.common.langDir,
  1042. 'default': '',
  1043. items: [
  1044. [ editor.lang.common.notSet, '' ],
  1045. [ editor.lang.common.langDirLtr, 'ltr' ],
  1046. [ editor.lang.common.langDirRtl, 'rtl' ]
  1047. ],
  1048. setup: function( type, element ) {
  1049. if ( type == IMAGE )
  1050. this.setValue( element.getAttribute( 'dir' ) );
  1051. },
  1052. commit: function( type, element ) {
  1053. if ( type == IMAGE ) {
  1054. if ( this.getValue() || this.isChanged() )
  1055. element.setAttribute( 'dir', this.getValue() );
  1056. }
  1057. }
  1058. },
  1059. {
  1060. type: 'text',
  1061. id: 'txtLangCode',
  1062. requiredContent: 'img[lang]',
  1063. label: editor.lang.common.langCode,
  1064. 'default': '',
  1065. setup: function( type, element ) {
  1066. if ( type == IMAGE )
  1067. this.setValue( element.getAttribute( 'lang' ) );
  1068. },
  1069. commit: function( type, element ) {
  1070. if ( type == IMAGE ) {
  1071. if ( this.getValue() || this.isChanged() )
  1072. element.setAttribute( 'lang', this.getValue() );
  1073. }
  1074. }
  1075. } ]
  1076. },
  1077. {
  1078. type: 'text',
  1079. id: 'txtGenLongDescr',
  1080. requiredContent: 'img[longdesc]',
  1081. label: editor.lang.common.longDescr,
  1082. setup: function( type, element ) {
  1083. if ( type == IMAGE )
  1084. this.setValue( element.getAttribute( 'longDesc' ) );
  1085. },
  1086. commit: function( type, element ) {
  1087. if ( type == IMAGE ) {
  1088. if ( this.getValue() || this.isChanged() )
  1089. element.setAttribute( 'longDesc', this.getValue() );
  1090. }
  1091. }
  1092. },
  1093. {
  1094. type: 'hbox',
  1095. widths: [ '50%', '50%' ],
  1096. children: [ {
  1097. type: 'text',
  1098. id: 'txtGenClass',
  1099. requiredContent: 'img(cke-xyz)', // Random text like 'xyz' will check if all are allowed.
  1100. label: editor.lang.common.cssClass,
  1101. 'default': '',
  1102. setup: function( type, element ) {
  1103. if ( type == IMAGE )
  1104. this.setValue( element.getAttribute( 'class' ) );
  1105. },
  1106. commit: function( type, element ) {
  1107. if ( type == IMAGE ) {
  1108. if ( this.getValue() || this.isChanged() )
  1109. element.setAttribute( 'class', this.getValue() );
  1110. }
  1111. }
  1112. },
  1113. {
  1114. type: 'text',
  1115. id: 'txtGenTitle',
  1116. requiredContent: 'img[title]',
  1117. label: editor.lang.common.advisoryTitle,
  1118. 'default': '',
  1119. onChange: function() {
  1120. updatePreview( this.getDialog() );
  1121. },
  1122. setup: function( type, element ) {
  1123. if ( type == IMAGE )
  1124. this.setValue( element.getAttribute( 'title' ) );
  1125. },
  1126. commit: function( type, element ) {
  1127. if ( type == IMAGE ) {
  1128. if ( this.getValue() || this.isChanged() )
  1129. element.setAttribute( 'title', this.getValue() );
  1130. } else if ( type == PREVIEW )
  1131. element.setAttribute( 'title', this.getValue() );
  1132. else if ( type == CLEANUP ) {
  1133. element.removeAttribute( 'title' );
  1134. }
  1135. }
  1136. } ]
  1137. },
  1138. {
  1139. type: 'text',
  1140. id: 'txtdlgGenStyle',
  1141. requiredContent: 'img{cke-xyz}', // Random text like 'xyz' will check if all are allowed.
  1142. label: editor.lang.common.cssStyle,
  1143. validate: CKEDITOR.dialog.validate.inlineStyle( editor.lang.common.invalidInlineStyle ),
  1144. 'default': '',
  1145. setup: function( type, element ) {
  1146. if ( type == IMAGE ) {
  1147. var genStyle = element.getAttribute( 'style' );
  1148. if ( !genStyle && element.$.style.cssText )
  1149. genStyle = element.$.style.cssText;
  1150. this.setValue( genStyle );
  1151. var height = element.$.style.height,
  1152. width = element.$.style.width,
  1153. aMatchH = ( height ? height : '' ).match( regexGetSize ),
  1154. aMatchW = ( width ? width : '' ).match( regexGetSize );
  1155. this.attributesInStyle = {
  1156. height: !!aMatchH,
  1157. width: !!aMatchW
  1158. };
  1159. }
  1160. },
  1161. onChange: function() {
  1162. commitInternally.call(
  1163. this, [
  1164. 'info:cmbFloat',
  1165. 'info:cmbAlign',
  1166. 'info:txtVSpace',
  1167. 'info:txtHSpace',
  1168. 'info:txtBorder',
  1169. 'info:txtWidth',
  1170. 'info:txtHeight'
  1171. ]
  1172. );
  1173. updatePreview( this );
  1174. },
  1175. commit: function( type, element ) {
  1176. if ( type == IMAGE && ( this.getValue() || this.isChanged() ) )
  1177. element.setAttribute( 'style', this.getValue() );
  1178. }
  1179. } ]
  1180. } ]
  1181. };
  1182. };
  1183. CKEDITOR.dialog.add( 'image', function( editor ) {
  1184. return imageDialog( editor, 'image' );
  1185. } );
  1186. CKEDITOR.dialog.add( 'imagebutton', function( editor ) {
  1187. return imageDialog( editor, 'imagebutton' );
  1188. } );
  1189. } )();