Ticket #4246: 4246_5.patch
File 4246_5.patch, 24.2 KB (added by , 14 years ago) |
---|
-
_source/core/dom/element.js
433 433 return attrValue ? 'checked' : null; 434 434 } 435 435 436 case 'hspace': 437 return this.$.hspace; 438 436 439 case 'style': 437 440 // IE does not return inline styles via getAttribute(). See #2947. 438 441 return this.$.style.cssText; … … 998 1001 */ 999 1002 removeStyle : function( name ) 1000 1003 { 1001 if ( this.$.style.removeAttribute ) 1002 this.$.style.removeAttribute( CKEDITOR.tools.cssStyleToDomStyle( name ) ); 1003 else 1004 this.setStyle( name, '' ); 1004 this.setStyle( name, '' ); 1005 1005 1006 1006 if ( !this.$.style.cssText ) 1007 1007 this.removeAttribute( 'style' ); -
_source/lang/en.js
385 385 vSpace : 'VSpace', 386 386 align : 'Align', 387 387 alignLeft : 'Left', 388 alignAbsBottom: 'Abs Bottom',389 alignAbsMiddle: 'Abs Middle',390 alignBaseline : 'Baseline',391 alignBottom : 'Bottom',392 alignMiddle : 'Middle',393 388 alignRight : 'Right', 394 alignTextTop : 'Text Top',395 alignTop : 'Top',396 389 preview : 'Preview', 397 390 alertUrl : 'Please type the image URL', 398 391 linkTab : 'Link', -
_source/plugins/image/dialogs/image.js
11 11 PREVIEW = 4, 12 12 CLEANUP = 8, 13 13 regexGetSize = /^\s*(\d+)((px)|\%)?\s*$/i, 14 regexGetSizeOrEmpty = /(^\s*(\d+)((px)|\%)?\s*$)|^$/i; 14 regexGetSizeOrEmpty = /(^\s*(\d+)((px)|\%)?\s*$)|^$/i, 15 pxLengthRegex = /^\d+px$/; 15 16 16 17 var onSizeChange = function() 17 18 { … … 61 62 return 0; 62 63 }; 63 64 65 // Avoid recursions. 66 var incommit; 67 // Commit the 68 function commitInternally( targetFields ) 69 { 70 if( incommit ) 71 return; 72 73 incommit = 1; 74 75 var dialog = this.getDialog(), 76 element = dialog.imageElement; 77 if( element ) 78 { 79 // Commit this field and broadcast to target fields. 80 this.commit( IMAGE, element ); 81 82 targetFields = [].concat( targetFields ); 83 var length = targetFields.length, 84 field; 85 for ( var i = 0; i < length; i++ ) 86 { 87 field = dialog.getContentElement.apply( dialog, targetFields[ i ].split( ':' ) ); 88 // May cause recursion. 89 field && field.setup( IMAGE, element ); 90 } 91 } 92 93 incommit = 0; 94 } 95 64 96 var switchLockRatio = function( dialog, value ) 65 97 { 66 98 var oImageOriginal = dialog.originalElement, … … 105 137 var oImageOriginal = dialog.originalElement; 106 138 if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' ) 107 139 { 108 dialog.setValueOf( 'info', 'txtWidth', oImageOriginal.$.width ); 109 dialog.setValueOf( 'info', 'txtHeight', oImageOriginal.$.height ); 140 var widthField = dialog.getContentElement( 'info', 'txtWidth' ), 141 heightField = dialog.getContentElement( 'info', 'txtHeight' ); 142 143 widthField.setValue( oImageOriginal.$.width ); 144 heightField.setValue( oImageOriginal.$.height ); 145 commitInternally.call( widthField, 'advanced:txtdlgGenStyle' ); 146 commitInternally.call( heightField, 'advanced:txtdlgGenStyle' ); 110 147 } 111 148 updatePreview( dialog ); 112 149 }; … … 138 175 139 176 if ( size ) 140 177 value = checkDimension( size, value ); 141 value = checkDimension( element. $.style[ dimension ], value );178 value = checkDimension( element.getStyle( dimension ), value ); 142 179 143 180 this.setValue( value ); 144 181 }; … … 242 279 this.setupContent( LINK, link ); 243 280 } 244 281 245 if ( element && element.getName() == 'img' && !element.getAttribute( '_cke_realelement' ) ) 246 this.imageEditMode = 'img'; 247 else if ( element && element.getName() == 'input' && element.getAttribute( 'type' ) && element.getAttribute( 'type' ) == 'image' ) 248 this.imageEditMode = 'input'; 249 250 if ( this.imageEditMode || this.imageElement ) 282 if ( element && element.getName() == 'img' && !element.getAttribute( '_cke_realelement' ) 283 || element && element.getName() == 'input' && element.getAttribute( 'type' ) == 'image' ) 251 284 { 252 if ( !this.imageElement ) 253 this.imageElement = element; 285 this.imageEditMode = element.getName(); 286 this.imageElement = element; 287 } 254 288 289 if ( this.imageEditMode ) 290 { 291 // Use the original element as a buffer from since we don't want 292 // temporary changes to be committed, e.g. if the dialog is canceled. 293 this.cleanImageElement = this.imageElement; 294 this.imageElement = this.cleanImageElement.clone( true, true ); 295 255 296 // Fill out all fields. 256 297 this.setupContent( IMAGE, this.imageElement ); 257 298 258 299 // Refresh LockRatio button 259 300 switchLockRatio ( this, true ); 260 301 } 302 else 303 this.imageElement = editor.document.createElement( 'img' ); 261 304 262 305 // Dont show preview if no URL given. 263 306 if ( !CKEDITOR.tools.trim( this.getValueOf( 'info', 'txtUrl' ) ) ) … … 296 339 ); 297 340 editor.insertElement( this.imageElement ); 298 341 } 299 } 342 else 343 { 344 // Restore the original element before all commits. 345 this.imageElement = this.cleanImageElement; 346 delete this.cleanImageElement; 347 } 348 } 300 349 else // Create a new image. 301 350 { 302 351 // Image dialog -> create IMG element. … … 318 367 this.commitContent( IMAGE, this.imageElement ); 319 368 this.commitContent( LINK, this.linkElement ); 320 369 370 // Remove empty style attribute. 371 if( !this.imageElement.getAttribute( 'style' ) ) 372 this.imageElement.removeAttribute( 'style' ); 373 321 374 // Insert a new Image. 322 375 if ( !this.imageEditMode ) 323 376 { … … 372 425 this.originalElement.remove(); 373 426 this.originalElement = false; // Dialog is closed. 374 427 } 428 429 delete this.imageElement; 375 430 }, 376 431 contents : [ 377 432 { … … 533 588 id : 'txtWidth', 534 589 labelLayout : 'horizontal', 535 590 label : editor.lang.image.width, 536 onKeyUp : onSizeChange, 591 onKeyUp : function() 592 { 593 onSizeChange.apply( this, arguments ); 594 commitInternally.call( this, 'advanced:txtdlgGenStyle' ); 595 }, 537 596 validate: function() 538 597 { 539 598 var aMatch = this.getValue().match( regexGetSizeOrEmpty ); … … 542 601 return !!aMatch; 543 602 }, 544 603 setup : setupDimension, 545 commit : function( type, element )604 commit : function( type, element, internalCommit ) 546 605 { 606 var value = this.getValue(); 547 607 if ( type == IMAGE ) 548 608 { 549 var value = this.getValue();550 609 if ( value ) 551 element.setAttribute( 'width', value ); 552 else if ( !value && this.isChanged() ) 553 element.removeAttribute( 'width' ); 610 element.setStyle( 'width', CKEDITOR.tools.cssLength( value ) ); 611 else if ( !value && this.isChanged( ) ) 612 element.removeStyle( 'width' ); 613 614 !internalCommit && element.removeAttribute( 'width' ); 554 615 } 555 616 else if ( type == PREVIEW ) 556 617 { 557 value = this.getValue();558 618 var aMatch = value.match( regexGetSize ); 559 619 if ( !aMatch ) 560 620 { … … 567 627 } 568 628 else if ( type == CLEANUP ) 569 629 { 570 element.setStyle( 'width', '0px' ); // If removeAttribute doesn't work.571 630 element.removeAttribute( 'width' ); 572 631 element.removeStyle( 'width' ); 573 632 } … … 579 638 width: '40px', 580 639 labelLayout : 'horizontal', 581 640 label : editor.lang.image.height, 582 onKeyUp : onSizeChange, 641 onKeyUp : function() 642 { 643 onSizeChange.apply( this, arguments ); 644 commitInternally.call( this, 'advanced:txtdlgGenStyle' ); 645 }, 583 646 validate: function() 584 647 { 585 648 var aMatch = this.getValue().match( regexGetSizeOrEmpty ); … … 588 651 return !!aMatch; 589 652 }, 590 653 setup : setupDimension, 591 commit : function( type, element )654 commit : function( type, element, internalCommit ) 592 655 { 656 var value = this.getValue(); 593 657 if ( type == IMAGE ) 594 658 { 595 var value = this.getValue();596 659 if ( value ) 597 element.setAttribute( 'height', value ); 598 else if ( !value && this.isChanged() ) 660 element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) ); 661 else if ( !value && this.isChanged( ) ) 662 element.removeStyle( 'height' ); 663 664 if( !internalCommit && type == IMAGE ) 599 665 element.removeAttribute( 'height' ); 600 666 } 601 667 else if ( type == PREVIEW ) 602 668 { 603 value = this.getValue();604 669 var aMatch = value.match( regexGetSize ); 605 670 if ( !aMatch ) 606 671 { 607 672 var oImageOriginal = this.getDialog().originalElement; 608 673 if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' ) 609 element.setStyle( 'height', oImageOriginal.$.height + 'px');674 element.setStyle( 'height', oImageOriginal.$.height + 'px' ); 610 675 } 611 676 else 612 element.setStyle( 'height', value + 'px' );677 element.setStyle( 'height', value + 'px' ); 613 678 } 614 679 else if ( type == CLEANUP ) 615 680 { 616 element.setStyle( 'height', '0px' ); // If removeAttribute doesn't work.617 681 element.removeAttribute( 'height' ); 618 682 element.removeStyle( 'height' ); 619 683 } … … 697 761 onKeyUp : function() 698 762 { 699 763 updatePreview( this.getDialog() ); 764 commitInternally.call( this, 'advanced:txtdlgGenStyle' ); 700 765 }, 701 766 validate: function() 702 767 { … … 706 771 setup : function( type, element ) 707 772 { 708 773 if ( type == IMAGE ) 709 this.setValue( element.getAttribute( 'border' ) ); 774 { 775 var value, 776 borderStyle = element.getStyle( 'border-width' ); 777 778 borderStyle = borderStyle && borderStyle.match( /^(\d+px)(?: \1 \1 \1)?$/ ); 779 value = borderStyle && parseInt( borderStyle[ 1 ] ); 780 !value && ( value = element.getAttribute( 'border' ) ); 781 782 this.setValue( value ); 783 } 710 784 }, 711 commit : function( type, element )785 commit : function( type, element, internalCommit ) 712 786 { 713 if ( type == IMAGE ) 787 var value = parseInt( this.getValue() ); 788 if ( type == IMAGE || type == PREVIEW ) 714 789 { 715 if ( this.getValue() || this.isChanged() ) 716 element.setAttribute( 'border', this.getValue() ); 717 } 718 else if ( type == PREVIEW ) 719 { 720 var value = parseInt( this.getValue(), 10 ); 721 value = isNaN( value ) ? 0 : value; 722 element.setAttribute( 'border', value ); 723 element.setStyle( 'border', value + 'px solid black' ); 724 } 790 if ( value ) 791 element.setStyle( 'border', CKEDITOR.tools.cssLength( value ) + ' solid' ); 792 else if ( !value && this.isChanged() ) 793 { 794 if( CKEDITOR.env.ie ) 795 { 796 element.removeStyle( 'border-width' ); 797 element.removeStyle( 'border-style' ); 798 element.removeStyle( 'border-color' ); 799 } 800 else 801 element.removeStyle( 'border' ); 802 } 803 804 if( !internalCommit && type == IMAGE ) 805 element.removeAttribute( 'border' ); 806 } 725 807 else if ( type == CLEANUP ) 726 808 { 727 809 element.removeAttribute( 'border' ); … … 739 821 onKeyUp : function() 740 822 { 741 823 updatePreview( this.getDialog() ); 824 commitInternally.call( this, 'advanced:txtdlgGenStyle' ); 742 825 }, 743 826 validate: function() 744 827 { … … 749 832 { 750 833 if ( type == IMAGE ) 751 834 { 752 var value = element.getAttribute( 'hspace' ); 753 if ( value != -1 ) // In IE empty = -1. 754 this.setValue( value ); 835 var value, 836 marginLeftPx, 837 marginRightPx, 838 marginLeftStyle = element.getStyle( 'margin-left' ), 839 marginRightStyle = element.getStyle( 'margin-right' ); 840 841 marginLeftStyle = marginLeftStyle && marginLeftStyle.match( pxLengthRegex ); 842 marginRightStyle = marginRightStyle && marginRightStyle.match( pxLengthRegex ); 843 marginLeftPx = parseInt( marginLeftStyle ); 844 marginRightPx = parseInt( marginRightStyle ); 845 846 value = ( marginLeftPx == marginRightPx ) && marginLeftPx; 847 !value && ( value = element.getAttribute( 'hspace' ) ); 848 849 this.setValue( value ); 755 850 } 756 851 }, 757 commit : function( type, element )852 commit : function( type, element, internalCommit ) 758 853 { 759 if ( type == IMAGE ) 854 var value = parseInt( this.getValue() ); 855 if ( type == IMAGE || type == PREVIEW ) 760 856 { 761 if ( this.getValue() || this.isChanged() ) 762 element.setAttribute( 'hspace', this.getValue() ); 763 } 764 else if ( type == PREVIEW ) 765 { 766 var value = parseInt( this.getValue(), 10 ); 767 value = isNaN( value ) ? 0 : value; 768 element.setAttribute( 'hspace', value ); 769 element.setStyle( 'margin-left', value + 'px' ); 770 element.setStyle( 'margin-right', value + 'px' ); 771 } 857 if ( value ) 858 { 859 element.setStyle( 'margin-left', CKEDITOR.tools.cssLength( value ) ); 860 element.setStyle( 'margin-right', CKEDITOR.tools.cssLength( value ) ); 861 } 862 else if ( !value && this.isChanged( ) ) 863 { 864 element.removeStyle( 'margin-left' ); 865 element.removeStyle( 'margin-right' ); 866 } 867 868 if( !internalCommit && type == IMAGE ) 869 element.removeAttribute( 'hspace' ); 870 } 772 871 else if ( type == CLEANUP ) 773 872 { 774 873 element.removeAttribute( 'hspace' ); … … 787 886 onKeyUp : function() 788 887 { 789 888 updatePreview( this.getDialog() ); 889 commitInternally.call( this, 'advanced:txtdlgGenStyle' ); 790 890 }, 791 891 validate: function() 792 892 { … … 796 896 setup : function( type, element ) 797 897 { 798 898 if ( type == IMAGE ) 799 this.setValue( element.getAttribute( 'vspace' ) ); 899 { 900 var value, 901 marginTopPx, 902 marginBottomPx, 903 marginTopStyle = element.getStyle( 'margin-top' ), 904 marginBottomStyle = element.getStyle( 'margin-bottom' ); 905 906 marginTopStyle = marginTopStyle && marginTopStyle.match( pxLengthRegex ); 907 marginBottomStyle = marginBottomStyle && marginBottomStyle.match( pxLengthRegex ); 908 marginTopPx = parseInt( marginTopStyle ); 909 marginBottomPx = parseInt( marginBottomStyle ); 910 911 value = ( marginTopPx == marginBottomPx ) && marginTopPx; 912 !value && ( value = element.getAttribute( 'vspace' ) ); 913 this.setValue( value ); 914 } 800 915 }, 801 commit : function( type, element )916 commit : function( type, element, internalCommit ) 802 917 { 803 if ( type == IMAGE ) 918 var value = parseInt( this.getValue() ); 919 if ( type == IMAGE || type == PREVIEW ) 804 920 { 805 if ( this.getValue() || this.isChanged() ) 806 element.setAttribute( 'vspace', this.getValue() ); 807 } 808 else if ( type == PREVIEW ) 809 { 810 var value = parseInt( this.getValue(), 10 ); 811 value = isNaN( value ) ? 0 : value; 812 element.setAttribute( 'vspace', this.getValue() ); 813 element.setStyle( 'margin-top', value + 'px' ); 814 element.setStyle( 'margin-bottom', value + 'px' ); 815 } 921 if ( value ) 922 { 923 element.setStyle( 'margin-top', CKEDITOR.tools.cssLength( value ) ); 924 element.setStyle( 'margin-bottom', CKEDITOR.tools.cssLength( value ) ); 925 } 926 else if ( !value && this.isChanged( ) ) 927 { 928 element.removeStyle( 'margin-top' ); 929 element.removeStyle( 'margin-bottom' ); 930 } 931 932 if( !internalCommit && type == IMAGE ) 933 element.removeAttribute( 'vspace' ); 934 } 816 935 else if ( type == CLEANUP ) 817 936 { 818 937 element.removeAttribute( 'vspace' ); … … 833 952 [ 834 953 [ editor.lang.common.notSet , ''], 835 954 [ editor.lang.image.alignLeft , 'left'], 836 [ editor.lang.image.alignAbsBottom , 'absBottom'],837 [ editor.lang.image.alignAbsMiddle , 'absMiddle'],838 [ editor.lang.image.alignBaseline , 'baseline'],839 [ editor.lang.image.alignBottom , 'bottom'],840 [ editor.lang.image.alignMiddle , 'middle'],841 955 [ editor.lang.image.alignRight , 'right'], 842 [ editor.lang.image.alignTextTop , 'textTop'], 843 [ editor.lang.image.alignTop , 'top'] 956 // Backward compatible with v2 on setup when specified as attribute value, 957 // while these values are no more available as select options. 958 // [ editor.lang.image.alignAbsBottom , 'absBottom'], 959 // [ editor.lang.image.alignAbsMiddle , 'absMiddle'], 960 // [ editor.lang.image.alignBaseline , 'baseline'], 961 // [ editor.lang.image.alignTextTop , 'text-top'], 962 // [ editor.lang.image.alignBottom , 'bottom'], 963 // [ editor.lang.image.alignMiddle , 'middle'], 964 // [ editor.lang.image.alignTop , 'top'] 844 965 ], 845 966 onChange : function() 846 967 { 847 968 updatePreview( this.getDialog() ); 969 commitInternally.call( this, 'advanced:txtdlgGenStyle' ); 848 970 }, 849 971 setup : function( type, element ) 850 972 { 851 973 if ( type == IMAGE ) 852 this.setValue( element.getAttribute( 'align' ) ); 853 }, 854 commit : function( type, element ) 855 { 856 var value = this.getValue(); 857 if ( type == IMAGE ) 858 { 859 if ( value || this.isChanged() ) 860 element.setAttribute( 'align', value ); 861 } 862 else if ( type == PREVIEW ) 863 { 864 element.setAttribute( 'align', this.getValue() ); 974 { 975 var value = element.getStyle( 'float' ); 976 switch( value ) 977 { 978 // Ignore those unrelated values. 979 case 'inherit': 980 case 'none': 981 value = ''; 982 } 865 983 866 if ( value == 'absMiddle' || value == 'middle' ) 867 element.setStyle( 'vertical-align', 'middle' ); 868 else if ( value == 'top' || value == 'textTop' ) 869 element.setStyle( 'vertical-align', 'top' ); 870 else 871 element.removeStyle( 'vertical-align' ); 872 873 if ( value == 'right' || value == 'left' ) 874 element.setStyle( 'styleFloat', value ); 875 else 876 element.removeStyle( 'styleFloat' ); 877 984 !value && ( value = ( element.getAttribute( 'align' ) || '' ).toLowerCase() ); 985 this.setValue( value ); 878 986 } 879 else if ( type == CLEANUP ) 880 { 881 element.removeAttribute( 'align' ); 882 } 883 } 884 } 987 }, 988 commit : function( type, element, internalCommit ) 989 { 990 var value = this.getValue(); 991 if ( type == IMAGE || type == PREVIEW ) 992 { 993 if ( value ) 994 element.setStyle( 'float', value ); 995 else if ( !value && this.isChanged( ) ) 996 element.removeStyle( 'float' ); 997 998 if( !internalCommit && type == IMAGE ) 999 { 1000 value = ( element.getAttribute( 'align' ) || '' ).toLowerCase(); 1001 switch( value ) 1002 { 1003 // we should remove it only if it matches "left" or "right", 1004 // otherwise leave it intact. 1005 case 'left': 1006 case 'right': 1007 element.removeAttribute( 'align' ); 1008 } 1009 } 1010 } 1011 else if ( type == CLEANUP ) 1012 element.removeStyle( 'float' ); 1013 1014 } 1015 } 885 1016 ] 886 1017 } 887 1018 ] … … 1183 1314 }; 1184 1315 } 1185 1316 }, 1317 onKeyUp : function () 1318 { 1319 commitInternally.call( this, 1320 [ 'info:cmbFloat', 'info:cmbAlign', 1321 'info:txtVSpace', 'info:txtHSpace', 1322 'info:txtBorder', 1323 'info:txtWidth', 'info:txtHeight' ] ); 1324 }, 1186 1325 commit : function( type, element ) 1187 1326 { 1188 1327 if ( type == IMAGE && ( this.getValue() || this.isChanged() ) ) 1189 1328 { 1190 1329 element.setAttribute( 'style', this.getValue() ); 1191 1192 // Set STYLE dimensions. 1193 var height = element.getAttribute( 'height' ), 1194 width = element.getAttribute( 'width' ); 1195 1196 if ( this.attributesInStyle && this.attributesInStyle.height ) 1197 { 1198 if ( height ) 1199 { 1200 if ( height.match( regexGetSize )[2] == '%' ) // % is allowed 1201 element.setStyle( 'height', height + '%' ); 1202 else 1203 element.setStyle( 'height', height + 'px' ); 1204 } 1205 else 1206 element.removeStyle( 'height' ); 1207 } 1208 if ( this.attributesInStyle && this.attributesInStyle.width ) 1209 { 1210 if ( width ) 1211 { 1212 if ( width.match( regexGetSize )[2] == '%' ) // % is allowed 1213 element.setStyle( 'width', width + '%' ); 1214 else 1215 element.setStyle( 'width', width + 'px' ); 1216 } 1217 else 1218 element.removeStyle( 'width' ); 1219 } 1220 } 1221 } 1222 } 1330 } 1331 } 1332 } 1223 1333 ] 1224 1334 } 1225 1335 ]