url controller updates, list bugfixes
This commit is contained in:
parent
ef9040ba24
commit
3965eed153
12 changed files with 98 additions and 48 deletions
|
@ -348,8 +348,10 @@ Ox.Element = function(options, self) {
|
||||||
'draganddropstart', 'draganddrop', 'draganddropenter', 'draganddropleave', 'draganddropend',
|
'draganddropstart', 'draganddrop', 'draganddropenter', 'draganddropleave', 'draganddropend',
|
||||||
'playing', 'position', 'progress'
|
'playing', 'position', 'progress'
|
||||||
].indexOf(event) == -1) {
|
].indexOf(event) == -1) {
|
||||||
|
if (!/^pandora_/.test(event)) {
|
||||||
Ox.print(that.id, self.options.id, 'trigger', event, data);
|
Ox.print(that.id, self.options.id, 'trigger', event, data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// it is necessary to check if self.$eventHandler exists,
|
// it is necessary to check if self.$eventHandler exists,
|
||||||
// since, for example, when removing the element on click,
|
// since, for example, when removing the element on click,
|
||||||
// singleclick will fire after the removal of the event handler
|
// singleclick will fire after the removal of the event handler
|
||||||
|
|
|
@ -19,7 +19,9 @@ Ox.Event = (function() {
|
||||||
@*/
|
@*/
|
||||||
that.bind = function() {
|
that.bind = function() {
|
||||||
Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
|
Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
|
||||||
|
var foo = event;
|
||||||
self.$eventHandler.bind('ox_' + event, function(event, data) {
|
self.$eventHandler.bind('ox_' + event, function(event, data) {
|
||||||
|
Ox.print('CALLBACK', foo, data.value);
|
||||||
callback(data.value);
|
callback(data.value);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -242,7 +242,7 @@ Ox.URL = function(options) {
|
||||||
].indexOf(state.view) > -1) {
|
].indexOf(state.view) > -1) {
|
||||||
parts.push(state.view);
|
parts.push(state.view);
|
||||||
}
|
}
|
||||||
if (state.span) {
|
if (state.span && state.span.length) {
|
||||||
parts.push(constructSpan(state.span, state));
|
parts.push(constructSpan(state.span, state));
|
||||||
}
|
}
|
||||||
if (state.sort && state.sort.length) {
|
if (state.sort && state.sort.length) {
|
||||||
|
@ -444,7 +444,7 @@ Ox.URL = function(options) {
|
||||||
parseBeyondItem();
|
parseBeyondItem();
|
||||||
} else {
|
} else {
|
||||||
// test for item id or name
|
// test for item id or name
|
||||||
self.options.getItem(parts[0], function(item) {
|
self.options.getItem(parts[0].replace(/%20/g, ' '), function(item) {
|
||||||
state.item = item;
|
state.item = item;
|
||||||
if (item) {
|
if (item) {
|
||||||
parts.shift();
|
parts.shift();
|
||||||
|
@ -585,10 +585,13 @@ Ox.URL = function(options) {
|
||||||
+ document.location.search
|
+ document.location.search
|
||||||
+ document.location.hash,
|
+ document.location.hash,
|
||||||
callback = arguments[arguments.length - 1];
|
callback = arguments[arguments.length - 1];
|
||||||
|
/*
|
||||||
parseURL(str, function(state) {
|
parseURL(str, function(state) {
|
||||||
that.replace(constructURL(state));
|
that.replace(constructURL(state));
|
||||||
callback(state);
|
callback(state);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
parseURL(str, callback);
|
||||||
return that;
|
return that;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,34 +605,61 @@ Ox.URL = function(options) {
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
push <f> Pushes a new URL
|
push <f> Pushes a new URL
|
||||||
(url, callback) -> <o> URL controller
|
(state, title, url, callback) -> <o> URL controller
|
||||||
(state) -> <o> URL controller
|
state <o> State for the new URL
|
||||||
url <s> New URL
|
title <s> Title for the new URL
|
||||||
|
url <s|o> New URL, or state object to construct it from
|
||||||
|
This state object can be different from the first one
|
||||||
|
(for example: save full state, create URL from reduced state)
|
||||||
callback <f> callback function
|
callback <f> callback function
|
||||||
state <o> New state
|
state <o> New state
|
||||||
state <o> State to construct the new URL from
|
|
||||||
@*/
|
@*/
|
||||||
that.push = function(url, callback) {
|
that.push = function(state, title, url, callback) {
|
||||||
url = callback ? url : constructURL(url);
|
if (Ox.isString(url)) {
|
||||||
saveURL();
|
if (state) {
|
||||||
Ox.print('PUSH', url);
|
pushState(state, title, url);
|
||||||
history.pushState({}, '', url);
|
} else {
|
||||||
callback && parseURL(url, callback);
|
parseURL(url, function(state) {
|
||||||
return that;
|
pushState(state, title, url);
|
||||||
};
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
url = constructURL(url);
|
||||||
|
pushState(state, title, url);
|
||||||
|
}
|
||||||
|
function pushState(state, title, url) {
|
||||||
|
history.pushState(state, title, url);
|
||||||
|
callback && callback(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
that.replace = function(url) {
|
/*@
|
||||||
saveURL();
|
replace <f> Replaces the URL with a new URL
|
||||||
history.replaceState({}, '', url);
|
(state, title, url, callback) -> <o> URL controller
|
||||||
return that;
|
state <o> State for the new URL
|
||||||
};
|
title <s> Title for the new URL
|
||||||
|
url <s|o> New URL, or state object to construct it from
|
||||||
that.update = function(state) {
|
callback <f> callback function
|
||||||
// pushes a new URL, constructed from state
|
state <o> New state
|
||||||
// state can have type, item, view, span, sort, find
|
@*/
|
||||||
that.push(constructURL(state));
|
that.replace = function(state, title, url, callback) {
|
||||||
return that;
|
if (Ox.isString(url)) {
|
||||||
};
|
if (state) {
|
||||||
|
replaceState(state, title, url);
|
||||||
|
} else {
|
||||||
|
parseURL(url, function(state) {
|
||||||
|
replaceState(state, title, url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
url = constructURL(url);
|
||||||
|
replaceState(state, title, url);
|
||||||
|
}
|
||||||
|
function replaceState(state, title, url) {
|
||||||
|
history.replaceState(state, title, url);
|
||||||
|
callback && callback(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
|
|
||||||
|
|
|
@ -195,7 +195,7 @@ Ox.Select = function(options, self) {
|
||||||
id <s> item id
|
id <s> item id
|
||||||
@*/
|
@*/
|
||||||
that.selectItem = function(id) {
|
that.selectItem = function(id) {
|
||||||
//Ox.print('selectItem', id, Ox.getObjectById(self.options.items, id).title)
|
Ox.print('selectItem', id, self.options.items, self.options.items.length, Ox.getObjectById(self.options.items, id))
|
||||||
self.options.type == 'text' && self.$title.html(
|
self.options.type == 'text' && self.$title.html(
|
||||||
Ox.getObjectById(self.options.items, id).title
|
Ox.getObjectById(self.options.items, id).title
|
||||||
);
|
);
|
||||||
|
|
|
@ -134,6 +134,7 @@ Ox.IconItem = function(options, self) {
|
||||||
);
|
);
|
||||||
|
|
||||||
function formatText(text, maxLines, maxLength) {
|
function formatText(text, maxLines, maxLength) {
|
||||||
|
text = Ox.isArray(text) ? text.join(', ') : text;
|
||||||
var lines = Ox.wordwrap(text, maxLength, '<br/>', true, false).split('<br/>');
|
var lines = Ox.wordwrap(text, maxLength, '<br/>', true, false).split('<br/>');
|
||||||
return Ox.map(lines, function(line, i) {
|
return Ox.map(lines, function(line, i) {
|
||||||
if (i < maxLines - 1) {
|
if (i < maxLines - 1) {
|
||||||
|
|
|
@ -113,9 +113,8 @@ Ox.IconList = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateKeys() {
|
function updateKeys() {
|
||||||
self.options.keys = Ox.unique(Ox.merge(self.options.keys, [self.options.sort[0].key]));
|
|
||||||
that.$element.options({
|
that.$element.options({
|
||||||
keys: self.options.keys
|
keys: Ox.unique(Ox.merge(self.options.sort[0].key, self.options.keys))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +128,9 @@ Ox.IconList = function(options, self) {
|
||||||
} else if (key == 'selected') {
|
} else if (key == 'selected') {
|
||||||
that.$element.options(key, value);
|
that.$element.options(key, value);
|
||||||
} else if (key == 'sort') {
|
} else if (key == 'sort') {
|
||||||
|
updateKeys();
|
||||||
that.$element.options(key, value);
|
that.$element.options(key, value);
|
||||||
|
//that.$element.sortList(key, operator);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -177,6 +178,7 @@ Ox.IconList = function(options, self) {
|
||||||
that.$element.size();
|
that.$element.size();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// fixme: deprecate, use options()
|
||||||
/*@
|
/*@
|
||||||
sortList <f> sort list
|
sortList <f> sort list
|
||||||
(key, operator) -> <o> the list
|
(key, operator) -> <o> the list
|
||||||
|
|
|
@ -37,7 +37,7 @@ Ox.List <f:Ox.Element> List Element
|
||||||
draganddropstart <i> Fires when drag starts
|
draganddropstart <i> Fires when drag starts
|
||||||
copy <!> copy
|
copy <!> copy
|
||||||
paste <!> paste
|
paste <!> paste
|
||||||
movie <!> move item
|
move <!> move item
|
||||||
load <!> list loaded
|
load <!> list loaded
|
||||||
openpreview <!> preview of selected item opened
|
openpreview <!> preview of selected item opened
|
||||||
closepreview <!> preview closed
|
closepreview <!> preview closed
|
||||||
|
@ -291,7 +291,7 @@ Ox.List = function(options, self) {
|
||||||
Ox.Request.cancel(v);
|
Ox.Request.cancel(v);
|
||||||
});
|
});
|
||||||
Ox.extend(self, {
|
Ox.extend(self, {
|
||||||
//$items: [],
|
$items: [],
|
||||||
$pages: [],
|
$pages: [],
|
||||||
page: 0,
|
page: 0,
|
||||||
requests: []
|
requests: []
|
||||||
|
@ -677,6 +677,7 @@ Ox.List = function(options, self) {
|
||||||
|
|
||||||
function loadItems() {
|
function loadItems() {
|
||||||
that.$content.empty();
|
that.$content.empty();
|
||||||
|
self.$items = [];
|
||||||
self.options.items.forEach(function(item, pos) {
|
self.options.items.forEach(function(item, pos) {
|
||||||
// fixme: duplicated
|
// fixme: duplicated
|
||||||
self.$items[pos] = Ox.ListItem({
|
self.$items[pos] = Ox.ListItem({
|
||||||
|
@ -1649,17 +1650,20 @@ Ox.List = function(options, self) {
|
||||||
value <s> value, can be whatever that property is
|
value <s> value, can be whatever that property is
|
||||||
@*/
|
@*/
|
||||||
that.value = function(id, key, value) {
|
that.value = function(id, key, value) {
|
||||||
//Ox.print('that.value', id, getPositionById(id))
|
|
||||||
var pos = getPositionById(id),
|
var pos = getPositionById(id),
|
||||||
$item = self.$items[pos],
|
$item = self.$items[pos],
|
||||||
data = $item.options('data'),
|
data = $item.options('data');
|
||||||
oldValue;
|
|
||||||
if (arguments.length == 1) {
|
if (arguments.length == 1) {
|
||||||
return data;
|
return data;
|
||||||
} else if (arguments.length == 2) {
|
} else if (arguments.length == 2) {
|
||||||
return data[key];
|
return data[key];
|
||||||
} else {
|
} else {
|
||||||
oldValue = data[key];
|
if (key == self.options.unique) {
|
||||||
|
// unique id has changed
|
||||||
|
self.options.selected = self.options.selected.map(function(id_) {
|
||||||
|
return id_ == data[key] ? value : id_
|
||||||
|
});
|
||||||
|
}
|
||||||
data[key] = value;
|
data[key] = value;
|
||||||
$item.options({data: data});
|
$item.options({data: data});
|
||||||
return that;
|
return that;
|
||||||
|
|
|
@ -196,7 +196,7 @@ Ox.TextList = function(options, self) {
|
||||||
sortable: self.options.sortable,
|
sortable: self.options.sortable,
|
||||||
type: 'text',
|
type: 'text',
|
||||||
unique: self.unique
|
unique: self.unique
|
||||||
}, Ox.extend({}, self)) // pass event handler
|
}, Ox.clone(self)) // pass event handler
|
||||||
.addClass('OxBody')
|
.addClass('OxBody')
|
||||||
.css({
|
.css({
|
||||||
top: (self.options.columnsVisible ? 16 : 0) + 'px',
|
top: (self.options.columnsVisible ? 16 : 0) + 'px',
|
||||||
|
@ -222,7 +222,6 @@ Ox.TextList = function(options, self) {
|
||||||
//that.triggerEvent('init', data);
|
//that.triggerEvent('init', data);
|
||||||
},
|
},
|
||||||
select: function() {
|
select: function() {
|
||||||
Ox.print('SELECT????')
|
|
||||||
self.options.selected = that.$body.options('selected');
|
self.options.selected = that.$body.options('selected');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -929,18 +928,19 @@ Ox.TextList = function(options, self) {
|
||||||
return that.$body.value(id, key);
|
return that.$body.value(id, key);
|
||||||
} else {
|
} else {
|
||||||
that.$body.value(id, key, value);
|
that.$body.value(id, key, value);
|
||||||
//Ox.print('? ? ?', column, column.format)
|
if (key == self.unique) {
|
||||||
|
// unique id has changed
|
||||||
|
self.options.selected = self.options.selected.map(function(id_) {
|
||||||
|
return id_ == id ? value : id_
|
||||||
|
});
|
||||||
|
id = value;
|
||||||
|
}
|
||||||
$cell = getCell(id, key);
|
$cell = getCell(id, key);
|
||||||
$cell && $cell.html(formatValue(key, value));
|
$cell && $cell.html(formatValue(key, value));
|
||||||
if (key == self.options.sort[0].key) {
|
if (key == self.options.sort[0].key) {
|
||||||
|
// sort key has changed
|
||||||
that.$body.sort();
|
that.$body.sort();
|
||||||
}
|
}
|
||||||
/* fixme: something like this is needed:
|
|
||||||
if (column.unique) {
|
|
||||||
that.$body.setId($item.data('id'), value);
|
|
||||||
$item.data({id: value});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return that;
|
return that;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,6 +196,8 @@ Ox.SplitPanel = function(options, self) {
|
||||||
that.$elements[pos] = element
|
that.$elements[pos] = element
|
||||||
.css(self.edges[2], (parseInt(element.css(self.edges[2])) || 0) + 'px')
|
.css(self.edges[2], (parseInt(element.css(self.edges[2])) || 0) + 'px')
|
||||||
.css(self.edges[3], (parseInt(element.css(self.edges[3])) || 0) + 'px');
|
.css(self.edges[3], (parseInt(element.css(self.edges[3])) || 0) + 'px');
|
||||||
|
// fixme: it would be better to call removeElement here,
|
||||||
|
// or have a custom replaceElement function that removes event handlers
|
||||||
self.options.elements[pos].element.replaceWith(element.$element.$element || element.$element);
|
self.options.elements[pos].element.replaceWith(element.$element.$element || element.$element);
|
||||||
self.options.elements[pos].element = element;
|
self.options.elements[pos].element = element;
|
||||||
setSizes();
|
setSizes();
|
||||||
|
|
|
@ -65,6 +65,7 @@ Ox.VideoPreview = function(options, self) {
|
||||||
|
|
||||||
function getFrameCSS() {
|
function getFrameCSS() {
|
||||||
var css = {};
|
var css = {};
|
||||||
|
// fixme: these are still wrong
|
||||||
if (!self.options.scaleToFill) {
|
if (!self.options.scaleToFill) {
|
||||||
css.width = self.options.width;
|
css.width = self.options.width;
|
||||||
css.height = Math.round(css.width / self.options.frameRatio);
|
css.height = Math.round(css.width / self.options.frameRatio);
|
||||||
|
|
|
@ -261,6 +261,7 @@ Ox.Dialog = function(options, self) {
|
||||||
function getButtonById(id) {
|
function getButtonById(id) {
|
||||||
var ret = null;
|
var ret = null;
|
||||||
Ox.forEach(self.options.buttons, function(button) {
|
Ox.forEach(self.options.buttons, function(button) {
|
||||||
|
Ox.print(button.options(), button.options('id'))
|
||||||
if (button.options && button.options('id') == id) {
|
if (button.options && button.options('id') == id) {
|
||||||
ret = button;
|
ret = button;
|
||||||
return false;
|
return false;
|
||||||
|
@ -271,6 +272,7 @@ Ox.Dialog = function(options, self) {
|
||||||
|
|
||||||
function keypress(key) {
|
function keypress(key) {
|
||||||
var id = self.options.keys[key];
|
var id = self.options.keys[key];
|
||||||
|
Ox.print(id, getButtonById(id));
|
||||||
id && getButtonById(id).$element.trigger('click');
|
id && getButtonById(id).$element.trigger('click');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
source/Ox.js
10
source/Ox.js
|
@ -431,6 +431,8 @@ Ox.clone <f> Returns a (shallow or deep) copy of an object or array
|
||||||
'val'
|
'val'
|
||||||
> (function() { a = {key: 'val'}; b = Ox.clone(a); a.key = null; return b.key; }())
|
> (function() { a = {key: 'val'}; b = Ox.clone(a); a.key = null; return b.key; }())
|
||||||
'val'
|
'val'
|
||||||
|
> Ox.clone(0)
|
||||||
|
0
|
||||||
@*/
|
@*/
|
||||||
|
|
||||||
Ox.clone = function(col, deep) {
|
Ox.clone = function(col, deep) {
|
||||||
|
@ -442,7 +444,9 @@ Ox.clone = function(col, deep) {
|
||||||
? Ox.clone(val, true) : val;
|
? Ox.clone(val, true) : val;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ret = Ox.isArray(col) ? col.slice() : Ox.extend({}, col);
|
ret = Ox.isArray(col) ? col.slice()
|
||||||
|
: Ox.isObject(col) ? Ox.extend({}, col)
|
||||||
|
: col;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
@ -670,10 +674,10 @@ Ox.getset = function(obj, args, callback, context) {
|
||||||
var obj_ = Ox.clone(obj), ret;
|
var obj_ = Ox.clone(obj), ret;
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
// getset([])
|
// getset([])
|
||||||
ret = obj;
|
ret = obj_;
|
||||||
} else if (args.length == 1 && !Ox.isObject(args[0])) {
|
} else if (args.length == 1 && !Ox.isObject(args[0])) {
|
||||||
// getset([key])
|
// getset([key])
|
||||||
ret = obj[args[0]];
|
ret = Ox.clone(obj[args[0]]);
|
||||||
} else {
|
} else {
|
||||||
// getset([key, val]) or getset([{key: val, ...}])
|
// getset([key, val]) or getset([{key: val, ...}])
|
||||||
args = Ox.makeObject(args);
|
args = Ox.makeObject(args);
|
||||||
|
|
Loading…
Reference in a new issue