| 1 |
'use strict'; |
| 2 |
|
| 3 |
var $ = window.jQuery; |
| 4 |
|
| 5 |
var Option = function( element ) { |
| 6 |
|
| 7 |
// find corresponding element |
| 8 |
if( typeof(element) == "string" ) { |
| 9 |
element = document.getElementById('boxzilla-' + element); |
| 10 |
} |
| 11 |
|
| 12 |
if( ! element ) { |
| 13 |
console.error("Unable to find option element."); |
| 14 |
} |
| 15 |
|
| 16 |
this.element = element; |
| 17 |
}; |
| 18 |
|
| 19 |
Option.prototype.getColorValue = function() { |
| 20 |
if( this.element.value.length > 0 ) { |
| 21 |
if( $(this.element).hasClass('wp-color-field')) { |
| 22 |
return $(this.element).wpColorPicker('color'); |
| 23 |
} else { |
| 24 |
return this.element.value; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
return ''; |
| 29 |
}; |
| 30 |
|
| 31 |
Option.prototype.getPxValue = function( fallbackValue ) { |
| 32 |
if( this.element.value.length > 0 ) { |
| 33 |
return parseInt( this.element.value ) + "px"; |
| 34 |
} |
| 35 |
|
| 36 |
return fallbackValue || ''; |
| 37 |
}; |
| 38 |
|
| 39 |
Option.prototype.getValue = function( fallbackValue ) { |
| 40 |
|
| 41 |
if( this.element.value.length > 0 ) { |
| 42 |
return this.element.value; |
| 43 |
} |
| 44 |
|
| 45 |
return fallbackValue || ''; |
| 46 |
}; |
| 47 |
|
| 48 |
Option.prototype.clear = function() { |
| 49 |
this.element.value = ''; |
| 50 |
}; |
| 51 |
|
| 52 |
Option.prototype.setValue = function(value) { |
| 53 |
this.element.value = value; |
| 54 |
}; |
| 55 |
|
| 56 |
module.exports = Option; |