- Timestamp:
- 10/24/11 18:22:18 (13 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
ether_megapoli/trunk/web/resources/js/classesForJQuery/Slide.js
r172 r233 1 1 //******************************************************** 2 // Class S elect3 // Display a S elect2 // Class Slide 3 // Display a Slide 4 4 // 5 // obj objParam: {id, [parent], [specificClass], [maxOptionSize], [isDisable], [isDisplayed]} 6 // int objParam.id: id of the dom element 7 // [dom objParam.parent]: in which dom element to draw the button 8 // [str objParam.specificClass] 9 // [int objParam.maxOptionSize]: define a max number of line to display 10 // [int objParam.isDisable]: is the Select disable by default? 11 // [int objParam.isDisplayed]: is the Select opened by default? 12 // 13 // Public functions 14 // Select.getValue 15 // Select.getName 16 // Select.disable 17 // Select.enable 18 // Select.add 19 // Select.remove 20 // Select.clear 21 // Select.select 22 // Select.selectFirst 5 // use jQuery 23 6 //******************************************************** 24 7 25 var S elect= Class.create( {8 var Slide = Class.create( { 26 9 27 10 // Public functions ******************************************************** … … 30 13 { 31 14 // Param 32 this.id = objectParameter.id;33 15 this.parent = objectParameter.parent ? objectParameter.parent : document.body; 34 this.isDisplayed = (true == objectParameter.isDisplayed) ? true : false; 35 this.isDisable = (true == objectParameter.isDisable) ? true : false; 36 this.maxOptionSize = objectParameter.maxOptionSize ? objectParameter.maxOptionSize : 0; 37 this.indexOption = 0; 38 this.isHover = false; 39 this.arrayOptions = $A(); 40 this.className = objectParameter.className ? "select_container " + objectParameter.className : "select_container"; 41 this.classNameOption = objectParameter.classNameOption ? "select_choicelist " + objectParameter.classNameOption : "select_choicelist"; 16 this.contentId = objectParameter.contentId; 17 this.buttonId = objectParameter.buttonId; 18 this.specificContentClass = objectParameter.specificContentClass ? objectParameter.specificContentClass : false; 19 this.specificButtonClass = objectParameter.specificButtonClass ? objectParameter.specificButtonClass : false; 20 this.timeToSlide = objectParameter.timeToSlide ? objectParameter.timeToSlide : 500; 21 this.contentSlide = objectParameter.contentSlide ? objectParameter.contentSlide : false; 22 this.contentButton = objectParameter.contentButton; 23 this.isIndexToChange = objectParameter.isIndexToChange ? objectParameter.isIndexToChange : false; 24 this.zIndex = this.parent.css( "z-index" ); 42 25 43 // Select div 44 this.divSelect = document.createElement( "div" ); 45 this.divSelect.id = this.id; 46 this.divSelect.className = this.className; 26 // Content div 27 this.divSlideContent = $( document.createElement( "div" ) ); 28 this.divSlideContent.attr( {id:this.contentId, class:"containerSlideContent"} ); 29 if( this.specificContentClass ) 30 this.divSlideContent.addClass( this.specificContentClass ); 31 if( this.contentId ) 32 this.divSlideContent.html( this.contentSlide ); 33 this.parent.append( this.divSlideContent ); 47 34 48 this.divSelectLeft = document.createElement( "div" ); 49 this.divSelectLeft.className = "select_selectLeft"; 50 this.divSelect.appendChild( this.divSelectLeft ); 51 52 this.divSelectMiddle = document.createElement( "div" ); 53 this.divSelectMiddle.className = "select_selectMiddle"; 54 this.divSelect.appendChild( this.divSelectMiddle ); 55 56 this.divSelectRight = document.createElement( "div" ); 57 this.divSelectRight.className = "select_selectRight"; 58 this.divSelect.appendChild( this.divSelectRight ); 59 60 this.parent.appendChild( this.divSelect ); 61 62 // Options div 63 this.divOption = document.createElement( "div" ); 64 this.divSelect.id = this.id; 65 this.divOption.className = this.classNameOption; 66 this.parent.appendChild( this.divOption ); 67 68 Event.observe( this.divSelect, "mouseup", this.toggleOption.bindAsEventListener( this ) ); 69 Event.observe( document.body, "mousedown", this.hideOption.bindAsEventListener( this ) ); 70 Event.observe( this.divSelect, 'mouseover', this.onMouseHover.bindAsEventListener( this ) ); 71 Event.observe( this.divSelect, 'mouseout', this.onMouseOut.bindAsEventListener( this ) ); 72 Event.observe( this.divOption, 'mouseover', this.onMouseHover.bindAsEventListener( this ) ); 73 Event.observe( this.divOption, 'mouseout', this.onMouseOut.bindAsEventListener( this ) ); 74 75 if( this.isDisplayed ) 76 this.showOption(); 77 78 if( this.isDisable ) 79 this.hideOption(); 35 // Button div 36 this.divSlideButton = $( document.createElement( "div" ) ); 37 this.divSlideButton.attr( {id:this.buttonId} ); 38 this.divSlideButton.attr( {id:this.buttonId, class:"containerSlideButton"} ); 39 if( this.specificButtonClass ) 40 this.divSlideButton.addClass( this.specificButtonClass ); 41 this.divSlideButton.append( this.contentButton ); 42 this.divSlideButton.bind( "click", jQuery.proxy( this.onClickButton, this ) ); 43 this.parent.append( this.divSlideButton ); 80 44 }, 81 45 82 get Name: function()46 getContent: function() 83 47 { 84 return this. itemName;48 return this.divSlideContent.html(); 85 49 }, 86 50 87 getValue: function()51 setContent: function( newContent ) 88 52 { 89 return this.itemValue;53 this.divSlideContent.html( newContent ); 90 54 }, 91 55 92 getSize: function()56 isContentVisible: function() 93 57 { 94 return this.arrayOptions.size(); 95 }, 96 97 // private 98 toggleOption:function() 99 { 100 if( this.isDisplayed ) 101 { 102 this.isHover = false; 103 this.hideOption(); 104 } 105 else 106 this.showOption(); 107 }, 108 109 // private 110 showOption:function() 111 { 112 if( this.isDisable ) 113 return; 114 115 this.isDisplayed = true; 116 this.displayOptions(); 117 this.divOption.style.display = "block"; 118 }, 119 120 // private 121 hideOption: function() 122 { 123 if( this.isHover ) 124 return; 125 126 this.isDisplayed = false; 127 this.divOption.style.display = "none"; 58 return (this.divSlideContent.css( "display" ) == "block"); 128 59 }, 129 60 130 61 // public 131 disable: function()62 onClickButton: function() 132 63 { 133 this.isDisable = true; 134 this.divSelect.addClassName( "disable" ); 135 this.hideOption(); 136 }, 64 if( this.isIndexToChange ) 65 if( this.isContentVisible() ) 66 this.parent.css( "z-index", this.zIndex ); 67 else 68 this.parent.css( "z-index", 100 ); 137 69 138 // public 139 enable: function() 140 { 141 this.isDisable = false; 142 this.divSelect.removeClassName( "disable" ); 143 }, 144 145 // public 146 /** 147 * This method indicates if the itemValue is already in the array 148 */ 149 content: function( itemValue ) 150 { 151 var resu = false; 152 this.arrayOptions.each( function( divOption ) 153 { 154 if( divOption.itemValue == itemValue ) 155 { 156 resu = true; 157 throw $break; 158 } 159 }.bind( this ) ); 160 return resu; 161 }, 162 163 // public 164 add: function( itemValue, itemName, callback ) 165 { 166 var divOption = document.createElement( "div" ); 167 divOption.className = "select_item_middle"; 168 divOption.innerHTML = itemName; 169 divOption.itemName = itemName; 170 divOption.itemValue = itemValue; 171 divOption.callback = callback; 172 this.divOption.appendChild( divOption ); 173 174 Event.observe( divOption, 'click', this.onOptionClick.bind( this, divOption ) ); 175 176 this.arrayOptions.push( divOption ); 177 }, 178 179 // public 180 remove: function( itemValue ) 181 { 182 this.arrayOptions.each( function( divOption ) 183 { 184 if( divOption.itemValue == itemValue ) 185 { 186 this.divOption.removeChild( divOption ); 187 this.arrayOptions = this.arrayOptions.without( divOption ); 188 throw $break; 189 } 190 }.bind( this ) ); 191 }, 192 193 // public 194 clear: function() 195 { 196 this.arrayOptions.each( function( divOption ) 197 { 198 this.divOption.removeChild( divOption ); 199 this.arrayOptions = this.arrayOptions.without( divOption ); 200 }.bind( this ) ); 201 }, 202 203 // public 204 /** 205 * This method changes only the content of the divSelect without add the item to the array 206 * @param itemValue 207 * @param itemName 208 * @param callback 209 */ 210 changeSelectMiddle: function( itemValue, itemName, callback ) 211 { 212 this.add( itemValue, itemName, callback ); 213 this.select( itemValue, callback ); 214 this.remove( itemValue ); 215 }, 216 217 // public 218 // @itemValue : code of the selected line 219 // @ execute : true / false. Execute the callback. 220 select: function( itemValue, execute ) 221 { 222 this.arrayOptions.each( function( divOption ) 223 { 224 if( divOption.itemValue == itemValue ) 225 { 226 this.selectOption( divOption ); 227 if( execute && undefined != divOption.callback ) 228 divOption.callback( divOption.itemValue ); 229 throw $break; 230 } 231 }.bind( this ) ); 232 }, 233 234 // public 235 // @ execute : true / false. Execute the callback. 236 selectFirst: function( execute ) 237 { 238 var divOption = this.arrayOptions.first(); 239 if( undefined == divOption ) 240 return; 241 242 this.selectOption( divOption ); 243 if( execute && undefined != divOption.callback ) 244 divOption.callback( divOption.itemValue ); 245 }, 246 247 // private 248 selectOption: function( divOption ) 249 { 250 this.itemName = divOption.itemName; 251 this.itemValue = divOption.itemValue; 252 this.divSelectMiddle.innerHTML = divOption.itemName; 253 }, 254 255 // private 256 onOptionClick: function( divOption ) 257 { 258 this.isHover = false; 259 this.hideOption(); 260 this.select( divOption.itemValue, true ); 261 if( undefined != divOption.callback ) 262 divOption.callback( divOption.itemValue ); 263 }, 264 265 // private 266 onMouseHover: function() 267 { 268 this.isHover = true; 269 }, 270 271 // private 272 onMouseOut: function() 273 { 274 this.isHover = false; 275 }, 276 277 // private 278 displayOptions: function() 279 { 280 var fromOption = this.indexOption; 281 var toOption = this.indexOption + this.maxOptionSize - 1; 282 for( var i = 0; i < this.arrayOptions.size(); i++ ) 283 { 284 if( 0 == this.maxOptionSize ) 285 this.arrayOptions[i].style.display = ""; 286 else if( i >= fromOption && i <= toOption ) 287 this.arrayOptions[i].style.display = ""; 288 else 289 this.arrayOptions[i].style.display = "none"; 290 } 70 this.divSlideContent.animate( {width:"toggle"}, this.timeToSlide ); 291 71 } 292 72 } );
Note: See TracChangeset
for help on using the changeset viewer.