FileInput: handle disabled option
This commit is contained in:
parent
abc6cbbb15
commit
f93c575c8f
1 changed files with 20 additions and 4 deletions
|
@ -2,10 +2,16 @@
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.FileInput <f> File Input
|
Ox.FileInput <f> File Input
|
||||||
|
options <o> Options
|
||||||
|
disabled <b|false> If true, the element is disabled
|
||||||
|
maxFiles <n|-1> Maximum number of files (or -1 for unlimited)
|
||||||
|
maxLines <n|-1> Maximum number of lines to display (or -1 for unlimited)
|
||||||
|
maxSize <n|-1> Maximum total file size in bytes (or -1 for unlimited)
|
||||||
|
value <a|[]> Value (array of file objects)
|
||||||
|
width <w|256> Width in px
|
||||||
|
self <o> Shared private variable
|
||||||
([options[, self]]) -> <o:Ox.Element> File Input
|
([options[, self]]) -> <o:Ox.Element> File Input
|
||||||
change <!> change
|
change <!> change
|
||||||
options <o> Options
|
|
||||||
self <o> Shared private variable
|
|
||||||
@*/
|
@*/
|
||||||
|
|
||||||
Ox.FileInput = function(options, self) {
|
Ox.FileInput = function(options, self) {
|
||||||
|
@ -13,6 +19,7 @@ Ox.FileInput = function(options, self) {
|
||||||
self = self || {};
|
self = self || {};
|
||||||
var that = Ox.Element({}, self)
|
var that = Ox.Element({}, self)
|
||||||
.defaults({
|
.defaults({
|
||||||
|
disabled: false,
|
||||||
maxFiles: -1,
|
maxFiles: -1,
|
||||||
maxLines: -1,
|
maxLines: -1,
|
||||||
maxSize: -1,
|
maxSize: -1,
|
||||||
|
@ -20,7 +27,14 @@ Ox.FileInput = function(options, self) {
|
||||||
width: 256
|
width: 256
|
||||||
})
|
})
|
||||||
.options(options || {})
|
.options(options || {})
|
||||||
.addClass('OxFileInput')
|
.update({
|
||||||
|
disabled: function() {
|
||||||
|
that[self.options.disabled ? 'addClass' : 'removeClass']('OxDisabled');
|
||||||
|
self.$button.options({disabled: self.options.disabled});
|
||||||
|
self.$input && self.$input[self.options.disabled ? 'hide' : 'show']();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.addClass('OxFileInput' + (self.options.disabled ? ' OxDisabled' : ''))
|
||||||
.css({width: self.options.width + 'px'});
|
.css({width: self.options.width + 'px'});
|
||||||
|
|
||||||
self.multiple = self.options.maxFiles != 1;
|
self.multiple = self.options.maxFiles != 1;
|
||||||
|
@ -60,6 +74,7 @@ Ox.FileInput = function(options, self) {
|
||||||
.appendTo(self.$bar);
|
.appendTo(self.$bar);
|
||||||
|
|
||||||
self.$button = Ox.Button({
|
self.$button = Ox.Button({
|
||||||
|
disabled: self.options.disabled,
|
||||||
style: 'symbol',
|
style: 'symbol',
|
||||||
title: self.multiple || self.options.value.length == 0
|
title: self.multiple || self.options.value.length == 0
|
||||||
? 'add' : 'close',
|
? 'add' : 'close',
|
||||||
|
@ -80,6 +95,7 @@ Ox.FileInput = function(options, self) {
|
||||||
|
|
||||||
if (self.multiple || self.options.value.length == 0) {
|
if (self.multiple || self.options.value.length == 0) {
|
||||||
self.$input = renderInput();
|
self.$input = renderInput();
|
||||||
|
self.options.disabled && self.$input.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.multiple) {
|
if (self.multiple) {
|
||||||
|
@ -158,7 +174,7 @@ Ox.FileInput = function(options, self) {
|
||||||
b = b.name.toLowerCase();
|
b = b.name.toLowerCase();
|
||||||
return a < b ? -1 : a > b ? 1 : 0;
|
return a < b ? -1 : a > b ? 1 : 0;
|
||||||
} : function(a, b) {
|
} : function(a, b) {
|
||||||
// if there's a max size,
|
// if there is a max size,
|
||||||
// try to add small files first
|
// try to add small files first
|
||||||
return a.size - b.size;
|
return a.size - b.size;
|
||||||
}).forEach(function(file) {
|
}).forEach(function(file) {
|
||||||
|
|
Loading…
Reference in a new issue