22 | | |
| 22 | |
| 23 | var advParamsMap = { |
| 24 | 'advLangDir' : 'dir', |
| 25 | 'advAccessKey' : 'accessKey', |
| 26 | 'advName' : 'name', |
| 27 | 'advLangCode' : 'lang', |
| 28 | 'advTabIndex' : 'tabindex', |
| 29 | 'advTitle' : 'title', |
| 30 | 'advContentType' : 'type', |
| 31 | 'advCSSClasses' : 'class', |
| 32 | 'advCharset' : 'charset', |
| 33 | 'advStyles' : 'style', |
| 34 | 'advId' : 'id' |
| 35 | }; |
| 36 | |
| 37 | var setupAdvParams = function( element ) |
| 38 | { |
| 39 | var attrName = advParamsMap[ this.id ]; |
| 40 | |
| 41 | // Try to get existing value first in case of inChange commit. |
| 42 | var value = this.getValue() || element && element.hasAttribute( attrName ) && element.getAttribute( attrName ) || ''; |
| 43 | |
| 44 | // Compatibility with showborders plugin. |
| 45 | if ( attrName == 'class' ) |
| 46 | { |
| 47 | var _tmpValue = CKEDITOR.tools.trim( value ).split( ' ' ); |
| 48 | if ( CKEDITOR.tools.indexOf( _tmpValue, 'cke_show_border' ) != -1 ) |
| 49 | { |
| 50 | var newValue = []; |
| 51 | for ( var i = 0; i < _tmpValue.length; i++ ) |
| 52 | { |
| 53 | if ( _tmpValue[ i ] != 'cke_show_border' ) |
| 54 | newValue.push( _tmpValue[ i ] ); |
| 55 | } |
| 56 | value = newValue.length && newValue.join( ' ' ) || undefined; |
| 57 | } |
| 58 | } |
| 59 | else if ( attrName == 'style' ) |
| 60 | { |
| 61 | // Check if we've already read element value. |
| 62 | if ( !this._elementStyleRead && element ) |
| 63 | { |
| 64 | value = element.hasAttribute( attrName ) && element.getAttribute( attrName ); |
| 65 | this._elementStyleRead = 1; |
| 66 | } |
| 67 | |
| 68 | // Inherit width value from width field. |
| 69 | var widthField = this.getDialog().getContentElement( 'info', 'txtWidth'); |
| 70 | var widthFieldValue = widthField.getValue(); |
| 71 | |
| 72 | if ( widthFieldValue ) |
| 73 | { |
| 74 | var widthUnit = this.getDialog().getContentElement( 'info', 'cmbWidthType').getValue(); |
| 75 | widthUnit = widthUnit == 'percents' ? '%' : 'px'; |
| 76 | |
| 77 | widthFieldValue = 'width: ' + widthFieldValue + widthUnit + ';'; |
| 78 | if ( value ) |
| 79 | value = value.replace( /\s*width: .+?;\s*/, '' ); |
| 80 | value = value ? value + '; ' + widthFieldValue : widthFieldValue; |
| 81 | } |
| 82 | |
| 83 | // Inherit height value from height field. |
| 84 | var heightField = this.getDialog().getContentElement( 'info', 'txtHeight'); |
| 85 | var heightFieldValue = heightField.getValue(); |
| 86 | if ( heightFieldValue ) |
| 87 | { |
| 88 | heightFieldValue = 'height: ' + heightFieldValue + 'px;'; |
| 89 | if ( value ) |
| 90 | value = value.replace( /\s*height: .+?;\s*/, '' ); |
| 91 | value = value ? value + '; ' + heightFieldValue : heightFieldValue; |
| 92 | } |
| 93 | |
| 94 | if ( value ) |
| 95 | value = value.replace( /\s*;\s*;\s*/g, ';' ); |
| 96 | } |
| 97 | |
| 98 | if ( value !== undefined ) |
| 99 | this.setValue( value ) |
| 100 | }; |
| 101 | |
| 102 | var commitAdvParams = function( data, element ) |
| 103 | { |
| 104 | element = data instanceof CKEDITOR.dom.element ? data : element; |
| 105 | |
| 106 | var value = this.getValue(); |
| 107 | if ( value ) |
| 108 | { |
| 109 | var attrName = advParamsMap[ this.id ]; |
| 110 | |
| 111 | // Compatibility with showborders plugin. |
| 112 | if ( attrName == 'style' ) |
| 113 | { |
| 114 | this._elementStyleRead = 0; |
| 115 | } |
| 116 | else if ( attrName == 'class' ) |
| 117 | { |
| 118 | if ( CKEDITOR.tools.indexOf( CKEDITOR.tools.trim( element.getAttribute( 'class' ) ).split( ' ' ), 'cke_show_border' ) != -1 ) |
| 119 | value += ' cke_show_border'; |
| 120 | } |
| 121 | |
| 122 | if ( element ) |
| 123 | element.setAttribute( attrName, value ); |
| 124 | } |
| 125 | else |
| 126 | element.removeAttribute( attrName, value ); |
| 127 | }; |
| 128 | |
| 129 | // Synchronous field values to other impacted fields is required, e.g. div styles |
| 130 | // change should also alter inline-style text. |
| 131 | function commitInternally( targetFields ) |
| 132 | { |
| 133 | var dialog = this.getDialog(), |
| 134 | element = dialog._.selectedElement; |
| 135 | |
| 136 | // Commit this field and broadcast to target fields. |
| 137 | // this.commit( element, true ); |
| 138 | |
| 139 | targetFields = [].concat( targetFields ); |
| 140 | var length = targetFields.length, field; |
| 141 | for ( var i = 0; i < length; i++ ) |
| 142 | { |
| 143 | field = dialog.getContentElement.apply( dialog, targetFields[ i ].split( ':' ) ); |
| 144 | field && field.setup && field.setup( element, true ); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // Registered 'CKEDITOR.style' instances. |
| 149 | var styles = {} ; |
| 150 | |
583 | | } |
584 | | ] |
| 721 | }, |
| 722 | { |
| 723 | id : 'advanced', |
| 724 | label : editor.lang.link.advanced, |
| 725 | title : editor.lang.link.advanced, |
| 726 | elements : |
| 727 | [ |
| 728 | { |
| 729 | type : 'vbox', |
| 730 | padding : 1, |
| 731 | children : |
| 732 | [ |
| 733 | { |
| 734 | type : 'hbox', |
| 735 | widths : [ '45%', '45%' ], |
| 736 | children : |
| 737 | [ |
| 738 | { |
| 739 | type : 'text', |
| 740 | id : 'advId', |
| 741 | label : editor.lang.link.id, |
| 742 | setup : setupAdvParams, |
| 743 | commit : commitAdvParams |
| 744 | }, |
| 745 | { |
| 746 | type : 'hbox', |
| 747 | widths : [ '45%', '55%' ], |
| 748 | children : |
| 749 | [ |
| 750 | { |
| 751 | type : 'text', |
| 752 | label : editor.lang.link.cssClasses, |
| 753 | 'default' : '', |
| 754 | id : 'advCSSClasses', |
| 755 | setup : setupAdvParams, |
| 756 | commit : commitAdvParams |
| 757 | |
| 758 | } |
| 759 | ] |
| 760 | } |
| 761 | ] |
| 762 | }, |
| 763 | { |
| 764 | type : 'text', |
| 765 | label : editor.lang.link.styles, |
| 766 | 'default' : '', |
| 767 | id : 'advStyles', |
| 768 | onChange : function() |
| 769 | { |
| 770 | // Transaction prevents from recursive calls to onChange() of this field. |
| 771 | if ( this._duringTransaction ) |
| 772 | return; |
| 773 | |
| 774 | this._duringTransaction = 1; |
| 775 | |
| 776 | var value = this.getValue(), |
| 777 | dialog = this.getDialog(), |
| 778 | match; |
| 779 | |
| 780 | // Synchronize width value. |
| 781 | match = value.match( /width\s*:\s*(\d+)(px|%)/ ); |
| 782 | if ( match ) |
| 783 | { |
| 784 | dialog.getContentElement( 'info', 'txtWidth' ).setValue( match[ 1 ] ); |
| 785 | dialog.getContentElement( 'info', 'cmbWidthType' ).setValue( |
| 786 | match[ 2 ] == 'px' ? 'pixels' : 'percents' |
| 787 | ); |
| 788 | } |
| 789 | |
| 790 | // Synchronize height value. |
| 791 | match = value.match( /height\s*:\s*(\d+)(px|%)/ ); |
| 792 | if ( match ) |
| 793 | { |
| 794 | dialog.getContentElement( 'info', 'txtHeight' ).setValue( match[ 1 ] ); |
| 795 | } |
| 796 | |
| 797 | this._duringTransaction = 0; |
| 798 | }, |
| 799 | setup : setupAdvParams, |
| 800 | commit : commitAdvParams |
| 801 | |
| 802 | } |
| 803 | ] |
| 804 | } |
| 805 | ] |
| 806 | } |
| 807 | ] |