// vim: et:ts=4:sw=4:sts=4:ft=js /*@ Ox.IconList IconList Object () -> IconList Object (options) -> IconList Object (options, self) -> IconList Object options Options object centerSelection scroll list so selection is always centered draggable can be dragged id element id item called with data, sort, size, extends data with information needed for constructor itemConstructor contructor used to create item items items array or callback function keys available item keys max maximum selected selected items min minimum of selcted items orientation list orientation selected array of selected items size list size sort sort keys self shared private variable @*/ Ox.IconList = function(options, self) { self = self || {}; var that = Ox.Element({}, self) .defaults({ centerSelection: false, draggable: true, id: '', item: null, itemConstructor: Ox.IconItem, items: null, keys: [], max: -1, min: 0, orientation: 'both', selected: [], size: 128, sort: [], }) .options(options || {}); $.extend(self, { itemHeight: self.options.size * 1.5, itemWidth: self.options.size }); that.$element = Ox.List({ centered: self.options.centered, construct: constructItem, draggable: self.options.draggable, id: self.options.id, itemHeight: self.itemHeight, items: self.options.items, itemWidth: self.itemWidth, keys: self.options.keys, max: self.options.max, min: self.options.min, orientation: self.options.orientation, selected: self.options.selected, size: self.options.size, sort: self.options.sort, type: 'icon', unique: self.options.unique }, $.extend({}, self)) // pass event handler .addClass('OxIconList Ox' + Ox.toTitleCase(self.options.orientation)) .click(click) .dblclick(dblclick) .scroll(scroll); updateKeys(); function click() { } function constructItem(data) { var data = !$.isEmptyObject(data) ? self.options.item(data, self.options.sort, self.options.size) : {height: 8, width: 5}, ratio = data.width / data.height; return self.options.itemConstructor($.extend(data, { height: Math.round(self.options.size / (ratio <= 1 ? 1 : ratio)), size: self.options.size, width: Math.round(self.options.size * (ratio >= 1 ? 1 : ratio)) })); } function dblclick() { } function scroll() { } function updateKeys() { self.options.keys = Ox.unique($.merge(self.options.keys, [self.options.sort[0].key])); that.$element.options({ keys: self.options.keys }); } /*@ setOption set key/value (key, value) -> set eky in options to value @*/ self.setOption = function(key, value) { if (key == 'items') { that.$element.options(key, value); } else if (key == 'paste') { that.$element.options(key, value); } else if (key == 'selected') { that.$element.options(key, value); } }; /*@ closePreview close preview () -> close @*/ that.closePreview = function() { that.$element.closePreview(); }; /*@ paste paste to list (data) -> paste data, returns IconList @*/ that.paste = function(data) { that.$element.paste(data); return that; }; /*@ reloadList reload list () -> reload iconlist @*/ that.reloadList = function() { that.$element.reloadList(); return that; }; /*@ scrollToSelection set key/value () -> scroll list ot selection @*/ that.scrollToSelection = function() { that.$element.scrollToSelection(); }; /*@ size set key/value () -> get size of list @*/ that.size = function() { that.$element.size(); }; /*@ sortList sort list (key, operator) -> sort list by key with operator operator can be + / - @*/ that.sortList = function(key, operator) { self.options.sort = [{ key: key, operator: operator }]; updateKeys(); that.$element.sortList(key, operator); }; /*@ value get/set value of item in list (id) -> get all data for item (id, key) -> get value of key of item with id (id, key, value) -> set value, returns IconList @*/ that.value = function(id, key, value) { // fixme: make this accept id, {k: v, ...} if (arguments.length == 1) { return that.$element.value(id); } else if (arguments.length == 2) { return that.$element.value(id, key); } else { that.$element.value(id, key, value); return that; } }; return that; };