update file selection example
This commit is contained in:
parent
2ec03287f2
commit
0d614ed7a1
1 changed files with 60 additions and 11 deletions
|
@ -11,7 +11,7 @@ Ox.load('UI', function() {
|
||||||
|
|
||||||
var $elements = [
|
var $elements = [
|
||||||
/*
|
/*
|
||||||
Ox.FileButton creates a simple button. It has the following options:
|
Ox.FileButton has the following options:
|
||||||
<pre>
|
<pre>
|
||||||
disabled
|
disabled
|
||||||
If true, the button is disabled
|
If true, the button is disabled
|
||||||
|
@ -40,9 +40,11 @@ Ox.load('UI', function() {
|
||||||
<pre>
|
<pre>
|
||||||
$fileButton.bindEvent({
|
$fileButton.bindEvent({
|
||||||
click: function(data) {
|
click: function(data) {
|
||||||
Ox.print(data.files);
|
data.files.forEach(function(file) {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
</pre>
|
</pre>
|
||||||
We create two image buttons and two text buttons: one of each to
|
We create two image buttons and two text buttons: one of each to
|
||||||
select a single file, one for multiple files.
|
select a single file, one for multiple files.
|
||||||
|
@ -66,10 +68,23 @@ Ox.load('UI', function() {
|
||||||
width: 128
|
width: 128
|
||||||
}),
|
}),
|
||||||
/*
|
/*
|
||||||
...
|
Ox.FileInput is a form element, so it has a value and fires a
|
||||||
|
`change` event. Its options are similar to Ox.FileButton, without
|
||||||
|
`image`, `title` and `type`, and we can bind to its `change` event
|
||||||
|
like this:
|
||||||
|
<pre>
|
||||||
|
$fileInput.bindEvent({
|
||||||
|
change: function(data) {
|
||||||
|
data.value.forEach(function(file) {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</pre>
|
||||||
|
Again, we create one input to select a single file and one for
|
||||||
|
multiple files.
|
||||||
*/
|
*/
|
||||||
Ox.FileInput({
|
Ox.FileInput({
|
||||||
disabled: true,
|
|
||||||
maxFiles: 1,
|
maxFiles: 1,
|
||||||
maxSize: 1000000,
|
maxSize: 1000000,
|
||||||
width: 256
|
width: 256
|
||||||
|
@ -80,9 +95,26 @@ Ox.load('UI', function() {
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
/*
|
/*
|
||||||
A basic menu item looks like `{id: 'id', title: 'Title'}`. By adding a
|
File selection also works from a menu. A basic menu item looks like
|
||||||
`file` property (which takes the same `maxFiles`, `maxSize` and `width`
|
`{id: 'id', title: 'Title'}`, and its `click` event fires on click.
|
||||||
options as Ox.FileButton), ...
|
By adding a `file` property (which takes the same `maxFiles`, `maxSize`
|
||||||
|
and `width` options as Ox.FileButton), we enable file selection, and
|
||||||
|
the `click` event now fires once one or more files are selected. We can
|
||||||
|
bind to it like this:
|
||||||
|
<pre>
|
||||||
|
$mainMenu.bindEvent({
|
||||||
|
click: function(data) {
|
||||||
|
if (data.id == 'foo') {
|
||||||
|
data.files.forEach(function(file) {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</pre>
|
||||||
|
Note that keyboard navigation works as well. Just like any other menu
|
||||||
|
item, it can be activated by pressing `enter`, which opens the file
|
||||||
|
selection dialog.
|
||||||
*/
|
*/
|
||||||
$menu = Ox.MainMenu({
|
$menu = Ox.MainMenu({
|
||||||
menus: [
|
menus: [
|
||||||
|
@ -96,18 +128,30 @@ Ox.load('UI', function() {
|
||||||
]}
|
]}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
/*
|
||||||
|
On click, we display the event data and open a dialog.
|
||||||
|
*/
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
click: function(data) {
|
click: function(data) {
|
||||||
showEvent(data);
|
showEvent(data);
|
||||||
openDialog(data);
|
openDialog(data);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
/*
|
||||||
|
This is a container for our buttons and inputs.
|
||||||
|
*/
|
||||||
$main = Ox.Element(),
|
$main = Ox.Element(),
|
||||||
|
/*
|
||||||
|
This is the list that will display the event data.
|
||||||
|
*/
|
||||||
$list = Ox.TreeList({
|
$list = Ox.TreeList({
|
||||||
data: {},
|
data: {},
|
||||||
expanded: true,
|
expanded: true,
|
||||||
width: 256
|
width: 256
|
||||||
}),
|
}),
|
||||||
|
/*
|
||||||
|
They both share a panel.
|
||||||
|
*/
|
||||||
$innerPanel = Ox.SplitPanel({
|
$innerPanel = Ox.SplitPanel({
|
||||||
elements: [
|
elements: [
|
||||||
{element: $main},
|
{element: $main},
|
||||||
|
@ -115,6 +159,9 @@ Ox.load('UI', function() {
|
||||||
],
|
],
|
||||||
orientation: 'horizontal'
|
orientation: 'horizontal'
|
||||||
}),
|
}),
|
||||||
|
/*
|
||||||
|
Menu and inner panel go into the outer panel.
|
||||||
|
*/
|
||||||
$outerPanel = Ox.SplitPanel({
|
$outerPanel = Ox.SplitPanel({
|
||||||
elements: [
|
elements: [
|
||||||
{element: $menu, size: 20},
|
{element: $menu, size: 20},
|
||||||
|
@ -124,6 +171,11 @@ Ox.load('UI', function() {
|
||||||
})
|
})
|
||||||
.appendTo(Ox.$body);
|
.appendTo(Ox.$body);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Here, we append the buttons and inputs to the container. For each element,
|
||||||
|
we add an event handler (`click` event for buttons, `change` event for
|
||||||
|
inputs) to display the event data.
|
||||||
|
*/
|
||||||
$elements.forEach(function($element, i) {
|
$elements.forEach(function($element, i) {
|
||||||
$element
|
$element
|
||||||
.css({top: 16 + 32 * i + 'px'})
|
.css({top: 16 + 32 * i + 'px'})
|
||||||
|
@ -133,9 +185,6 @@ Ox.load('UI', function() {
|
||||||
.appendTo($main);
|
.appendTo($main);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.$elements = $elements;
|
|
||||||
window.$menu = $menu;
|
|
||||||
|
|
||||||
function openDialog(data) {
|
function openDialog(data) {
|
||||||
var $button = Ox.Button({
|
var $button = Ox.Button({
|
||||||
id: 'close',
|
id: 'close',
|
||||||
|
|
Loading…
Reference in a new issue