mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-10-05 01:44:18 +00:00
Spinner: added an init callback which exposes the addItem method for dynamic population of spinner via an external objects.
This commit is contained in:
parent
48cce41f39
commit
accc76bc64
@ -10,12 +10,34 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
var itemList = [
|
||||
{url: "http://ejohn.org", title: "John Resig"},
|
||||
{url: "http://bassistance.de/", title: "Jörn Zaefferer"},
|
||||
{url: "http://snook.ca/jonathan/", title: "Jonathan Snook"},
|
||||
{url: "http://rdworth.org/", title: "Richard Worth"},
|
||||
{url: "http://www.paulbakaus.com/", title: "Paul Bakaus"},
|
||||
{url: "http://www.yehudakatz.com/", title: "Yehuda Katz"},
|
||||
{url: "http://www.azarask.in/", title: "Aza Raskin"},
|
||||
{url: "http://www.karlswedberg.com/", title: "Karl Swedberg"},
|
||||
{url: "http://scottjehl.com/", title: "Scott Jehl"},
|
||||
{url: "http://jdsharp.us/", title: "Jonathan Sharp"},
|
||||
{url: "http://www.kevinhoyt.org/", title: "Kevin Hoyt"},
|
||||
{url: "http://www.codylindley.com/", title: "Cody Lindley"},
|
||||
{url: "http://malsup.com/jquery/", title: "Mike Alsup"}
|
||||
];
|
||||
|
||||
var opts = {
|
||||
's1': {},
|
||||
's2': {stepping: 0.25},
|
||||
's3': {currency: '$'},
|
||||
's4': {}
|
||||
's4': {},
|
||||
's5': {
|
||||
init: function(ui) {
|
||||
for (var i=0; i<itemList.length; i++) {
|
||||
ui.add(itemList[i].title +' <a href="'+ itemList[i].url +'" target="_blank">»</a>');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (var n in opts)
|
||||
@ -181,5 +203,18 @@ label {
|
||||
|
||||
<hr />
|
||||
|
||||
<p><label for="s5">Presenters: </label>
|
||||
<div id="s5"></div>
|
||||
|
||||
<p>
|
||||
<button id="s5-disable">disable</button>
|
||||
<button id="s5-enable">enable</button>
|
||||
<button id="s5-destroy">destroy</button>
|
||||
<button id="s5-create">create</button>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -17,6 +17,11 @@ $.widget('ui.spinner', {
|
||||
// terminate initialization if spinner already applied to current element
|
||||
if($.data(this.element[0], 'spinner')) return;
|
||||
|
||||
// check for onInit callback
|
||||
if (this.options.init) {
|
||||
this.options.init(this.ui(null));
|
||||
}
|
||||
|
||||
// check for decimals in steppinng and set _decimals as internal (needs cleaning up)
|
||||
this._decimals = 0;
|
||||
if (this.options.stepping.toString().indexOf('.') != -1) {
|
||||
@ -113,6 +118,7 @@ $.widget('ui.spinner', {
|
||||
})
|
||||
.end();
|
||||
|
||||
|
||||
// DataList: Set contraints for object length and step size.
|
||||
// Manipulate height of spinner.
|
||||
this._items = this.element.children().length;
|
||||
@ -151,6 +157,7 @@ $.widget('ui.spinner', {
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
_constrain: function() {
|
||||
if(this.options.min != undefined && this._getValue() < this.options.min) this._setValue(this.options.min);
|
||||
if(this.options.max != undefined && this._getValue() > this.options.max) this._setValue(this.options.max);
|
||||
@ -229,6 +236,15 @@ $.widget('ui.spinner', {
|
||||
});
|
||||
}
|
||||
},
|
||||
_addItem: function(html) {
|
||||
if (!this.element.is('input')) {
|
||||
var wrapper = 'div';
|
||||
if (this.element.is('ol') || this.element.is('ul')) {
|
||||
wrapper = 'li';
|
||||
}
|
||||
this.element.append('<'+ wrapper +' class="ui-spinner-dyn">'+ html + '</'+ wrapper +'>');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
plugins: {},
|
||||
@ -236,7 +252,8 @@ $.widget('ui.spinner', {
|
||||
return {
|
||||
options: this.options,
|
||||
element: this.element,
|
||||
value: this._getValue()
|
||||
value: this._getValue(),
|
||||
add: this._addItem
|
||||
};
|
||||
},
|
||||
_propagate: function(n,e) {
|
||||
@ -259,6 +276,7 @@ $.widget('ui.spinner', {
|
||||
.end()
|
||||
.children()
|
||||
.removeClass('ui-spinner-listitem')
|
||||
.remove('.ui-spinner-dyn')
|
||||
.end()
|
||||
.parent()
|
||||
.removeClass('ui-spinner ui-spinner-disabled')
|
||||
|
Loading…
Reference in New Issue
Block a user