| 1 | | /* file: ui.inputText.js - v1.1.1 | minified on 2011/01/31 with http://jscompress.com/ */ |
| 2 | | /** |
| 3 | | * ----------------------------------------------------------------------------- |
| 4 | | * file: ui.inputText.js |
| 5 | | * file version: 1.1.0 |
| 6 | | * date: 2011-01-09 |
| 7 | | * |
| 8 | | * A jQuery plugin provided by the piwigo's plugin "GrumPluginClasses" |
| 9 | | * |
| 10 | | * ----------------------------------------------------------------------------- |
| 11 | | * Author : Grum |
| 12 | | * email : grum@piwigo.com |
| 13 | | * website : http://photos.grum.fr |
| 14 | | * PWG user : http://forum.phpwebgallery.net/profile.php?id=3706 |
| 15 | | * |
| 16 | | * << May the Little SpaceFrog be with you ! >> |
| 17 | | * ----------------------------------------------------------------------------- |
| 18 | | * |
| 19 | | * |
| 20 | | * |
| 21 | | * |
| 22 | | * :: HISTORY :: |
| 23 | | * |
| 24 | | * | release | date | |
| 25 | | * | 1.0.0 | 2010/11/04 | * first release |
| 26 | | * | | | |
| 27 | | * | 1.1.0 | 2011/01/09 | * if div content is not empty and text value not |
| 28 | | * | | | defined, use of div content to define text value |
| 29 | | * | | | |
| 30 | | * | | | * add multilanguage managment |
| 31 | | * | | | |
| 32 | | * | | | |
| 33 | | * | | | |
| 34 | | * |
| 35 | | */ |
| 36 | | |
| 37 | | |
| 38 | | |
| 39 | | ( |
| 40 | | function($) |
| 41 | | { |
| 42 | | /* |
| 43 | | * plugin 'public' functions |
| 44 | | */ |
| 45 | | var publicMethods = |
| 46 | | { |
| 47 | | init : function (opt) |
| 48 | | { |
| 49 | | return this.each(function() |
| 50 | | { |
| 51 | | // default values for the plugin |
| 52 | | var $this=$(this), |
| 53 | | data = $this.data('options'), |
| 54 | | objects = $this.data('objects'), |
| 55 | | properties = $this.data('properties'), |
| 56 | | options = |
| 57 | | { |
| 58 | | languages:[], |
| 59 | | currentLanguage:'', |
| 60 | | languagesValues:{}, |
| 61 | | languageSelector:'', |
| 62 | | multilines:false, |
| 63 | | disabled:false, |
| 64 | | textAlign:'left', |
| 65 | | displayChar:0, |
| 66 | | maxChar:0, |
| 67 | | numRows:1, |
| 68 | | regExp:'', |
| 69 | | value:'', |
| 70 | | change:null |
| 71 | | }; |
| 72 | | |
| 73 | | // if options given, merge it |
| 74 | | // if(opt) $.extend(options, opt); ==> options are set by setters |
| 75 | | if(options.value=='' && $.trim($this.html())!='') options.value=$.trim($this.html()); |
| 76 | | |
| 77 | | $this.data('options', options); |
| 78 | | |
| 79 | | if(!properties) |
| 80 | | { |
| 81 | | $this.data('properties', |
| 82 | | { |
| 83 | | initialized:false, |
| 84 | | re:/.*/, |
| 85 | | value:0, |
| 86 | | isValid:true, |
| 87 | | languagesValues:{} |
| 88 | | } |
| 89 | | ); |
| 90 | | properties=$this.data('properties'); |
| 91 | | } |
| 92 | | |
| 93 | | if(!objects) |
| 94 | | { |
| 95 | | objects = |
| 96 | | { |
| 97 | | container:$('<div/>', |
| 98 | | { |
| 99 | | 'class':'ui-inputText', |
| 100 | | css:{ |
| 101 | | width:'100%' |
| 102 | | } |
| 103 | | } |
| 104 | | ).bind('click.inputText', |
| 105 | | function () |
| 106 | | { |
| 107 | | objects.input.focus(); |
| 108 | | } |
| 109 | | ), |
| 110 | | input:null |
| 111 | | }; |
| 112 | | |
| 113 | | $this |
| 114 | | .html('') |
| 115 | | .append(objects.container); |
| 116 | | |
| 117 | | $this.data('objects', objects); |
| 118 | | } |
| 119 | | |
| 120 | | privateMethods.setOptions($this, opt); |
| 121 | | } |
| 122 | | ); |
| 123 | | }, // init |
| 124 | | destroy : function () |
| 125 | | { |
| 126 | | return this.each( |
| 127 | | function() |
| 128 | | { |
| 129 | | // default values for the plugin |
| 130 | | var $this=$(this), |
| 131 | | objects = $this.data('objects'); |
| 132 | | objects.input.unbind().remove(); |
| 133 | | objects.container.unbind().remove(); |
| 134 | | $this |
| 135 | | .unbind('.inputText') |
| 136 | | .css( |
| 137 | | { |
| 138 | | width:'', |
| 139 | | height:'' |
| 140 | | } |
| 141 | | ); |
| 142 | | } |
| 143 | | ); |
| 144 | | }, // destroy |
| 145 | | |
| 146 | | options: function (value) |
| 147 | | { |
| 148 | | return( |
| 149 | | this.each( |
| 150 | | function() |
| 151 | | { |
| 152 | | privateMethods.setOptions($(this), value); |
| 153 | | } |
| 154 | | ) |
| 155 | | ); |
| 156 | | }, // options |
| 157 | | |
| 158 | | disabled: function (value) |
| 159 | | { |
| 160 | | if(value!=null) |
| 161 | | { |
| 162 | | return( |
| 163 | | this.each( |
| 164 | | function() |
| 165 | | { |
| 166 | | privateMethods.setDisabled($(this), value); |
| 167 | | } |
| 168 | | ) |
| 169 | | ); |
| 170 | | } |
| 171 | | else |
| 172 | | { |
| 173 | | var options = this.data('options'); |
| 174 | | |
| 175 | | if(options) |
| 176 | | { |
| 177 | | return(options.disabled); |
| 178 | | } |
| 179 | | else |
| 180 | | { |
| 181 | | return(''); |
| 182 | | } |
| 183 | | } |
| 184 | | }, // disabled |
| 185 | | |
| 186 | | textAlign: function (value) |
| 187 | | { |
| 188 | | if(value!=null) |
| 189 | | { |
| 190 | | return( |
| 191 | | this.each( |
| 192 | | function() |
| 193 | | { |
| 194 | | privateMethods.setTextAlign($(this), value); |
| 195 | | } |
| 196 | | ) |
| 197 | | ); |
| 198 | | } |
| 199 | | else |
| 200 | | { |
| 201 | | var options = this.data('options'); |
| 202 | | |
| 203 | | if(options) |
| 204 | | { |
| 205 | | return(options.textAlign); |
| 206 | | } |
| 207 | | else |
| 208 | | { |
| 209 | | return(''); |
| 210 | | } |
| 211 | | } |
| 212 | | }, // textAlign |
| 213 | | |
| 214 | | displayChar: function (value) |
| 215 | | { |
| 216 | | if(value!=null) |
| 217 | | { |
| 218 | | return( |
| 219 | | this.each( |
| 220 | | function() |
| 221 | | { |
| 222 | | privateMethods.setDisplayChar($(this), value); |
| 223 | | } |
| 224 | | ) |
| 225 | | ); |
| 226 | | } |
| 227 | | else |
| 228 | | { |
| 229 | | var options = this.data('options'); |
| 230 | | |
| 231 | | if(options) |
| 232 | | { |
| 233 | | return(options.displayChar); |
| 234 | | } |
| 235 | | else |
| 236 | | { |
| 237 | | return(''); |
| 238 | | } |
| 239 | | } |
| 240 | | }, // displayChar |
| 241 | | |
| 242 | | maxChar: function (value) |
| 243 | | { |
| 244 | | if(value!=null) |
| 245 | | { |
| 246 | | return( |
| 247 | | this.each( |
| 248 | | function() |
| 249 | | { |
| 250 | | privateMethods.setMaxChar($(this), value); |
| 251 | | } |
| 252 | | ) |
| 253 | | ); |
| 254 | | } |
| 255 | | else |
| 256 | | { |
| 257 | | var options = this.data('options'); |
| 258 | | |
| 259 | | if(options) |
| 260 | | { |
| 261 | | return(options.maxChar); |
| 262 | | } |
| 263 | | else |
| 264 | | { |
| 265 | | return(''); |
| 266 | | } |
| 267 | | } |
| 268 | | }, // maxChar |
| 269 | | |
| 270 | | numRows: function (value) |
| 271 | | { |
| 272 | | if(value!=null) |
| 273 | | { |
| 274 | | return( |
| 275 | | this.each( |
| 276 | | function() |
| 277 | | { |
| 278 | | privateMethods.setNumRows($(this), value); |
| 279 | | } |
| 280 | | ) |
| 281 | | ); |
| 282 | | } |
| 283 | | else |
| 284 | | { |
| 285 | | var options = this.data('options'); |
| 286 | | |
| 287 | | if(options) |
| 288 | | { |
| 289 | | return(options.numRows); |
| 290 | | } |
| 291 | | else |
| 292 | | { |
| 293 | | return(''); |
| 294 | | } |
| 295 | | } |
| 296 | | }, // numRows |
| 297 | | |
| 298 | | regExp: function (value) |
| 299 | | { |
| 300 | | if(value!=null) |
| 301 | | { |
| 302 | | return( |
| 303 | | this.each( |
| 304 | | function() |
| 305 | | { |
| 306 | | privateMethods.setRegExp($(this), value); |
| 307 | | } |
| 308 | | ) |
| 309 | | ); |
| 310 | | } |
| 311 | | else |
| 312 | | { |
| 313 | | var options = this.data('options'); |
| 314 | | |
| 315 | | if(options) |
| 316 | | { |
| 317 | | return(options.regExp); |
| 318 | | } |
| 319 | | else |
| 320 | | { |
| 321 | | return(''); |
| 322 | | } |
| 323 | | } |
| 324 | | }, // regExp |
| 325 | | |
| 326 | | multilines: function () |
| 327 | | { |
| 328 | | // return the selected tags |
| 329 | | var properties=this.data('properties'); |
| 330 | | return(properties.multilines); |
| 331 | | }, // multilines |
| 332 | | |
| 333 | | languages: function (value) |
| 334 | | { |
| 335 | | if(value!=null) |
| 336 | | { |
| 337 | | // set the known languages |
| 338 | | return( |
| 339 | | this.each( |
| 340 | | function() |
| 341 | | { |
| 342 | | privateMethods.setLanguages($(this), value); |
| 343 | | } |
| 344 | | ) |
| 345 | | ); |
| 346 | | } |
| 347 | | else |
| 348 | | { |
| 349 | | // return the known languages |
| 350 | | var options = this.data('options'); |
| 351 | | return(options.languages); |
| 352 | | } |
| 353 | | }, |
| 354 | | |
| 355 | | currentLanguage: function (value) |
| 356 | | { |
| 357 | | if(value!=null) |
| 358 | | { |
| 359 | | // set the current language |
| 360 | | return( |
| 361 | | this.each( |
| 362 | | function() |
| 363 | | { |
| 364 | | privateMethods.setCurrentLanguage($(this), value); |
| 365 | | } |
| 366 | | ) |
| 367 | | ); |
| 368 | | } |
| 369 | | else |
| 370 | | { |
| 371 | | // return the current language |
| 372 | | var options = this.data('options'); |
| 373 | | return(options.currentLanguage); |
| 374 | | } |
| 375 | | }, |
| 376 | | |
| 377 | | languageSelector: function (value) |
| 378 | | { |
| 379 | | if(value!=null) |
| 380 | | { |
| 381 | | // set the language selector id (inputList object) |
| 382 | | return( |
| 383 | | this.each( |
| 384 | | function() |
| 385 | | { |
| 386 | | privateMethods.setLanguageSelector($(this), value); |
| 387 | | } |
| 388 | | ) |
| 389 | | ); |
| 390 | | } |
| 391 | | else |
| 392 | | { |
| 393 | | // return the language selector id |
| 394 | | var options = this.data('options'); |
| 395 | | return(options.languageSelector); |
| 396 | | } |
| 397 | | }, //languageSelector |
| 398 | | |
| 399 | | languagesValues: function (value) |
| 400 | | { |
| 401 | | if(value!=null) |
| 402 | | { |
| 403 | | // set the languages values |
| 404 | | return( |
| 405 | | this.each( |
| 406 | | function() |
| 407 | | { |
| 408 | | privateMethods.setLanguagesValues($(this), value); |
| 409 | | } |
| 410 | | ) |
| 411 | | ); |
| 412 | | } |
| 413 | | else |
| 414 | | { |
| 415 | | // return the languages values |
| 416 | | var properties=this.data('properties'); |
| 417 | | return(properties.languagesValues); |
| 418 | | } |
| 419 | | }, |
| 420 | | |
| 421 | | value: function (value, language) |
| 422 | | { |
| 423 | | if(value!=null) |
| 424 | | { |
| 425 | | var options=this.data('options'); |
| 426 | | |
| 427 | | // set selected value |
| 428 | | return( |
| 429 | | this.each( |
| 430 | | function() |
| 431 | | { |
| 432 | | if(language!=null) |
| 433 | | { |
| 434 | | privateMethods.setLanguageValue($(this), language, value, options.currentLanguage==language); |
| 435 | | } |
| 436 | | else |
| 437 | | { |
| 438 | | privateMethods.setValue($(this), value, true); |
| 439 | | } |
| 440 | | } |
| 441 | | ) |
| 442 | | ); |
| 443 | | } |
| 444 | | else |
| 445 | | { |
| 446 | | // return the selected tags |
| 447 | | var properties=this.data('properties'); |
| 448 | | return(properties.value); |
| 449 | | } |
| 450 | | }, // value |
| 451 | | |
| 452 | | isValid: function (value) |
| 453 | | { |
| 454 | | if(value!=null) |
| 455 | | { |
| 456 | | // set selected value |
| 457 | | return( |
| 458 | | this.each( |
| 459 | | function() |
| 460 | | { |
| 461 | | privateMethods.setIsValid($(this), value); |
| 462 | | } |
| 463 | | ) |
| 464 | | ); |
| 465 | | } |
| 466 | | else |
| 467 | | { |
| 468 | | // return the selected tags |
| 469 | | var properties=this.data('properties'); |
| 470 | | return(properties.isValid); |
| 471 | | } |
| 472 | | }, // isValid |
| 473 | | |
| 474 | | change: function (value) |
| 475 | | { |
| 476 | | if(value!=null && $.isFunction(value)) |
| 477 | | { |
| 478 | | // set selected value |
| 479 | | return( |
| 480 | | this.each( |
| 481 | | function() |
| 482 | | { |
| 483 | | privateMethods.setEventChange($(this), value); |
| 484 | | } |
| 485 | | ) |
| 486 | | ); |
| 487 | | } |
| 488 | | else |
| 489 | | { |
| 490 | | // return the selected value |
| 491 | | var options=this.data('options'); |
| 492 | | |
| 493 | | if(options) |
| 494 | | { |
| 495 | | return(options.change); |
| 496 | | } |
| 497 | | else |
| 498 | | { |
| 499 | | return(null); |
| 500 | | } |
| 501 | | } |
| 502 | | }, // change |
| 503 | | |
| 504 | | doTranslation: function () |
| 505 | | { |
| 506 | | // set selected value |
| 507 | | return( |
| 508 | | this.each( |
| 509 | | function() |
| 510 | | { |
| 511 | | privateMethods.doTranslation($(this)); |
| 512 | | } |
| 513 | | ) |
| 514 | | ); |
| 515 | | } // doTranslation |
| 516 | | |
| 517 | | }; // methods |
| 518 | | |
| 519 | | |
| 520 | | /* |
| 521 | | * plugin 'private' methods |
| 522 | | */ |
| 523 | | var privateMethods = |
| 524 | | { |
| 525 | | /** |
| 526 | | * return true is given value is a valid numeric value, according to the |
| 527 | | * rules defined by the object |
| 528 | | * @param Object object |
| 529 | | * @param value |
| 530 | | * @return Bool |
| 531 | | */ |
| 532 | | isValid : function (object, value) |
| 533 | | { |
| 534 | | var properties=object.data('properties'); |
| 535 | | |
| 536 | | return(properties.re.exec(value)) |
| 537 | | }, |
| 538 | | |
| 539 | | setOptions : function (object, value) |
| 540 | | { |
| 541 | | var properties=object.data('properties'), |
| 542 | | options=object.data('options'); |
| 543 | | |
| 544 | | if(!$.isPlainObject(value)) return(false); |
| 545 | | |
| 546 | | properties.initialized=false; |
| 547 | | |
| 548 | | privateMethods.setMultilines(object, (value.multilines!=null)?value.multilines:options.multilines); |
| 549 | | privateMethods.setDisplayChar(object, (value.displayChar!=null)?value.displayChar:options.displayChar); |
| 550 | | privateMethods.setMaxChar(object, (value.maxChar!=null)?value.maxChar:options.maxChar); |
| 551 | | privateMethods.setNumRows(object, (value.numRows!=null)?value.numRows:options.numRows); |
| 552 | | privateMethods.setRegExp(object, (value.regExp!=null)?value.regExp:options.regExp); |
| 553 | | |
| 554 | | privateMethods.setLanguages(object, (value.languages!=null)?value.languages:options.languages); |
| 555 | | privateMethods.setLanguagesValues(object, (value.languagesValues!=null)?value.languagesValues:options.languagesValues); |
| 556 | | privateMethods.setCurrentLanguage(object, (value.currentLanguage!=null)?value.currentLanguage:options.currentLanguage); |
| 557 | | privateMethods.setLanguageSelector(object, (value.languageSelector!=null)?value.languageSelector:options.languageSelector); |
| 558 | | |
| 559 | | if((properties.languagesValues[options.currentLanguage]!=null && |
| 560 | | properties.languagesValues[options.currentLanguage]!='' || |
| 561 | | properties.languagesValues[options.currentLanguage]==null) && |
| 562 | | (value.value!=null && value.value!='' || options.value!='') |
| 563 | | ) privateMethods.setValue(object, (value.value!=null)?value.value:options.value, true); |
| 564 | | |
| 565 | | privateMethods.setTextAlign(object, (value.textAlign!=null)?value.textAlign:options.textAlign); |
| 566 | | |
| 567 | | privateMethods.setEventChange(object, (value.change!=null)?value.change:options.change); |
| 568 | | |
| 569 | | properties.initialized=true; |
| 570 | | }, |
| 571 | | |
| 572 | | /** |
| 573 | | * define the regular expression used to check validity of a numeric value |
| 574 | | * @param Object object |
| 575 | | */ |
| 576 | | setRegExp : function (object, value) |
| 577 | | { |
| 578 | | var properties=object.data('properties'), |
| 579 | | flagRE=/^\/(.*)\/(.*)$/, |
| 580 | | flags=flagRE.exec(value); |
| 581 | | |
| 582 | | if(flags==null) |
| 583 | | { |
| 584 | | flags=['.*', '']; |
| 585 | | } |
| 586 | | |
| 587 | | delete properties.re; |
| 588 | | properties.re = new RegExp(flags[1],flags[2]); |
| 589 | | }, |
| 590 | | |
| 591 | | setIsValid : function (object, value) |
| 592 | | { |
| 593 | | var objects=object.data('objects'), |
| 594 | | properties=object.data('properties'); |
| 595 | | |
| 596 | | if(properties.isValid!=value && properties.initialized) |
| 597 | | { |
| 598 | | properties.isValid=value; |
| 599 | | if(properties.isValid) |
| 600 | | { |
| 601 | | objects.container.removeClass('ui-error'); |
| 602 | | objects.input.removeClass('ui-error'); |
| 603 | | } |
| 604 | | else |
| 605 | | { |
| 606 | | objects.container.addClass('ui-error'); |
| 607 | | objects.input.addClass('ui-error'); |
| 608 | | } |
| 609 | | } |
| 610 | | return(properties.isValid); |
| 611 | | }, |
| 612 | | |
| 613 | | setDisplayChar : function (object, value) |
| 614 | | { |
| 615 | | var options=object.data('options'), |
| 616 | | objects=object.data('objects'); |
| 617 | | properties=object.data('properties'); |
| 618 | | |
| 619 | | if((!properties.initialized || options.displayChar!=value) && value>=0) |
| 620 | | { |
| 621 | | options.displayChar=value; |
| 622 | | if(options.displayChar>0) |
| 623 | | { |
| 624 | | if(options.multilines) |
| 625 | | { |
| 626 | | objects.input.attr('cols', options.displayChar); |
| 627 | | } |
| 628 | | else |
| 629 | | { |
| 630 | | objects.input.attr('size', options.displayChar); |
| 631 | | } |
| 632 | | } |
| 633 | | else |
| 634 | | { |
| 635 | | if(options.multilines) |
| 636 | | { |
| 637 | | objects.input.removeAttr('size'); |
| 638 | | } |
| 639 | | else |
| 640 | | { |
| 641 | | objects.input.removeAttr('cols'); |
| 642 | | } |
| 643 | | } |
| 644 | | } |
| 645 | | if(object.width()>0) |
| 646 | | { |
| 647 | | objects.input.css( |
| 648 | | { |
| 649 | | 'width': object.width()+'px', |
| 650 | | 'max-width': object.width()+'px' |
| 651 | | } |
| 652 | | ); |
| 653 | | } |
| 654 | | return(options.displayChar); |
| 655 | | }, |
| 656 | | |
| 657 | | setMaxChar : function (object, value) |
| 658 | | { |
| 659 | | var options=object.data('options'), |
| 660 | | objects=object.data('objects'), |
| 661 | | properties=object.data('properties'); |
| 662 | | |
| 663 | | if((!properties.initialized || options.maxChar!=value) && value>=0) |
| 664 | | { |
| 665 | | options.maxChar=value; |
| 666 | | if(!options.multilines) |
| 667 | | { |
| 668 | | if(options.maxChar>0) |
| 669 | | { |
| 670 | | objects.input.attr('maxlength', options.maxChar); |
| 671 | | } |
| 672 | | else |
| 673 | | { |
| 674 | | objects.input.removeAttr('maxlength'); |
| 675 | | } |
| 676 | | } |
| 677 | | } |
| 678 | | return(options.maxChar); |
| 679 | | }, |
| 680 | | |
| 681 | | setNumRows : function (object, value) |
| 682 | | { |
| 683 | | var options=object.data('options'), |
| 684 | | objects=object.data('objects'), |
| 685 | | properties=object.data('properties'); |
| 686 | | |
| 687 | | if((!properties.initialized || options.numRows!=value) && value>0) |
| 688 | | { |
| 689 | | options.numRows=value; |
| 690 | | if(options.multilines) |
| 691 | | { |
| 692 | | objects.input.attr('rows', options.numRows); |
| 693 | | } |
| 694 | | } |
| 695 | | return(options.numRows); |
| 696 | | }, |
| 697 | | |
| 698 | | setDisabled : function (object, value) |
| 699 | | { |
| 700 | | var options=object.data('options'), |
| 701 | | objects=object.data('objects'), |
| 702 | | properties=object.data('properties'); |
| 703 | | |
| 704 | | if((!properties.initialized || options.disabled!=value) && (value==true || value==false)) |
| 705 | | { |
| 706 | | options.disabled=value; |
| 707 | | objects.input.attr('disabled', options.disabled); |
| 708 | | } |
| 709 | | return(options.disabled); |
| 710 | | }, |
| 711 | | |
| 712 | | setTextAlign : function (object, value) |
| 713 | | { |
| 714 | | var options=object.data('options'), |
| 715 | | objects=object.data('objects'), |
| 716 | | properties=object.data('properties'); |
| 717 | | |
| 718 | | if((!properties.initialized || options.textAlign!=value) && (value=='left' || value=='right')) |
| 719 | | { |
| 720 | | options.textAlign=value; |
| 721 | | objects.input.css('text-align', options.textAlign); |
| 722 | | } |
| 723 | | return(options.textAlign); |
| 724 | | }, |
| 725 | | |
| 726 | | |
| 727 | | setMultilines : function (object, value) |
| 728 | | { |
| 729 | | var options=object.data('options'), |
| 730 | | objects=object.data('objects'), |
| 731 | | properties=object.data('properties'); |
| 732 | | |
| 733 | | if((!properties.initialized || options.multilines!=value) && (value==true || value==false)) |
| 734 | | { |
| 735 | | options.multilines=value; |
| 736 | | |
| 737 | | if(options.multilines) |
| 738 | | { |
| 739 | | objects.input=$('<textarea/>'); |
| 740 | | } |
| 741 | | else |
| 742 | | { |
| 743 | | objects.input=$('<input>', |
| 744 | | { |
| 745 | | type:"text", |
| 746 | | value:'' |
| 747 | | } |
| 748 | | ); |
| 749 | | } |
| 750 | | |
| 751 | | objects.container.append( |
| 752 | | objects.input.bind('keyup.inputText', |
| 753 | | function (event) |
| 754 | | { |
| 755 | | return(privateMethods.keyUp(object, event)); |
| 756 | | } |
| 757 | | ) |
| 758 | | .bind('change.inputText', |
| 759 | | function (event) |
| 760 | | { |
| 761 | | return(privateMethods.change(object, event)); |
| 762 | | } |
| 763 | | ) |
| 764 | | .bind('keydown.inputText', |
| 765 | | function (event) |
| 766 | | { |
| 767 | | return(privateMethods.keyDown(object, event)); |
| 768 | | } |
| 769 | | ) |
| 770 | | ); |
| 771 | | |
| 772 | | } |
| 773 | | return(options.textAlign); |
| 774 | | }, //setMultilines |
| 775 | | |
| 776 | | setLanguages : function (object, value) |
| 777 | | { |
| 778 | | var properties=object.data('properties'), |
| 779 | | options=object.data('options'); |
| 780 | | |
| 781 | | options.languages=value; |
| 782 | | options.languagesValues={}; |
| 783 | | |
| 784 | | if(options.languages.length>0) |
| 785 | | { |
| 786 | | if($.inArray(options.currentLanguage, options.languages)<0 || |
| 787 | | options.currentLanguage=='') options.currentLanguage=options.languages[0]; |
| 788 | | |
| 789 | | for(var i=0;i<options.languages.length;i++) |
| 790 | | { |
| 791 | | properties.languagesValues[options.languages[i]]=''; |
| 792 | | } |
| 793 | | } |
| 794 | | else |
| 795 | | { |
| 796 | | options.currentLanguage=''; |
| 797 | | } |
| 798 | | |
| 799 | | return(options.languages); |
| 800 | | }, //setLanguages |
| 801 | | |
| 802 | | setLanguagesValues : function (object, value) |
| 803 | | { |
| 804 | | var options=object.data('options'), |
| 805 | | properties=object.data('properties'); |
| 806 | | |
| 807 | | if(value==':clear') |
| 808 | | { |
| 809 | | for(var langValue in properties.languagesValues) |
| 810 | | { |
| 811 | | privateMethods.setLanguageValue(object, langValue, '', langValue==options.currentLanguage); |
| 812 | | } |
| 813 | | } |
| 814 | | else if(!$.isEmptyObject(value)) |
| 815 | | { |
| 816 | | for(var langValue in value) |
| 817 | | { |
| 818 | | if(properties.languagesValues[langValue]!=null) |
| 819 | | privateMethods.setLanguageValue(object, langValue, value[langValue], langValue==options.currentLanguage); |
| 820 | | } |
| 821 | | } |
| 822 | | |
| 823 | | return(properties.languagesValues); |
| 824 | | }, //setLanguagesValues |
| 825 | | |
| 826 | | setLanguageValue : function (object, language, value, updateInput) |
| 827 | | { |
| 828 | | var options=object.data('options'), |
| 829 | | properties=object.data('properties'); |
| 830 | | |
| 831 | | if(properties.languagesValues[language]!=null) |
| 832 | | { |
| 833 | | properties.languagesValues[language]=value; |
| 834 | | |
| 835 | | if(updateInput) privateMethods.setValue(object, properties.languagesValues[options.currentLanguage], true); |
| 836 | | } |
| 837 | | |
| 838 | | return(options.languagesValues); |
| 839 | | }, //setLanguageValue |
| 840 | | |
| 841 | | setCurrentLanguage : function (object, value) |
| 842 | | { |
| 843 | | var options=object.data('options'), |
| 844 | | properties=object.data('properties'); |
| 845 | | |
| 846 | | if((!properties.initialized || options.currentLanguage!=value) && $.inArray(value, options.languages)>=0) |
| 847 | | { |
| 848 | | options.currentLanguage=value; |
| 849 | | |
| 850 | | privateMethods.setValue(object, properties.languagesValues[options.currentLanguage], true); |
| 851 | | } |
| 852 | | |
| 853 | | return(options.currentLanguage); |
| 854 | | }, //setCurrentLanguage |
| 855 | | |
| 856 | | setLanguageSelector : function (object, value) |
| 857 | | { |
| 858 | | var options=object.data('options'), |
| 859 | | properties=object.data('properties'); |
| 860 | | |
| 861 | | if((!properties.initialized || options.languageSelector!=value) && value!='' && $('#'+value).length>0) |
| 862 | | { |
| 863 | | if(options.languageSelector!='') $('#'+options.languageSelector).unbind('inputListChange'); |
| 864 | | options.languageSelector=value; |
| 865 | | |
| 866 | | if(options.languageSelector!='') |
| 867 | | $('#'+options.languageSelector).bind('inputListChange', |
| 868 | | function (event, lang) |
| 869 | | { |
| 870 | | privateMethods.setCurrentLanguage(object, lang); |
| 871 | | } |
| 872 | | ); |
| 873 | | } |
| 874 | | |
| 875 | | return(options.currentLanguage); |
| 876 | | }, //setCurrentLanguage |
| 877 | | |
| 878 | | setValue : function (object, value, apply) |
| 879 | | { |
| 880 | | var options=object.data('options'), |
| 881 | | properties=object.data('properties'), |
| 882 | | objects=object.data('objects'); |
| 883 | | |
| 884 | | if(properties.initialized && properties.value==value) |
| 885 | | { |
| 886 | | return(properties.value); |
| 887 | | } |
| 888 | | |
| 889 | | privateMethods.setIsValid(object, true); |
| 890 | | |
| 891 | | properties.value=value; |
| 892 | | |
| 893 | | if(apply) |
| 894 | | { |
| 895 | | objects.input.val(properties.value); |
| 896 | | } |
| 897 | | |
| 898 | | if(options.currentLanguage!='') privateMethods.setLanguageValue(object, options.currentLanguage, value, false); |
| 899 | | |
| 900 | | if(options.change) object.trigger('inputTextChange', properties.value); |
| 901 | | |
| 902 | | return(properties.value); |
| 903 | | }, //setValue |
| 904 | | |
| 905 | | setEventChange : function (object, value) |
| 906 | | { |
| 907 | | var options=object.data('options'); |
| 908 | | |
| 909 | | options.change=value; |
| 910 | | object.unbind('inputTextChange'); |
| 911 | | if(value) object.bind('inputTextChange', options.change); |
| 912 | | return(options.change); |
| 913 | | }, |
| 914 | | |
| 915 | | keyUp : function (object, event) |
| 916 | | { |
| 917 | | var objects=object.data('objects'); |
| 918 | | |
| 919 | | if(event.keyCode==9 || //DOM_VK_TAB |
| 920 | | event.keyCode==12 || //DOM_VK_CLEAR |
| 921 | | event.keyCode==16 || //DOM_VK_SHIFT |
| 922 | | event.keyCode==17 || //DOM_VK_CONTROL |
| 923 | | event.keyCode==18 || //DOM_VK_ALT |
| 924 | | event.keyCode==33 || //DOM_VK_PAGE_UP |
| 925 | | event.keyCode==34 || //DOM_VK_PAGE_DOWN |
| 926 | | event.keyCode==35 || //DOM_VK_END |
| 927 | | event.keyCode==36 || //DOM_VK_HOME |
| 928 | | event.keyCode==37 || //DOM_VK_LEFT |
| 929 | | event.keyCode==38 || //DOM_VK_UP |
| 930 | | event.keyCode==39 || //DOM_VK_RIGHT |
| 931 | | event.keyCode==40 || //DOM_VK_DOWN |
| 932 | | event.keyCode==45 || //DOM_VK_INSERT |
| 933 | | event.keyCode==93 //DOM_VK_CONTEXT_MENU |
| 934 | | ) return(false); |
| 935 | | |
| 936 | | return(privateMethods.setValue(object, objects.input.val(), false)); |
| 937 | | }, |
| 938 | | |
| 939 | | change : function (object, event) |
| 940 | | { |
| 941 | | var objects=object.data('objects'); |
| 942 | | |
| 943 | | return(privateMethods.setValue(object, objects.input.val(), false)) |
| 944 | | }, |
| 945 | | |
| 946 | | keyDown : function (object, event) |
| 947 | | { |
| 948 | | var objects=object.data('objects'), |
| 949 | | options=object.data('options'); |
| 950 | | |
| 951 | | if(options.maxChar>0 && |
| 952 | | objects.input.val().length>=options.maxChar && |
| 953 | | !(event.keyCode==8 || //DOM_VK_BACK_SPACE |
| 954 | | event.keyCode==9 || //DOM_VK_TAB |
| 955 | | event.keyCode==12 || //DOM_VK_CLEAR |
| 956 | | event.keyCode==16 || //DOM_VK_SHIFT |
| 957 | | event.keyCode==17 || //DOM_VK_CONTROL |
| 958 | | event.keyCode==18 || //DOM_VK_ALT |
| 959 | | event.keyCode==33 || //DOM_VK_PAGE_UP |
| 960 | | event.keyCode==34 || //DOM_VK_PAGE_DOWN |
| 961 | | event.keyCode==35 || //DOM_VK_END |
| 962 | | event.keyCode==36 || //DOM_VK_HOME |
| 963 | | event.keyCode==37 || //DOM_VK_LEFT |
| 964 | | event.keyCode==38 || //DOM_VK_UP |
| 965 | | event.keyCode==39 || //DOM_VK_RIGHT |
| 966 | | event.keyCode==40 || //DOM_VK_DOWN |
| 967 | | event.keyCode==45 || //DOM_VK_INSERT |
| 968 | | event.keyCode==46 || //DOM_VK_DELETE |
| 969 | | event.keyCode==93 || //DOM_VK_CONTEXT_MENU |
| 970 | | objects.input.get(0).selectionStart!=objects.input.get(0).selectionEnd |
| 971 | | ) |
| 972 | | ) return(false); |
| 973 | | }, |
| 974 | | |
| 975 | | /** |
| 976 | | * do translation through a google translate API call (need the GPC google_translate.js file is loaded) |
| 977 | | * |
| 978 | | * @param String input : id of input field ; if empty, translate all localized fields |
| 979 | | */ |
| 980 | | doTranslation : function(object) |
| 981 | | { |
| 982 | | var objects=object.data('objects'), |
| 983 | | properties=object.data('properties'), |
| 984 | | options=object.data('options'); |
| 985 | | |
| 986 | | if(googleTranslate!=null) |
| 987 | | { |
| 988 | | googleTranslate(properties.value, '', options.currentLanguage.substr(0,2), |
| 989 | | function (result) |
| 990 | | { |
| 991 | | privateMethods.setValue(object, result, true); |
| 992 | | } |
| 993 | | ); |
| 994 | | } |
| 995 | | } |
| 996 | | |
| 997 | | }; |
| 998 | | |
| 999 | | |
| 1000 | | $.fn.inputText = function(method) |
| 1001 | | { |
| 1002 | | if(publicMethods[method]) |
| 1003 | | { |
| 1004 | | return publicMethods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); |
| 1005 | | } |
| 1006 | | else if(typeof method === 'object' || ! method) |
| 1007 | | { |
| 1008 | | return publicMethods.init.apply(this, arguments); |
| 1009 | | } |
| 1010 | | else |
| 1011 | | { |
| 1012 | | $.error( 'Method ' + method + ' does not exist on jQuery.inputText' ); |
| 1013 | | } |
| 1014 | | } // $.fn.inputText |
| 1015 | | |
| 1016 | | } |
| 1017 | | )(jQuery); |
| 1018 | | |
| 1019 | | |
| | 1 | (function($) |
| | 2 | {var publicMethods={init:function(opt) |
| | 3 | {return this.each(function() |
| | 4 | {var $this=$(this),data=$this.data('options'),objects=$this.data('objects'),properties=$this.data('properties'),options={languages:[],currentLanguage:'',languagesValues:{},languageSelector:'',multilines:false,disabled:false,textAlign:'left',displayChar:0,maxChar:0,numRows:1,regExp:'',value:'',change:null};if(options.value==''&&$.trim($this.html())!='')options.value=$.trim($this.html());$this.data('options',options);if(!properties) |
| | 5 | {$this.data('properties',{initialized:false,re:/.*/,value:0,isValid:true,languagesValues:{}});properties=$this.data('properties');} |
| | 6 | if(!objects) |
| | 7 | {objects={container:$('<div/>',{'class':'ui-inputText',css:{width:'100%'}}).bind('click.inputText',function() |
| | 8 | {objects.input.focus();}),input:null};$this.html('').append(objects.container);$this.data('objects',objects);} |
| | 9 | privateMethods.setOptions($this,opt);});},destroy:function() |
| | 10 | {return this.each(function() |
| | 11 | {var $this=$(this),objects=$this.data('objects');objects.input.unbind().remove();objects.container.unbind().remove();$this.unbind('.inputText').css({width:'',height:''});});},options:function(value) |
| | 12 | {return(this.each(function() |
| | 13 | {privateMethods.setOptions($(this),value);}));},disabled:function(value) |
| | 14 | {if(value!=null) |
| | 15 | {return(this.each(function() |
| | 16 | {privateMethods.setDisabled($(this),value);}));} |
| | 17 | else |
| | 18 | {var options=this.data('options');if(options) |
| | 19 | {return(options.disabled);} |
| | 20 | else |
| | 21 | {return('');}}},textAlign:function(value) |
| | 22 | {if(value!=null) |
| | 23 | {return(this.each(function() |
| | 24 | {privateMethods.setTextAlign($(this),value);}));} |
| | 25 | else |
| | 26 | {var options=this.data('options');if(options) |
| | 27 | {return(options.textAlign);} |
| | 28 | else |
| | 29 | {return('');}}},displayChar:function(value) |
| | 30 | {if(value!=null) |
| | 31 | {return(this.each(function() |
| | 32 | {privateMethods.setDisplayChar($(this),value);}));} |
| | 33 | else |
| | 34 | {var options=this.data('options');if(options) |
| | 35 | {return(options.displayChar);} |
| | 36 | else |
| | 37 | {return('');}}},maxChar:function(value) |
| | 38 | {if(value!=null) |
| | 39 | {return(this.each(function() |
| | 40 | {privateMethods.setMaxChar($(this),value);}));} |
| | 41 | else |
| | 42 | {var options=this.data('options');if(options) |
| | 43 | {return(options.maxChar);} |
| | 44 | else |
| | 45 | {return('');}}},numRows:function(value) |
| | 46 | {if(value!=null) |
| | 47 | {return(this.each(function() |
| | 48 | {privateMethods.setNumRows($(this),value);}));} |
| | 49 | else |
| | 50 | {var options=this.data('options');if(options) |
| | 51 | {return(options.numRows);} |
| | 52 | else |
| | 53 | {return('');}}},regExp:function(value) |
| | 54 | {if(value!=null) |
| | 55 | {return(this.each(function() |
| | 56 | {privateMethods.setRegExp($(this),value);}));} |
| | 57 | else |
| | 58 | {var options=this.data('options');if(options) |
| | 59 | {return(options.regExp);} |
| | 60 | else |
| | 61 | {return('');}}},multilines:function() |
| | 62 | {var properties=this.data('properties');return(properties.multilines);},languages:function(value) |
| | 63 | {if(value!=null) |
| | 64 | {return(this.each(function() |
| | 65 | {privateMethods.setLanguages($(this),value);}));} |
| | 66 | else |
| | 67 | {var options=this.data('options');return(options.languages);}},currentLanguage:function(value) |
| | 68 | {if(value!=null) |
| | 69 | {return(this.each(function() |
| | 70 | {privateMethods.setCurrentLanguage($(this),value);}));} |
| | 71 | else |
| | 72 | {var options=this.data('options');return(options.currentLanguage);}},languageSelector:function(value) |
| | 73 | {if(value!=null) |
| | 74 | {return(this.each(function() |
| | 75 | {privateMethods.setLanguageSelector($(this),value);}));} |
| | 76 | else |
| | 77 | {var options=this.data('options');return(options.languageSelector);}},languagesValues:function(value) |
| | 78 | {if(value!=null) |
| | 79 | {return(this.each(function() |
| | 80 | {privateMethods.setLanguagesValues($(this),value);}));} |
| | 81 | else |
| | 82 | {var properties=this.data('properties');return(properties.languagesValues);}},value:function(value,language) |
| | 83 | {if(value!=null) |
| | 84 | {var options=this.data('options');return(this.each(function() |
| | 85 | {if(language!=null) |
| | 86 | {privateMethods.setLanguageValue($(this),language,value,options.currentLanguage==language);} |
| | 87 | else |
| | 88 | {privateMethods.setValue($(this),value,true);}}));} |
| | 89 | else |
| | 90 | {var properties=this.data('properties');return(properties.value);}},isValid:function(value) |
| | 91 | {if(value!=null) |
| | 92 | {return(this.each(function() |
| | 93 | {privateMethods.setIsValid($(this),value);}));} |
| | 94 | else |
| | 95 | {var properties=this.data('properties');return(properties.isValid);}},change:function(value) |
| | 96 | {if(value!=null&&$.isFunction(value)) |
| | 97 | {return(this.each(function() |
| | 98 | {privateMethods.setEventChange($(this),value);}));} |
| | 99 | else |
| | 100 | {var options=this.data('options');if(options) |
| | 101 | {return(options.change);} |
| | 102 | else |
| | 103 | {return(null);}}},doTranslation:function() |
| | 104 | {return(this.each(function() |
| | 105 | {privateMethods.doTranslation($(this));}));}};var privateMethods={isValid:function(object,value) |
| | 106 | {var properties=object.data('properties');return(properties.re.exec(value))},setOptions:function(object,value) |
| | 107 | {var properties=object.data('properties'),options=object.data('options');if(!$.isPlainObject(value))return(false);properties.initialized=false;privateMethods.setMultilines(object,(value.multilines!=null)?value.multilines:options.multilines);privateMethods.setDisplayChar(object,(value.displayChar!=null)?value.displayChar:options.displayChar);privateMethods.setMaxChar(object,(value.maxChar!=null)?value.maxChar:options.maxChar);privateMethods.setNumRows(object,(value.numRows!=null)?value.numRows:options.numRows);privateMethods.setRegExp(object,(value.regExp!=null)?value.regExp:options.regExp);privateMethods.setLanguages(object,(value.languages!=null)?value.languages:options.languages);privateMethods.setLanguagesValues(object,(value.languagesValues!=null)?value.languagesValues:options.languagesValues);privateMethods.setCurrentLanguage(object,(value.currentLanguage!=null)?value.currentLanguage:options.currentLanguage);privateMethods.setLanguageSelector(object,(value.languageSelector!=null)?value.languageSelector:options.languageSelector);if((properties.languagesValues[options.currentLanguage]!=null&&properties.languagesValues[options.currentLanguage]!=''||properties.languagesValues[options.currentLanguage]==null)&&(value.value!=null&&value.value!=''||options.value!=''))privateMethods.setValue(object,(value.value!=null)?value.value:options.value,true);privateMethods.setTextAlign(object,(value.textAlign!=null)?value.textAlign:options.textAlign);privateMethods.setEventChange(object,(value.change!=null)?value.change:options.change);properties.initialized=true;},setRegExp:function(object,value) |
| | 108 | {var properties=object.data('properties'),flagRE=/^\/(.*)\/(.*)$/,flags=flagRE.exec(value);if(flags==null) |
| | 109 | {flags=['.*',''];} |
| | 110 | delete properties.re;properties.re=new RegExp(flags[1],flags[2]);},setIsValid:function(object,value) |
| | 111 | {var objects=object.data('objects'),properties=object.data('properties');if(properties.isValid!=value&&properties.initialized) |
| | 112 | {properties.isValid=value;if(properties.isValid) |
| | 113 | {objects.container.removeClass('ui-error');objects.input.removeClass('ui-error');} |
| | 114 | else |
| | 115 | {objects.container.addClass('ui-error');objects.input.addClass('ui-error');}} |
| | 116 | return(properties.isValid);},setDisplayChar:function(object,value) |
| | 117 | {var options=object.data('options'),objects=object.data('objects');properties=object.data('properties');if((!properties.initialized||options.displayChar!=value)&&value>=0) |
| | 118 | {options.displayChar=value;if(options.displayChar>0) |
| | 119 | {if(options.multilines) |
| | 120 | {objects.input.attr('cols',options.displayChar);} |
| | 121 | else |
| | 122 | {objects.input.attr('size',options.displayChar);}} |
| | 123 | else |
| | 124 | {if(options.multilines) |
| | 125 | {objects.input.removeAttr('size');} |
| | 126 | else |
| | 127 | {objects.input.removeAttr('cols');}}} |
| | 128 | if(object.width()>0) |
| | 129 | {objects.input.css({'width':object.width()+'px','max-width':object.width()+'px'});} |
| | 130 | return(options.displayChar);},setMaxChar:function(object,value) |
| | 131 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.maxChar!=value)&&value>=0) |
| | 132 | {options.maxChar=value;if(!options.multilines) |
| | 133 | {if(options.maxChar>0) |
| | 134 | {objects.input.attr('maxlength',options.maxChar);} |
| | 135 | else |
| | 136 | {objects.input.removeAttr('maxlength');}}} |
| | 137 | return(options.maxChar);},setNumRows:function(object,value) |
| | 138 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.numRows!=value)&&value>0) |
| | 139 | {options.numRows=value;if(options.multilines) |
| | 140 | {objects.input.attr('rows',options.numRows);}} |
| | 141 | return(options.numRows);},setDisabled:function(object,value) |
| | 142 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.disabled!=value)&&(value==true||value==false)) |
| | 143 | {options.disabled=value;objects.input.attr('disabled',options.disabled);} |
| | 144 | return(options.disabled);},setTextAlign:function(object,value) |
| | 145 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.textAlign!=value)&&(value=='left'||value=='right')) |
| | 146 | {options.textAlign=value;objects.input.css('text-align',options.textAlign);} |
| | 147 | return(options.textAlign);},setMultilines:function(object,value) |
| | 148 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.multilines!=value)&&(value==true||value==false)) |
| | 149 | {options.multilines=value;if(options.multilines) |
| | 150 | {objects.input=$('<textarea/>');} |
| | 151 | else |
| | 152 | {objects.input=$('<input>',{type:"text",value:''});} |
| | 153 | objects.container.append(objects.input.bind('keyup.inputText',function(event) |
| | 154 | {return(privateMethods.keyUp(object,event));}).bind('change.inputText',function(event) |
| | 155 | {return(privateMethods.change(object,event));}).bind('keydown.inputText',function(event) |
| | 156 | {return(privateMethods.keyDown(object,event));}));} |
| | 157 | return(options.textAlign);},setLanguages:function(object,value) |
| | 158 | {var properties=object.data('properties'),options=object.data('options');options.languages=value;options.languagesValues={};if(options.languages.length>0) |
| | 159 | {if($.inArray(options.currentLanguage,options.languages)<0||options.currentLanguage=='')options.currentLanguage=options.languages[0];for(var i=0;i<options.languages.length;i++) |
| | 160 | {properties.languagesValues[options.languages[i]]='';}} |
| | 161 | else |
| | 162 | {options.currentLanguage='';} |
| | 163 | return(options.languages);},setLanguagesValues:function(object,value) |
| | 164 | {var options=object.data('options'),properties=object.data('properties');if(value==':clear') |
| | 165 | {for(var langValue in properties.languagesValues) |
| | 166 | {privateMethods.setLanguageValue(object,langValue,'',langValue==options.currentLanguage);}} |
| | 167 | else if(!$.isEmptyObject(value)) |
| | 168 | {for(var langValue in value) |
| | 169 | {if(properties.languagesValues[langValue]!=null) |
| | 170 | privateMethods.setLanguageValue(object,langValue,value[langValue],langValue==options.currentLanguage);}} |
| | 171 | return(properties.languagesValues);},setLanguageValue:function(object,language,value,updateInput) |
| | 172 | {var options=object.data('options'),properties=object.data('properties');if(properties.languagesValues[language]!=null) |
| | 173 | {properties.languagesValues[language]=value;if(updateInput)privateMethods.setValue(object,properties.languagesValues[options.currentLanguage],true);} |
| | 174 | return(options.languagesValues);},setCurrentLanguage:function(object,value) |
| | 175 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.currentLanguage!=value)&&$.inArray(value,options.languages)>=0) |
| | 176 | {options.currentLanguage=value;privateMethods.setValue(object,properties.languagesValues[options.currentLanguage],true);} |
| | 177 | return(options.currentLanguage);},setLanguageSelector:function(object,value) |
| | 178 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.languageSelector!=value)&&value!=''&&$('#'+value).length>0) |
| | 179 | {if(options.languageSelector!='')$('#'+options.languageSelector).unbind('inputListChange');options.languageSelector=value;if(options.languageSelector!='') |
| | 180 | $('#'+options.languageSelector).bind('inputListChange',function(event,lang) |
| | 181 | {privateMethods.setCurrentLanguage(object,lang);});} |
| | 182 | return(options.currentLanguage);},setValue:function(object,value,apply) |
| | 183 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if(properties.initialized&&properties.value==value) |
| | 184 | {return(properties.value);} |
| | 185 | privateMethods.setIsValid(object,true);properties.value=value;if(apply) |
| | 186 | {objects.input.val(properties.value);} |
| | 187 | if(options.currentLanguage!='')privateMethods.setLanguageValue(object,options.currentLanguage,value,false);if(options.change)object.trigger('inputTextChange',properties.value);return(properties.value);},setEventChange:function(object,value) |
| | 188 | {var options=object.data('options');options.change=value;object.unbind('inputTextChange');if(value)object.bind('inputTextChange',options.change);return(options.change);},keyUp:function(object,event) |
| | 189 | {var objects=object.data('objects');if(event.keyCode==9||event.keyCode==12||event.keyCode==16||event.keyCode==17||event.keyCode==18||event.keyCode==33||event.keyCode==34||event.keyCode==35||event.keyCode==36||event.keyCode==37||event.keyCode==38||event.keyCode==39||event.keyCode==40||event.keyCode==45||event.keyCode==93)return(false);return(privateMethods.setValue(object,objects.input.val(),false));},change:function(object,event) |
| | 190 | {var objects=object.data('objects');return(privateMethods.setValue(object,objects.input.val(),false))},keyDown:function(object,event) |
| | 191 | {var objects=object.data('objects'),options=object.data('options');if(options.maxChar>0&&objects.input.val().length>=options.maxChar&&!(event.keyCode==8||event.keyCode==9||event.keyCode==12||event.keyCode==16||event.keyCode==17||event.keyCode==18||event.keyCode==33||event.keyCode==34||event.keyCode==35||event.keyCode==36||event.keyCode==37||event.keyCode==38||event.keyCode==39||event.keyCode==40||event.keyCode==45||event.keyCode==46||event.keyCode==93||objects.input.get(0).selectionStart!=objects.input.get(0).selectionEnd))return(false);},doTranslation:function(object) |
| | 192 | {var objects=object.data('objects'),properties=object.data('properties'),options=object.data('options');if(googleTranslate!=null) |
| | 193 | {googleTranslate(properties.value,'',options.currentLanguage.substr(0,2),function(result) |
| | 194 | {privateMethods.setValue(object,result,true);});}}};$.fn.inputText=function(method) |
| | 195 | {if(publicMethods[method]) |
| | 196 | {return publicMethods[method].apply(this,Array.prototype.slice.call(arguments,1));} |
| | 197 | else if(typeof method==='object'||!method) |
| | 198 | {return publicMethods.init.apply(this,arguments);} |
| | 199 | else |
| | 200 | {$.error('Method '+method+' does not exist on jQuery.inputText');}}})(jQuery); |