[8961] | 1 | /** |
---|
| 2 | * ----------------------------------------------------------------------------- |
---|
| 3 | * file: ui.inputColorsFB.js |
---|
[16012] | 4 | * file version: 1.0.1 |
---|
| 5 | * date: 2012-06-18 |
---|
[8961] | 6 | * |
---|
| 7 | * A jQuery plugin provided by the piwigo's plugin "GrumPluginClasses" |
---|
| 8 | * |
---|
| 9 | * ----------------------------------------------------------------------------- |
---|
| 10 | * Author : Grum |
---|
| 11 | * email : grum@piwigo.com |
---|
| 12 | * website : http://photos.grum.fr |
---|
| 13 | * |
---|
| 14 | * << May the Little SpaceFrog be with you ! >> |
---|
| 15 | * ----------------------------------------------------------------------------- |
---|
| 16 | * |
---|
| 17 | * |
---|
| 18 | * |
---|
| 19 | * |
---|
| 20 | * :: HISTORY :: |
---|
| 21 | * |
---|
| 22 | * | release | date | |
---|
| 23 | * | 1.0.0 | 2010/11/04 | first release |
---|
| 24 | * | | | |
---|
[16012] | 25 | * | 1.0.1 | 2012/06/18 | * improve memory managment |
---|
[8961] | 26 | * | | | |
---|
| 27 | * | | | |
---|
| 28 | * | | | |
---|
| 29 | * | | | |
---|
| 30 | * |
---|
| 31 | */ |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | ( |
---|
| 36 | function($) |
---|
| 37 | { |
---|
| 38 | /* |
---|
| 39 | * plugin 'public' functions |
---|
| 40 | */ |
---|
| 41 | var publicMethods = |
---|
| 42 | { |
---|
| 43 | init : function (opt) |
---|
| 44 | { |
---|
| 45 | return this.each(function() |
---|
| 46 | { |
---|
| 47 | // default values for the plugin |
---|
| 48 | var $this=$(this), |
---|
| 49 | data = $this.data('options'), |
---|
| 50 | objects = $this.data('objects'), |
---|
| 51 | properties = $this.data('properties'), |
---|
| 52 | options = |
---|
| 53 | { |
---|
| 54 | width:0, |
---|
| 55 | height:0, |
---|
| 56 | disabled:false, |
---|
| 57 | fg: |
---|
| 58 | { |
---|
| 59 | color:'#ffffff', |
---|
| 60 | opacity:1 |
---|
| 61 | }, |
---|
| 62 | bg: |
---|
| 63 | { |
---|
| 64 | color:'#000000', |
---|
| 65 | opacity:1 |
---|
| 66 | }, |
---|
| 67 | selected:'fg', |
---|
| 68 | mode:2, //1 - 2 |
---|
| 69 | boxSize:0.6, |
---|
| 70 | change:null, |
---|
| 71 | click:null |
---|
| 72 | }; |
---|
| 73 | |
---|
| 74 | // if options given, merge it |
---|
| 75 | // if(opt) $.extend(options, opt); ==> options are set by setters |
---|
| 76 | |
---|
| 77 | $this.data('options', options); |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | if(!properties) |
---|
| 81 | { |
---|
| 82 | $this.data('properties', |
---|
| 83 | { |
---|
| 84 | initialized:false |
---|
| 85 | } |
---|
| 86 | ); |
---|
| 87 | properties=$this.data('properties'); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | if(!objects) |
---|
| 91 | { |
---|
| 92 | objects = |
---|
| 93 | { |
---|
| 94 | container:$('<div/>', |
---|
| 95 | { |
---|
| 96 | 'class':'ui-inputColorsFB', |
---|
| 97 | css:{ |
---|
| 98 | width:'100%', |
---|
| 99 | height:'100%' |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | ), |
---|
| 103 | fg:$('<div/>', |
---|
| 104 | { |
---|
| 105 | 'class':'ui-inputColorsFB-fg' |
---|
| 106 | } |
---|
| 107 | ).bind('click.inputColorsFB', |
---|
| 108 | function (event) |
---|
| 109 | { |
---|
| 110 | if(options.mode==2) privateMethods.setSelected($this, 'fg' ); |
---|
| 111 | if(options.click) $this.trigger('inputColorsFBClick', {target:'fg', color: options.fg} ); |
---|
| 112 | } |
---|
| 113 | ), |
---|
| 114 | bg:$('<div/>', |
---|
| 115 | { |
---|
| 116 | 'class':'ui-inputColorsFB-bg' |
---|
| 117 | } |
---|
| 118 | ).bind('click.inputColorsFB', |
---|
| 119 | function (event) |
---|
| 120 | { |
---|
| 121 | if(options.mode==2) privateMethods.setSelected($this, 'bg' ); |
---|
| 122 | if(options.click) $this.trigger('inputColorsFBClick', {target:'bg', color: options.bg} ); |
---|
| 123 | } |
---|
| 124 | ), |
---|
| 125 | fgopacity:$('<div/>', |
---|
| 126 | { |
---|
| 127 | 'class':'ui-inputColorsFB-fgopacity' |
---|
| 128 | } |
---|
| 129 | ), |
---|
| 130 | bgopacity:$('<div/>', |
---|
| 131 | { |
---|
| 132 | 'class':'ui-inputColorsFB-bgopacity' |
---|
| 133 | } |
---|
| 134 | ) |
---|
| 135 | }; |
---|
| 136 | |
---|
| 137 | $this |
---|
| 138 | .html('') |
---|
| 139 | .append(objects.container.append(objects.fgopacity.append(objects.fg)).append(objects.bgopacity.append(objects.bg))); |
---|
| 140 | |
---|
| 141 | $this.data('objects', objects); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | privateMethods.setOptions($this, opt); |
---|
| 145 | } |
---|
| 146 | ); |
---|
| 147 | }, // init |
---|
| 148 | destroy : function () |
---|
| 149 | { |
---|
| 150 | return this.each( |
---|
| 151 | function() |
---|
| 152 | { |
---|
| 153 | // default values for the plugin |
---|
| 154 | var $this=$(this), |
---|
| 155 | objects = $this.data('objects'); |
---|
[16012] | 156 | objects.fg.remove(); |
---|
| 157 | objects.bg.remove(); |
---|
| 158 | objects.fgopacity.remove(); |
---|
| 159 | objects.bgopacity.remove(); |
---|
[8961] | 160 | objects.container.unbind().remove(); |
---|
| 161 | $this |
---|
| 162 | .unbind('.inputColorsFB') |
---|
[16012] | 163 | .removeData() |
---|
[8961] | 164 | .css( |
---|
| 165 | { |
---|
| 166 | width:'', |
---|
| 167 | height:'' |
---|
| 168 | } |
---|
| 169 | ); |
---|
[16012] | 170 | delete $this; |
---|
[8961] | 171 | } |
---|
| 172 | ); |
---|
| 173 | }, // destroy |
---|
| 174 | |
---|
| 175 | options: function (value) |
---|
| 176 | { |
---|
| 177 | return( |
---|
| 178 | this.each( |
---|
| 179 | function() |
---|
| 180 | { |
---|
| 181 | privateMethods.setOptions($(this), value); |
---|
| 182 | } |
---|
| 183 | ) |
---|
| 184 | ); |
---|
| 185 | }, // options |
---|
| 186 | |
---|
| 187 | disabled: function (value) |
---|
| 188 | { |
---|
| 189 | if(value!=null) |
---|
| 190 | { |
---|
| 191 | return( |
---|
| 192 | this.each( |
---|
| 193 | function() |
---|
| 194 | { |
---|
| 195 | privateMethods.setDisabled($(this), value); |
---|
| 196 | } |
---|
| 197 | ) |
---|
| 198 | ); |
---|
| 199 | } |
---|
| 200 | else |
---|
| 201 | { |
---|
| 202 | var options = this.data('options'); |
---|
| 203 | |
---|
| 204 | if(options) |
---|
| 205 | { |
---|
| 206 | return(options.disabled); |
---|
| 207 | } |
---|
| 208 | else |
---|
| 209 | { |
---|
| 210 | return(''); |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | }, // disabled |
---|
| 214 | |
---|
| 215 | mode: function (value) |
---|
| 216 | { |
---|
| 217 | if(value!=null) |
---|
| 218 | { |
---|
| 219 | return( |
---|
| 220 | this.each( |
---|
| 221 | function() |
---|
| 222 | { |
---|
| 223 | privateMethods.setMode($(this), value, true); |
---|
| 224 | } |
---|
| 225 | ) |
---|
| 226 | ); |
---|
| 227 | } |
---|
| 228 | else |
---|
| 229 | { |
---|
| 230 | var options=this.data('options'); |
---|
| 231 | return(options.mode); |
---|
| 232 | } |
---|
| 233 | }, // mode |
---|
| 234 | |
---|
| 235 | boxSize: function (value) |
---|
| 236 | { |
---|
| 237 | if(value!=null) |
---|
| 238 | { |
---|
| 239 | return( |
---|
| 240 | this.each( |
---|
| 241 | function() |
---|
| 242 | { |
---|
| 243 | privateMethods.setBoxSize($(this), value, true); |
---|
| 244 | } |
---|
| 245 | ) |
---|
| 246 | ); |
---|
| 247 | } |
---|
| 248 | else |
---|
| 249 | { |
---|
| 250 | var options=this.data('options'); |
---|
| 251 | return(options.boxSize); |
---|
| 252 | } |
---|
| 253 | }, // boxSize |
---|
| 254 | |
---|
| 255 | width: function (value) |
---|
| 256 | { |
---|
| 257 | if(value!=null) |
---|
| 258 | { |
---|
| 259 | return( |
---|
| 260 | this.each( |
---|
| 261 | function() |
---|
| 262 | { |
---|
| 263 | privateMethods.setWidth($(this), value, true); |
---|
| 264 | } |
---|
| 265 | ) |
---|
| 266 | ); |
---|
| 267 | } |
---|
| 268 | else |
---|
| 269 | { |
---|
| 270 | var options=this.data('options'); |
---|
| 271 | return(options.width); |
---|
| 272 | } |
---|
| 273 | }, // width |
---|
| 274 | |
---|
| 275 | height: function (value) |
---|
| 276 | { |
---|
| 277 | if(value!=null) |
---|
| 278 | { |
---|
| 279 | return( |
---|
| 280 | this.each( |
---|
| 281 | function() |
---|
| 282 | { |
---|
| 283 | privateMethods.setHeight($(this), value, true); |
---|
| 284 | } |
---|
| 285 | ) |
---|
| 286 | ); |
---|
| 287 | } |
---|
| 288 | else |
---|
| 289 | { |
---|
| 290 | var options=this.data('options'); |
---|
| 291 | return(options.height); |
---|
| 292 | } |
---|
| 293 | }, // height |
---|
| 294 | |
---|
| 295 | fg: function (value) |
---|
| 296 | { |
---|
| 297 | if(value!=null) |
---|
| 298 | { |
---|
| 299 | // set selected value |
---|
| 300 | return( |
---|
| 301 | this.each( |
---|
| 302 | function() |
---|
| 303 | { |
---|
| 304 | privateMethods.setFG($(this), value, true); |
---|
| 305 | } |
---|
| 306 | ) |
---|
| 307 | ); |
---|
| 308 | } |
---|
| 309 | else |
---|
| 310 | { |
---|
| 311 | // return the selected tags |
---|
| 312 | var options=this.data('options'); |
---|
| 313 | return(options.fg); |
---|
| 314 | } |
---|
| 315 | }, // fg |
---|
| 316 | |
---|
| 317 | bg: function (value) |
---|
| 318 | { |
---|
| 319 | if(value!=null) |
---|
| 320 | { |
---|
| 321 | // set selected value |
---|
| 322 | return( |
---|
| 323 | this.each( |
---|
| 324 | function() |
---|
| 325 | { |
---|
| 326 | privateMethods.setBG($(this), value, true); |
---|
| 327 | } |
---|
| 328 | ) |
---|
| 329 | ); |
---|
| 330 | } |
---|
| 331 | else |
---|
| 332 | { |
---|
| 333 | // return the selected tags |
---|
| 334 | var options=this.data('options'); |
---|
| 335 | return(options.bg); |
---|
| 336 | } |
---|
| 337 | }, // bg |
---|
| 338 | |
---|
| 339 | selected: function (value) |
---|
| 340 | { |
---|
| 341 | if(value!=null) |
---|
| 342 | { |
---|
| 343 | // set selected value |
---|
| 344 | return( |
---|
| 345 | this.each( |
---|
| 346 | function() |
---|
| 347 | { |
---|
| 348 | privateMethods.setSelected($(this), value); |
---|
| 349 | } |
---|
| 350 | ) |
---|
| 351 | ); |
---|
| 352 | } |
---|
| 353 | else |
---|
| 354 | { |
---|
| 355 | // return the selected tags |
---|
| 356 | var options=this.data('options'); |
---|
| 357 | return(options.selected); |
---|
| 358 | } |
---|
| 359 | }, // selected |
---|
| 360 | |
---|
| 361 | isValid: function (value) |
---|
| 362 | { |
---|
| 363 | if(value!=null) |
---|
| 364 | { |
---|
| 365 | // set selected value |
---|
| 366 | return( |
---|
| 367 | this.each( |
---|
| 368 | function() |
---|
| 369 | { |
---|
| 370 | privateMethods.setIsValid($(this), value); |
---|
| 371 | } |
---|
| 372 | ) |
---|
| 373 | ); |
---|
| 374 | } |
---|
| 375 | else |
---|
| 376 | { |
---|
| 377 | // return the selected tags |
---|
| 378 | var properties=this.data('properties'); |
---|
| 379 | return(properties.isValid); |
---|
| 380 | } |
---|
| 381 | }, // isValid |
---|
| 382 | |
---|
| 383 | change: function (value) |
---|
| 384 | { |
---|
| 385 | if(value!=null && $.isFunction(value)) |
---|
| 386 | { |
---|
| 387 | // set selected value |
---|
| 388 | return( |
---|
| 389 | this.each( |
---|
| 390 | function() |
---|
| 391 | { |
---|
| 392 | privateMethods.setEventChange($(this), value); |
---|
| 393 | } |
---|
| 394 | ) |
---|
| 395 | ); |
---|
| 396 | } |
---|
| 397 | else |
---|
| 398 | { |
---|
| 399 | // return the selected value |
---|
| 400 | var options=this.data('options'); |
---|
| 401 | |
---|
| 402 | if(options) |
---|
| 403 | { |
---|
| 404 | return(options.change); |
---|
| 405 | } |
---|
| 406 | else |
---|
| 407 | { |
---|
| 408 | return(null); |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | }, // change |
---|
| 412 | |
---|
| 413 | click: function (value) |
---|
| 414 | { |
---|
| 415 | if(value!=null && $.isFunction(value)) |
---|
| 416 | { |
---|
| 417 | // set selected value |
---|
| 418 | return( |
---|
| 419 | this.each( |
---|
| 420 | function() |
---|
| 421 | { |
---|
| 422 | privateMethods.setEventClick($(this), value); |
---|
| 423 | } |
---|
| 424 | ) |
---|
| 425 | ); |
---|
| 426 | } |
---|
| 427 | else |
---|
| 428 | { |
---|
| 429 | // return the selected value |
---|
| 430 | var options=this.data('options'); |
---|
| 431 | |
---|
| 432 | if(options) |
---|
| 433 | { |
---|
| 434 | return(options.click); |
---|
| 435 | } |
---|
| 436 | else |
---|
| 437 | { |
---|
| 438 | return(null); |
---|
| 439 | } |
---|
| 440 | } |
---|
| 441 | } // click |
---|
| 442 | |
---|
| 443 | }; // methods |
---|
| 444 | |
---|
| 445 | |
---|
| 446 | /* |
---|
| 447 | * plugin 'private' methods |
---|
| 448 | */ |
---|
| 449 | var privateMethods = |
---|
| 450 | { |
---|
| 451 | setOptions : function (object, value) |
---|
| 452 | { |
---|
| 453 | var properties=object.data('properties'), |
---|
| 454 | options=object.data('options'); |
---|
| 455 | |
---|
| 456 | if(!$.isPlainObject(value)) return(false); |
---|
| 457 | |
---|
| 458 | properties.initialized=false; |
---|
| 459 | |
---|
| 460 | privateMethods.setMode(object, (value.mode!=null)?value.mode:options.mode); |
---|
| 461 | privateMethods.setBoxSize(object, (value.boxSize!=null)?value.boxSize:options.boxSize); |
---|
| 462 | privateMethods.setWidth(object, (value.width!=null)?value.width:options.width); |
---|
| 463 | privateMethods.setHeight(object, (value.height!=null)?value.height:options.height); |
---|
| 464 | privateMethods.setFG(object, (value.fg!=null)?value.fg:options.fg); |
---|
| 465 | privateMethods.setBG(object, (value.bg!=null)?value.bg:options.bg); |
---|
| 466 | privateMethods.setSelected(object, (value.selected!=null)?value.selected:options.selected, true); |
---|
| 467 | |
---|
| 468 | privateMethods.setEventChange(object, (value.change!=null)?value.change:options.change); |
---|
| 469 | privateMethods.setEventClick(object, (value.click!=null)?value.click:options.click); |
---|
| 470 | |
---|
| 471 | properties.initialized=true; |
---|
| 472 | }, |
---|
| 473 | |
---|
| 474 | setIsValid : function (object, value) |
---|
| 475 | { |
---|
| 476 | var objects=object.data('objects'), |
---|
| 477 | properties=object.data('properties'); |
---|
| 478 | /* |
---|
| 479 | if(properties.isValid!=value && properties.initialized) |
---|
| 480 | { |
---|
| 481 | properties.isValid=value; |
---|
| 482 | if(properties.isValid) |
---|
| 483 | { |
---|
| 484 | objects.container.removeClass('ui-error'); |
---|
| 485 | objects.input.removeClass('ui-error'); |
---|
| 486 | } |
---|
| 487 | else |
---|
| 488 | { |
---|
| 489 | objects.container.addClass('ui-error'); |
---|
| 490 | objects.input.addClass('ui-error'); |
---|
| 491 | } |
---|
| 492 | } |
---|
| 493 | */ |
---|
| 494 | return(properties.isValid); |
---|
| 495 | }, |
---|
| 496 | |
---|
| 497 | |
---|
| 498 | setMode : function (object, value) |
---|
| 499 | { |
---|
| 500 | var options=object.data('options'), |
---|
| 501 | objects=object.data('objects'), |
---|
| 502 | properties=object.data('properties'); |
---|
| 503 | |
---|
| 504 | if((!properties.initialized || options.mode!=value) && (value==1 || value==2)) |
---|
| 505 | { |
---|
| 506 | options.mode=value; |
---|
| 507 | privateMethods.setSelected(object, 'fg'); |
---|
| 508 | if(options.mode==1) |
---|
| 509 | { |
---|
| 510 | objects.bg.css('display', 'none'); |
---|
| 511 | objects.bgopacity.css('display', 'none'); |
---|
| 512 | objects.fgopacity.removeClass('ui-inputColorsFB-selected'); |
---|
| 513 | if(options.click==null) objects.fgopacity.removeClass('ui-inputColorsFB-clickable'); |
---|
| 514 | } |
---|
| 515 | else |
---|
| 516 | { |
---|
| 517 | objects.bg.css('display', 'block'); |
---|
| 518 | objects.bgopacity.css('display', 'block').addClass('ui-inputColorsFB-clickable'); |
---|
| 519 | objects.fgopacity.addClass('ui-inputColorsFB-clickable'); |
---|
| 520 | } |
---|
| 521 | privateMethods.updateSizes(object); |
---|
| 522 | } |
---|
| 523 | return(options.mode); |
---|
| 524 | }, |
---|
| 525 | |
---|
| 526 | setBoxSize : function (object, value) |
---|
| 527 | { |
---|
| 528 | var options=object.data('options'), |
---|
| 529 | objects=object.data('objects'), |
---|
| 530 | properties=object.data('properties'); |
---|
| 531 | |
---|
| 532 | if((!properties.initialized || options.boxSize!=value) && (value>0 && value<=1)) |
---|
| 533 | { |
---|
| 534 | options.boxSize=value; |
---|
| 535 | privateMethods.updateSizes(object); |
---|
| 536 | } |
---|
| 537 | return(options.boxSize); |
---|
| 538 | }, |
---|
| 539 | |
---|
| 540 | setWidth : function (object, value) |
---|
| 541 | { |
---|
| 542 | var options=object.data('options'), |
---|
| 543 | objects=object.data('objects'), |
---|
| 544 | properties=object.data('properties'); |
---|
| 545 | |
---|
| 546 | if((!properties.initialized || options.width!=value) && value>0) |
---|
| 547 | { |
---|
| 548 | options.width=value; |
---|
| 549 | privateMethods.updateSizes(object); |
---|
| 550 | } |
---|
| 551 | return(options.width); |
---|
| 552 | }, |
---|
| 553 | |
---|
| 554 | setHeight : function (object, value) |
---|
| 555 | { |
---|
| 556 | var options=object.data('options'), |
---|
| 557 | objects=object.data('objects'), |
---|
| 558 | properties=object.data('properties'); |
---|
| 559 | |
---|
| 560 | if((!properties.initialized || options.height!=value) && value>0) |
---|
| 561 | { |
---|
| 562 | options.height=value; |
---|
| 563 | privateMethods.updateSizes(object); |
---|
| 564 | } |
---|
| 565 | return(options.height); |
---|
| 566 | }, |
---|
| 567 | |
---|
| 568 | setDisabled : function (object, value) |
---|
| 569 | { |
---|
| 570 | var options=object.data('options'), |
---|
| 571 | objects=object.data('objects'), |
---|
| 572 | properties=object.data('properties'); |
---|
| 573 | |
---|
| 574 | if((!properties.initialized || options.disabled!=value) && (value==true || value==false)) |
---|
| 575 | { |
---|
| 576 | options.disabled=value; |
---|
| 577 | objects.input.attr('disabled', options.disabled); |
---|
| 578 | } |
---|
| 579 | return(options.disabled); |
---|
| 580 | }, |
---|
| 581 | |
---|
| 582 | setSelected : function (object, value) |
---|
| 583 | { |
---|
| 584 | var options=object.data('options'), |
---|
| 585 | objects=object.data('objects'), |
---|
| 586 | properties=object.data('properties'); |
---|
| 587 | |
---|
| 588 | if((!properties.initialized || options.selected!=value) && (value=='fg' || value=='bg') && options.mode==2) |
---|
| 589 | { |
---|
| 590 | options.selected=value; |
---|
| 591 | |
---|
| 592 | if(options.selected=='fg') |
---|
| 593 | { |
---|
| 594 | objects.fgopacity.addClass('ui-inputColorsFB-selected'); |
---|
| 595 | objects.bgopacity.removeClass('ui-inputColorsFB-selected'); |
---|
| 596 | } |
---|
| 597 | else |
---|
| 598 | { |
---|
| 599 | objects.fgopacity.removeClass('ui-inputColorsFB-selected'); |
---|
| 600 | objects.bgopacity.addClass('ui-inputColorsFB-selected'); |
---|
| 601 | } |
---|
| 602 | if(options.change) object.trigger('inputColorsFBChange', options.selected); |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | return(options.selected); |
---|
| 606 | }, //setFG |
---|
| 607 | |
---|
| 608 | setFG : function (object, value) |
---|
| 609 | { |
---|
| 610 | var options=object.data('options'), |
---|
| 611 | objects=object.data('objects'); |
---|
| 612 | |
---|
| 613 | if(value.color==null || value.opacity==null) |
---|
| 614 | { |
---|
| 615 | return(false); |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | options.fg.color=value.color; |
---|
| 619 | options.fg.opacity=value.opacity; |
---|
| 620 | |
---|
| 621 | objects.fg.css( |
---|
| 622 | { |
---|
| 623 | 'background':options.fg.color, |
---|
| 624 | 'opacity':options.fg.opacity |
---|
| 625 | } |
---|
| 626 | ); |
---|
| 627 | |
---|
| 628 | return(true); |
---|
| 629 | }, //setFG |
---|
| 630 | |
---|
| 631 | setBG : function (object, value, apply) |
---|
| 632 | { |
---|
| 633 | var options=object.data('options'), |
---|
| 634 | objects=object.data('objects'); |
---|
| 635 | |
---|
| 636 | if(value.color==null || value.opacity==null) |
---|
| 637 | { |
---|
| 638 | return(false); |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | options.bg.color=value.color; |
---|
| 642 | options.bg.opacity=value.opacity; |
---|
| 643 | |
---|
| 644 | objects.bg.css( |
---|
| 645 | { |
---|
| 646 | 'background':options.bg.color, |
---|
| 647 | 'opacity':options.bg.opacity |
---|
| 648 | } |
---|
| 649 | ); |
---|
| 650 | |
---|
| 651 | return(true); |
---|
| 652 | }, //setBG |
---|
| 653 | |
---|
| 654 | |
---|
| 655 | setEventChange : function (object, value) |
---|
| 656 | { |
---|
| 657 | var options=object.data('options'); |
---|
| 658 | |
---|
| 659 | options.change=value; |
---|
| 660 | object.unbind('inputColorsFBChange'); |
---|
| 661 | if(value) object.bind('inputColorsFBChange', options.change); |
---|
| 662 | return(options.change); |
---|
| 663 | }, |
---|
| 664 | |
---|
| 665 | setEventClick : function (object, value) |
---|
| 666 | { |
---|
| 667 | var options=object.data('options'), |
---|
| 668 | objects=object.data('objects'); |
---|
| 669 | |
---|
| 670 | options.click=value; |
---|
| 671 | object.unbind('inputColorsFBClick'); |
---|
| 672 | if(value) |
---|
| 673 | { |
---|
| 674 | object.bind('inputColorsFBClick', options.click); |
---|
| 675 | objects.fgopacity.addClass('ui-inputColorsFB-clickable'); |
---|
| 676 | } |
---|
| 677 | else if(options.mode==1) |
---|
| 678 | { |
---|
| 679 | objects.fgopacity.removeClass('ui-inputColorsFB-clickable'); |
---|
| 680 | } |
---|
| 681 | return(options.click); |
---|
| 682 | }, |
---|
| 683 | |
---|
| 684 | updateSizes : function (object) |
---|
| 685 | { |
---|
| 686 | var options=object.data('options'), |
---|
| 687 | objects=object.data('objects'), |
---|
| 688 | tmpSize=1; |
---|
| 689 | |
---|
| 690 | if(options.mode==2) tmpSize=options.boxSize; |
---|
| 691 | |
---|
| 692 | |
---|
| 693 | |
---|
| 694 | objects.container.css( |
---|
| 695 | { |
---|
| 696 | 'width': options.width+'px', |
---|
| 697 | 'height': options.height+'px' |
---|
| 698 | } |
---|
| 699 | ); |
---|
| 700 | objects.fgopacity.css( |
---|
| 701 | { |
---|
| 702 | 'width': (options.width*tmpSize)+'px', |
---|
| 703 | 'height': (options.height*tmpSize)+'px' |
---|
| 704 | } |
---|
| 705 | ); |
---|
| 706 | |
---|
| 707 | if(options.mode==2) |
---|
| 708 | { |
---|
| 709 | objects.bgopacity.css( |
---|
| 710 | { |
---|
| 711 | 'width': (options.width*options.boxSize)+'px', |
---|
| 712 | 'height': (options.height*options.boxSize)+'px', |
---|
| 713 | 'margin-left': (options.width*(1-options.boxSize))+'px', |
---|
| 714 | 'margin-top': (options.height*(1-options.boxSize))+'px' |
---|
| 715 | } |
---|
| 716 | ); |
---|
| 717 | } |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | }; |
---|
| 721 | |
---|
| 722 | |
---|
| 723 | $.fn.inputColorsFB = function(method) |
---|
| 724 | { |
---|
| 725 | if(publicMethods[method]) |
---|
| 726 | { |
---|
| 727 | return publicMethods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); |
---|
| 728 | } |
---|
| 729 | else if(typeof method === 'object' || ! method) |
---|
| 730 | { |
---|
| 731 | return publicMethods.init.apply(this, arguments); |
---|
| 732 | } |
---|
| 733 | else |
---|
| 734 | { |
---|
| 735 | $.error( 'Method ' + method + ' does not exist on jQuery.inputColorsFB' ); |
---|
| 736 | } |
---|
| 737 | } // $.fn.inputColorsFB |
---|
| 738 | |
---|
| 739 | } |
---|
| 740 | )(jQuery); |
---|
| 741 | |
---|
| 742 | |
---|