Copie depuis le svn du cri à l'état :
[Plinn.git] / skins / ajax_scripts / palette.js
1 // (c) Benoît PIN 2006
2 // http://plinn.org
3 // Licence GPL
4 // $Id: palette.js 1315 2008-07-29 15:36:15Z pin $
5 // $URL: http://svn.cri.ensmp.fr/svn/Plinn/branches/CMF-2.1/skins/ajax_scripts/palette.js $
6
7
8 function InspectorPalette(baseUrl, toggleButton, contentNode, onExpand, onCollapse) {
9 var thisInspector = this;
10 this._preloadImages();
11 this.baseUrl = baseUrl;
12 this.toggleButton = toggleButton;
13 this.toggleButton.src = baseUrl + '/collapsedPalette.gif';
14 this.contentNode = contentNode;
15 this.expanded = false;
16 this.onExpand = onExpand ? onExpand : function(){thisInspector.contentNode.innerHTML='expanded';};
17 this.onCollapse = onCollapse ? onCollapse : function(){thisInspector.contentNode.innerHTML='collapsed';};
18
19 toggleButton.onclick = function(evt) {
20 if (thisInspector.expanded)
21 thisInspector.collapse();
22 else
23 thisInspector.expand();
24 disableDefault(evt);
25 disablePropagation(evt);
26 };
27 }
28
29 InspectorPalette.prototype._preloadImages = function() {
30 var images = ['expandPalette.gif', 'collapsePalette.gif', 'expandedPalette.gif', 'collapsedPalette.gif' ], img;
31 for (var i=0 ; i<images.lenght ; i++) {
32 img = new Image();
33 img.src = this.baseUrl + '/' + images[i];
34 }
35 }
36
37 InspectorPalette.prototype.expand = function() {
38 var toggleButton = this.toggleButton;
39 if (toggleButton.blur) toggleButton.blur();
40 toggleButton.src = this.baseUrl + '/expandPalette.gif';
41 var staticButtonSrc = this.baseUrl + '/expandedPalette.gif';
42 window.setTimeout(function(){toggleButton.src = staticButtonSrc;}, 500);
43 this.onExpand(this);
44 this.expanded = true;
45 }
46
47 InspectorPalette.prototype.collapse = function() {
48 var toggleButton = this.toggleButton;
49 if (toggleButton.blur) toggleButton.blur();
50 toggleButton.src = this.baseUrl + '/collapsePalette.gif';
51 var staticButtonSrc = this.baseUrl + '/collapsedPalette.gif';
52 window.setTimeout(function(){toggleButton.src = staticButtonSrc;}, 500);
53 this.onCollapse(this);
54 this.expanded = false;
55 }