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