|
382 | 382 | }); |
383 | 383 |
|
384 | 384 | })(); |
| 385 | +;/** |
| 386 | + * Created by narendra on 13/4/15. |
| 387 | + */ |
| 388 | + |
| 389 | +(function() { |
| 390 | + "use strict"; |
| 391 | + |
| 392 | + var boolStringToBoolean = { |
| 393 | + "true": true, |
| 394 | + "false": false, |
| 395 | + null: false, |
| 396 | + "": true |
| 397 | + }; |
| 398 | + pitana.accessorType = {}; |
| 399 | + pitana.accessorType.int = { |
| 400 | + get: function(attrName, attrObj) { |
| 401 | + var val = this.getAttribute(attrName); |
| 402 | + if (val !== null) { |
| 403 | + return parseInt(val, 10); |
| 404 | + } else { |
| 405 | + return attrObj.default; |
| 406 | + } |
| 407 | + }, |
| 408 | + set: function(attrName, newVal, attrObj) { |
| 409 | + if (typeof newVal === "number" && this[attrName] !== newVal + "") { |
| 410 | + this.setAttribute(attrName, newVal); |
| 411 | + } |
| 412 | + } |
| 413 | + }; |
| 414 | + |
| 415 | + pitana.accessorType.boolean = { |
| 416 | + get: function(attrName) { |
| 417 | + var val = boolStringToBoolean[this.getAttribute(attrName)]; |
| 418 | + if (val === undefined) { |
| 419 | + return false; |
| 420 | + } else { |
| 421 | + return val; |
| 422 | + } |
| 423 | + }, |
| 424 | + set: function(attrName, newVal, attrObj) { |
| 425 | + if (this[attrName] !== newVal && typeof newVal === "boolean") { |
| 426 | + if (newVal === true) { |
| 427 | + this.setAttribute(attrName, ""); |
| 428 | + } else { |
| 429 | + this.removeAttribute(attrName); |
| 430 | + } |
| 431 | + } |
| 432 | + } |
| 433 | + }; |
| 434 | +})(); |
385 | 435 | ;/** |
386 | 436 | * Created by narendra on 15/3/15. |
387 | 437 | */ |
|
437 | 487 | view.attributeChangedCallback.apply(view, arguments); |
438 | 488 | }; |
439 | 489 |
|
440 | | - ElementPrototype.getIntegerAttribute = function(attrName, attrObj) { |
441 | | - var val = this.getAttribute(attrName); |
442 | | - if (val !== null) { |
443 | | - return parseInt(val, 10); |
444 | | - } else { |
445 | | - return attrObj.default; |
446 | | - } |
447 | | - }; |
448 | | - ElementPrototype.setIntegerAttribute = function(attrName, newVal, attrObj) { |
449 | | - if (typeof newVal === "number" && this[attrName] !== newVal + "") { |
450 | | - this.setAttribute(attrName, newVal); |
451 | | - } |
452 | | - }; |
453 | | - ElementPrototype.getBooleanAttribute = function(attr) { |
454 | | - var boolStringToBoolean = { |
455 | | - "true": true, |
456 | | - "false": false, |
457 | | - null: false, |
458 | | - "": true |
459 | | - }; |
460 | | - var val = boolStringToBoolean[this.getAttribute(attr)]; |
461 | | - if (val === undefined) { |
462 | | - return false; |
463 | | - } else { |
464 | | - return val; |
465 | | - } |
466 | | - }; |
467 | | - ElementPrototype.setBooleanAttribute = function(attr, newVal) { |
468 | | - if (this[attr] !== newVal && typeof newVal === "boolean") { |
469 | | - if (newVal === true) { |
470 | | - this.setAttribute(attr, ""); |
471 | | - } else { |
472 | | - this.removeAttribute(attr); |
473 | | - } |
474 | | - } |
475 | | - }; |
476 | | - |
477 | 490 | if (ViewConstructor.prototype.accessors !== undefined) { |
478 | 491 | pitana.util.for(ViewConstructor.prototype.accessors, function(attrObj, attrName) { |
479 | 492 | var Prop = {}; |
480 | 493 | Prop[attrName] = { |
481 | 494 | get: function() { |
482 | | - switch (attrObj.type) { |
483 | | - case "int": |
484 | | - return this.getIntegerAttribute(attrName, attrObj); |
485 | | - case "boolean": |
486 | | - return this.getBooleanAttribute(attrName, attrObj); |
487 | | - default: |
488 | | - return this.getAttribute(attrName); |
| 495 | + if (pitana.accessorType[attrObj.type] !== undefined) { |
| 496 | + return pitana.accessorType[attrObj.type].get.call(this, attrName, attrObj); |
| 497 | + } else { |
| 498 | + return this.getAttribute(attrName); |
489 | 499 | } |
490 | 500 | }, |
491 | 501 | set: function(newVal) { |
492 | | - switch (attrObj.type) { |
493 | | - case "int": |
494 | | - this.setIntegerAttribute(attrName, newVal, attrObj); |
495 | | - break; |
496 | | - case "boolean": |
497 | | - this.setBooleanAttribute(attrName, newVal, attrObj); |
498 | | - break; |
499 | | - default: |
500 | | - this.setAttribute(attrName, newVal); |
501 | | - break; |
| 502 | + if (pitana.accessorType[attrObj.type] !== undefined) { |
| 503 | + pitana.accessorType[attrObj.type].set.call(this, attrName, newVal, attrObj); |
| 504 | + } else { |
| 505 | + this.setAttribute(attrName, newVal); |
502 | 506 | } |
503 | 507 | if (typeof attrObj.afterSet === "function") { |
504 | 508 | attrObj.afterSet.apply(pitana.nodeToViewMapping.get(this), arguments); |
|
0 commit comments