import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / classes / fckicon.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * FCKIcon Class: renders an icon from a single image, a strip or even a\r
22  * spacer.\r
23  */\r
24 \r
25 var FCKIcon = function( iconPathOrStripInfoArray )\r
26 {\r
27         var sTypeOf = iconPathOrStripInfoArray ? typeof( iconPathOrStripInfoArray ) : 'undefined' ;\r
28         switch ( sTypeOf )\r
29         {\r
30                 case 'number' :\r
31                         this.Path = FCKConfig.SkinPath + 'fck_strip.gif' ;\r
32                         this.Size = 16 ;\r
33                         this.Position = iconPathOrStripInfoArray ;\r
34                         break ;\r
35 \r
36                 case 'undefined' :\r
37                         this.Path = FCK_SPACER_PATH ;\r
38                         break ;\r
39 \r
40                 case 'string' :\r
41                         this.Path = iconPathOrStripInfoArray ;\r
42                         break ;\r
43 \r
44                 default :\r
45                         // It is an array in the format [ StripFilePath, IconSize, IconPosition ]\r
46                         this.Path               = iconPathOrStripInfoArray[0] ;\r
47                         this.Size               = iconPathOrStripInfoArray[1] ;\r
48                         this.Position   = iconPathOrStripInfoArray[2] ;\r
49         }\r
50 }\r
51 \r
52 FCKIcon.prototype.CreateIconElement = function( document )\r
53 {\r
54         var eIcon, eIconImage ;\r
55 \r
56         if ( this.Position )            // It is using an icons strip image.\r
57         {\r
58                 var sPos = '-' + ( ( this.Position - 1 ) * this.Size ) + 'px' ;\r
59 \r
60                 if ( FCKBrowserInfo.IsIE )\r
61                 {\r
62                         // <div class="TB_Button_Image"><img src="strip.gif" style="top:-16px"></div>\r
63 \r
64                         eIcon = document.createElement( 'DIV' ) ;\r
65 \r
66                         eIconImage = eIcon.appendChild( document.createElement( 'IMG' ) ) ;\r
67                         eIconImage.src = this.Path ;\r
68                         eIconImage.style.top = sPos ;\r
69                 }\r
70                 else\r
71                 {\r
72                         // <img class="TB_Button_Image" src="spacer.gif" style="background-position: 0px -16px;background-image: url(strip.gif);">\r
73 \r
74                         eIcon = document.createElement( 'IMG' ) ;\r
75                         eIcon.src = FCK_SPACER_PATH ;\r
76                         eIcon.style.backgroundPosition  = '0px ' + sPos ;\r
77                         eIcon.style.backgroundImage             = 'url("' + this.Path + '")' ;\r
78                 }\r
79         }\r
80         else                                    // It is using a single icon image.\r
81         {\r
82                 if ( FCKBrowserInfo.IsIE )\r
83                 {\r
84                         // IE makes the button 1px higher if using the <img> directly, so we\r
85                         // are changing to the <div> system to clip the image correctly.\r
86                         eIcon = document.createElement( 'DIV' ) ;\r
87 \r
88                         eIconImage = eIcon.appendChild( document.createElement( 'IMG' ) ) ;\r
89                         eIconImage.src = this.Path ? this.Path : FCK_SPACER_PATH ;\r
90                 }\r
91                 else\r
92                 {\r
93                         // This is not working well with IE. See notes above.\r
94                         // <img class="TB_Button_Image" src="smiley.gif">\r
95                         eIcon = document.createElement( 'IMG' ) ;\r
96                         eIcon.src = this.Path ? this.Path : FCK_SPACER_PATH ;\r
97                 }\r
98         }\r
99 \r
100         eIcon.className = 'TB_Button_Image' ;\r
101 \r
102         return eIcon ;\r
103 }\r