From dcb341e7f8a5ddc3dc94b00f9d9fc7e3867958b3 Mon Sep 17 00:00:00 2001 From: Ca-Phun Ung Date: Sat, 20 Sep 2008 19:04:01 +0000 Subject: [PATCH] Spinner: new options: format, items & decimals (r728). items: accepts a array of objects which will be converted to a list of items by the spinner. format: printf style formatting of each item - accepts named arguments. --- tests/visual/spinner.html | 12 ++++++++++-- ui/ui.spinner.js | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/tests/visual/spinner.html b/tests/visual/spinner.html index de05b6d25..f5b441e26 100644 --- a/tests/visual/spinner.html +++ b/tests/visual/spinner.html @@ -32,11 +32,19 @@ $(function(){ 's3': {currency: '$'}, 's4': {}, 's5': { + // + // Two methods of adding external items to the spinner + // + // method 1: on initalisation call the add method directly and format html manually init: function(ui) { for (var i=0; i»'); + ui.add(''+ itemList[i].title +''); } - } + }, + + // method 2: use the format and items options in combination + format: '%(title) »', + items: itemList } }; diff --git a/ui/ui.spinner.js b/ui/ui.spinner.js index 98d10811d..572611b5d 100644 --- a/ui/ui.spinner.js +++ b/ui/ui.spinner.js @@ -22,6 +22,14 @@ $.widget('ui.spinner', { this.options.init(this.ui(null)); } + // perform data bind on generic objects + if (typeof this.options.items[0] == 'object' && !this.element.is('input')) { + var data = this.options.items; + for (var i=0; i'+ html + ''); } }, @@ -307,7 +336,9 @@ $.extend($.ui.spinner, { stepping: 1, start: 0, incremental: true, - currency: false + currency: false, + format: '%', + items: [] }, format: { number: function(num, dec) { @@ -329,4 +360,5 @@ $.extend($.ui.spinner, { } }); + })(jQuery);