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