nanoislands
Advanced tools
Comparing version 0.3.15 to 0.3.16
@@ -12,3 +12,3 @@ ## Yate | ||
* `'size'` {string} `'s' / 'm' / 'l'` | ||
* `'theme'` {string} `'normal' / 'action' (yellow) / 'dark' / 'pseudo' / 'promo' (big yellow)` | ||
* `'theme'` {string} `'normal' / 'action' (yellow) / 'dark' / 'pseudo' / 'pseudo_inverted' / 'promo' (big yellow)` | ||
* `'id'` {string} ... | ||
@@ -15,0 +15,0 @@ * `'name'` {string} ... |
@@ -17,617 +17,634 @@ /* | ||
nb.define('select', { | ||
events: { | ||
'mousedown': '_onclick' | ||
//'open' { event, ui} | ||
//'close' { event, ui} | ||
}, | ||
events: { | ||
'mousedown': '_onclick' | ||
//'open' { event, ui} | ||
//'close' { event, ui} | ||
}, | ||
/** | ||
* Init select | ||
* @fires 'nb-inited' | ||
* @constructor | ||
*/ | ||
oninit: function() { | ||
this.isOpen = false; | ||
this.$control = this.$node.find('select'); | ||
this.$dropdown = this.$node.children('.nb-select__dropdown').appendTo('body'); | ||
this.data = this.nbdata(); | ||
/** | ||
* Init select | ||
* @fires 'nb-inited' | ||
* @constructor | ||
*/ | ||
oninit: function() { | ||
this.isOpen = false; | ||
this.$control = this.$node.find('select'); | ||
this.$dropdown = this.$node.children('.nb-select__dropdown').appendTo('body'); | ||
this.data = this.nbdata(); | ||
this._updateFromSelect(); | ||
this._updateFromSelect(); | ||
// degradation to native control in IE < 9 | ||
if (nb.IE_LT9) { | ||
var that = this; | ||
this.$control.on('change', function(e) { | ||
that.setState({ | ||
value: e.target.value | ||
// degradation to native control in IE < 9 | ||
if (nb.IE_LT9) { | ||
var that = this; | ||
this.$control.on('change', function(e) { | ||
that.setState({ | ||
value: e.target.value | ||
}); | ||
}); | ||
}); | ||
} else { | ||
// preparing control depending on configuration and content | ||
this.controlPrepare(); | ||
} | ||
} else { | ||
// preparing control depending on configuration and content | ||
this.controlPrepare(); | ||
} | ||
this.trigger('nb-inited', this); | ||
}, | ||
this.trigger('nb-inited', this); | ||
}, | ||
/** | ||
* preparing control depending on configuration and content | ||
*/ | ||
controlPrepare: function() { | ||
var that = this; | ||
// preparing position parameters for popup from direction data | ||
var position = {}; | ||
position.collision = 'flip'; | ||
/** | ||
* preparing control depending on configuration and content | ||
*/ | ||
controlPrepare: function() { | ||
var that = this; | ||
// preparing position parameters for popup from direction data | ||
var position = {}; | ||
position.collision = 'flip'; | ||
if (that.data.within) { | ||
position.within = that.data.within; | ||
} | ||
if (that.data.within) { | ||
position.within = that.data.within; | ||
} | ||
if (that.data.direction == 'top') { | ||
position.my = "left bottom"; | ||
position.at = "left top"; | ||
if (that.data.direction == 'top') { | ||
position.my = "left bottom"; | ||
position.at = "left top"; | ||
} else { | ||
position.my = "left top"; | ||
position.at = "left bottom"; | ||
} | ||
} else { | ||
position.my = "left top"; | ||
position.at = "left bottom"; | ||
} | ||
// select JUI control init | ||
this.$node.autocomplete({ | ||
delay: 0, | ||
minLength: 0, | ||
autoFocus: false, | ||
position: position, | ||
appendTo: that.$dropdown, | ||
source: function(request, response) { | ||
response(that.$control.children(['option', 'optgroup']).map(function() { | ||
var returnObj; | ||
var $this = $(this); | ||
that._returnOptItem = function(item) { | ||
var $item = $(item); | ||
var icon = $item.data('icon'); | ||
var result = {}; | ||
if ($item.attr('separator')) { | ||
result = { | ||
separator: true, | ||
option: item | ||
}; | ||
} else { | ||
result = { | ||
label: $item.text(), | ||
value: $item.val(), | ||
option: item | ||
}; | ||
if (icon) { | ||
result['icon'] = icon; | ||
} | ||
} | ||
return result; | ||
}; | ||
if (this.tagName == 'OPTGROUP') { | ||
returnObj = { | ||
type: 'group', | ||
label: $this.attr('label'), | ||
option: this, | ||
group: $this.children('option').map(function() { | ||
return { | ||
label: $(this).text(), | ||
value: $(this).val(), | ||
option: this | ||
}; | ||
}) | ||
}; | ||
} else { | ||
var icon = $this.data('icon'); | ||
returnObj = { | ||
label: $this.text(), | ||
value: $this.val(), | ||
option: this | ||
}; | ||
// select JUI control init | ||
that.$node.autocomplete({ | ||
delay: 0, | ||
minLength: 0, | ||
autoFocus: false, | ||
position: position, | ||
appendTo: that.$dropdown, | ||
source: function(request, response) { | ||
response(that.$control.children(['option', 'optgroup']).map(function() { | ||
var returnObj; | ||
var $this = $(this); | ||
if (icon) { | ||
returnObj['icon'] = icon; | ||
if (this.tagName == 'OPTGROUP') { | ||
returnObj = { | ||
type: 'group', | ||
label: $this.attr('label'), | ||
option: this, | ||
group: $this.children('option').map(function() { | ||
return that._returnOptItem(this); | ||
}) | ||
}; | ||
} else { | ||
returnObj = that._returnOptItem(this); | ||
} | ||
} | ||
return returnObj; | ||
})); | ||
}, | ||
select: function(event, ui) { | ||
return returnObj; | ||
})); | ||
}, | ||
select: function(event, ui) { | ||
if (ui.item.type != 'group') { | ||
ui.item.option.selected = true; | ||
if (ui.item.type != 'group') { | ||
ui.item.option.selected = true; | ||
that.$jUI._trigger('selected', event, { | ||
item: ui.item.option | ||
that.$jUI._trigger('selected', event, { | ||
item: ui.item.option | ||
}); | ||
} | ||
}, | ||
// delegate handler on 'outer' click on open | ||
open: function() { | ||
that.$jUI._on(that.$jUI.document, { | ||
// on 'outer' mousedown close control | ||
mousedown: function(e) { | ||
if (e.which == 1 && !$.contains(that.$jUI.element.get(0), e.target) && !$.contains(that.$dropdown[0], e.target)) { | ||
this.close(); | ||
} | ||
} | ||
}); | ||
that.trigger('nb-opened', that); | ||
}, | ||
close: function() { | ||
that.$jUI._off(that.$jUI.document, 'mousedown'); | ||
that.trigger('nb-closed', that); | ||
} | ||
}, | ||
// delegate handler on 'outer' click on open | ||
open: function() { | ||
that.$jUI._on(that.$jUI.document, { | ||
// on 'outer' mousedown close control | ||
mousedown: function(e) { | ||
if (e.which == 1 && !$.contains(that.$jUI.element.get(0), e.target) && !$.contains(that.$dropdown[0], e.target)) { | ||
this.close(); | ||
} | ||
} | ||
}); | ||
that.trigger('nb-opened', that); | ||
}, | ||
}).addClass('ui-widget ui-widget-content'); | ||
close: function() { | ||
that.$jUI._off(that.$jUI.document, 'mousedown'); | ||
that.trigger('nb-closed', that); | ||
} | ||
}).addClass('ui-widget ui-widget-content'); | ||
that.$jUI = that.$node.data('uiAutocomplete'); | ||
that.$jUI = that.$node.data('uiAutocomplete'); | ||
that.$node.on('autocompleteopen', function() { | ||
that.isOpen = true; | ||
}); | ||
that.$node.on('autocompleteopen', function() { | ||
that.isOpen = true; | ||
}); | ||
that.$node.on('autocompleteclose', function() { | ||
that.isOpen = false; | ||
}); | ||
that.$node.on('autocompleteclose', function() { | ||
that.isOpen = false; | ||
}); | ||
// redefine one menu item rendering method, fires every time, then popup opening | ||
that.$jUI._renderItem = function(ul, item) { | ||
var $itemNode = $('<li class="nb-select__item"></li>'); | ||
// redefine one menu item rendering method, fires every time, then popup opening | ||
that.$jUI._renderItem = function(ul, item) { | ||
var $itemNode = $('<li class="nb-select__item"></li>'); | ||
if (item.option.selected) { | ||
$itemNode.addClass('nb-select__item_selected_yes'); | ||
} | ||
if (item.option.selected) { | ||
$itemNode.addClass('nb-select__item_selected_yes'); | ||
} | ||
if (item.type == 'group') { | ||
if (item.type == 'group') { | ||
$itemNode.addClass('nb-select__item_type_group'); | ||
var $innerUL = $('<ul></ul>'); | ||
$itemNode.addClass('nb-select__item_type_group'); | ||
var $innerUL = $('<ul></ul>'); | ||
item.group.each(function(index, item) { | ||
that.$jUI._renderItem($innerUL, item); | ||
}); | ||
item.group.each(function(index, item) { | ||
that.$jUI._renderItem($innerUL, item); | ||
}); | ||
$itemNode.append($innerUL); | ||
} | ||
$itemNode.append($innerUL); | ||
} | ||
if (item.separator) { | ||
$itemNode.addClass('nb-select__item_seperator'); | ||
} else { | ||
$itemNode.data('ui-autocomplete-item', item); | ||
$itemNode.data('ui-autocomplete-item', item); | ||
var $itemNodeContent = $('<a class="nb-select__a"></a>'); | ||
var $itemText = $('<span class="nb-select__text"></span>').text(item.label).appendTo($itemNodeContent); | ||
var $itemNodeContent = $('<a class="nb-select__a"></a>'); | ||
var $itemText = $('<span class="nb-select__text"></span>').text(item.label).appendTo($itemNodeContent); | ||
if (item.icon) { | ||
$itemText.prepend('<img src="//yandex.st/lego/_/La6qi18Z8LwgnZdsAr1qy1GwCwo.gif" class="nb-icon nb-icon_' + item.icon + '">'); | ||
} | ||
$itemNode | ||
.append($itemNodeContent) | ||
.appendTo(ul); | ||
if (item.icon) { | ||
$itemText.prepend('<img src="//yandex.st/lego/_/La6qi18Z8LwgnZdsAr1qy1GwCwo.gif" class="nb-icon nb-icon_' + item.icon + '">'); | ||
} | ||
return $itemNode; | ||
}; | ||
$itemNode.append($itemNodeContent); | ||
} | ||
// redefine valueMethod, extend with button text changing and fallback select value changing | ||
// if value not provided, return current value of fallback select | ||
that.$jUI.valueMethod = function(value) { | ||
$itemNode.appendTo(ul); | ||
return $itemNode; | ||
}; | ||
if (typeof value === 'string') { | ||
var text = that.$control.find('option[value="' + value + '"]').text(); | ||
that.setState({ | ||
value: value, | ||
text: text | ||
}); | ||
} | ||
return that.$selected.val(); | ||
}; | ||
// redefine valueMethod, extend with button text changing and fallback select value changing | ||
// if value not provided, return current value of fallback select | ||
that.$jUI.valueMethod = function(value) { | ||
// safe original function | ||
that.$jUI.__resizeMenu = that.$jUI._resizeMenu; | ||
if (typeof value === 'string') { | ||
var text = that.$control.find('option[value="' + value + '"]').text(); | ||
that.setState({ | ||
value: value, | ||
text: text | ||
}); | ||
} | ||
return that.$selected.val(); | ||
}; | ||
that.$jUI._resizeMenu = function() { | ||
// set maxHeight before the menu is displayed | ||
if (that.data.maxheight) { | ||
that._setMaxHeight(that.data.maxheight); | ||
} | ||
// safe original function | ||
that.$jUI.__resizeMenu = that.$jUI._resizeMenu; | ||
this.__resizeMenu(); | ||
}; | ||
that.$jUI._resizeMenu = function() { | ||
// set maxHeight before the menu is displayed | ||
if (that.data.maxheight) { | ||
that._setMaxHeight(that.data.maxheight); | ||
} | ||
that.$jUI.menu.element.on('click', function(evt) { | ||
evt.stopPropagation(); | ||
}); | ||
}, | ||
this.__resizeMenu(); | ||
}; | ||
/** | ||
* Save value and text from <select> node. | ||
* @private | ||
*/ | ||
_updateFromSelect: function() { | ||
// get selected <option/> | ||
this.$selected = this.$control.children(':selected'); | ||
that.$jUI.menu.element.on('click', function(evt) { | ||
evt.stopPropagation(); | ||
}); | ||
}, | ||
this.value = this.$selected.val(); | ||
// - to prevent button from collapse if no text on <option/> | ||
this.text = this.$selected.text() || ' '; | ||
/** | ||
* Save value and text from <select> node. | ||
* @private | ||
*/ | ||
_updateFromSelect: function() { | ||
// get selected <option/> | ||
this.$selected = this.$control.children(':selected'); | ||
this._setText(this.text); | ||
}, | ||
this.value = this.$selected.val(); | ||
// - to prevent button from collapse if no text on <option/> | ||
this.text = this.$selected.text() || ' '; | ||
_onclick: function(evt) { | ||
if (this.$node && this.$node.data('uiAutocomplete')) { | ||
evt.preventDefault(); | ||
// close if already visible | ||
if (this.isOpen) { | ||
this.close(); | ||
} else if (this.isEnabled()) { | ||
this.open(); | ||
this.$node.focus(); | ||
this._setText(this.text); | ||
}, | ||
_onclick: function(evt) { | ||
if (this.$node && this.$node.data('uiAutocomplete')) { | ||
evt.preventDefault(); | ||
// close if already visible | ||
if (this.isOpen) { | ||
this.close(); | ||
} else if (this.isEnabled()) { | ||
this.open(); | ||
this.$node.focus(); | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
_setText: function(text) { | ||
this.$node.find('.nb-button__text').text(text); | ||
}, | ||
_setText: function(text) { | ||
this.$node.find('.nb-button__text').text(text); | ||
}, | ||
_setMaxHeight: function(maxheight) { | ||
var height; | ||
if (/^\d+$/.test(maxheight)) { | ||
var item = this.$jUI.menu.element.find('.nb-select__item').first(); | ||
height = parseInt(item.height()) * maxheight; | ||
} else { | ||
height = maxheight; | ||
} | ||
_setMaxHeight: function(maxheight) { | ||
var height; | ||
if (/^\d+$/.test(maxheight)) { | ||
var item = this.$jUI.menu.element.find('.nb-select__item').first(); | ||
height = parseInt(item.height()) * maxheight; | ||
} else { | ||
height = maxheight; | ||
} | ||
this.$jUI.menu.element.css({ | ||
'max-height': height, | ||
'overflow-y': 'auto', | ||
'overflow-x': 'hidden' | ||
}); | ||
}, | ||
this.$jUI.menu.element.css({ | ||
'max-height': height, | ||
'overflow-y': 'auto', | ||
'overflow-x': 'hidden' | ||
}); | ||
}, | ||
/** | ||
* Render dropdown of the select | ||
* @fires 'nb-rendered' | ||
* @returns {Object} nb.block | ||
*/ | ||
render: function() { | ||
if (!this.isEnabled()) { | ||
return this; | ||
} | ||
/** | ||
* Render dropdown of the select | ||
* @fires 'nb-rendered' | ||
* @returns {Object} nb.block | ||
*/ | ||
render: function() { | ||
if (!this.isEnabled()) { | ||
return this; | ||
} | ||
// pass empty string as value to search for, displaying all results | ||
this.$node.autocomplete('search', ''); | ||
// pass empty string as value to search for, displaying all results | ||
this.$node.autocomplete('search', ''); | ||
this.trigger('nb-rendered', this); | ||
return this; | ||
}, | ||
this.trigger('nb-rendered', this); | ||
return this; | ||
}, | ||
/** | ||
* Open dropdown of the select | ||
* @fires 'nb-opened' | ||
* @returns {Object} nb.block | ||
*/ | ||
open: function() { | ||
if (this.$node && this.$node.data('uiAutocomplete') && this.isEnabled()) { | ||
this.render(); | ||
} | ||
return this; | ||
}, | ||
/** | ||
* Open dropdown of the select | ||
* @fires 'nb-opened' | ||
* @returns {Object} nb.block | ||
*/ | ||
open: function() { | ||
if (this.$node && this.$node.data('uiAutocomplete') && this.isEnabled()) { | ||
this.render(); | ||
} | ||
return this; | ||
}, | ||
/** | ||
* Close dropdown of the select | ||
* @fires 'nb-closed' | ||
* @returns {Object} nb.block | ||
*/ | ||
close: function() { | ||
if (this.$node && this.$node.data('uiAutocomplete')) { | ||
this.$node.autocomplete('close'); | ||
this.trigger('nb-closed', this); | ||
} | ||
return this; | ||
}, | ||
/** | ||
* Close dropdown of the select | ||
* @fires 'nb-closed' | ||
* @returns {Object} nb.block | ||
*/ | ||
close: function() { | ||
if (this.$node && this.$node.data('uiAutocomplete')) { | ||
this.$node.autocomplete('close'); | ||
this.trigger('nb-closed', this); | ||
} | ||
return this; | ||
}, | ||
/** | ||
* Changes a value of control, text on the button and select value it the fallback | ||
* @param {Object} params — { | ||
/** | ||
* Changes a value of control, text on the button and select value it the fallback | ||
* @param {Object} params — { | ||
* text: '..' | ||
* value: '..' | ||
* } | ||
* @fires 'nb-changed' | ||
* @returns {Object} nb.block | ||
*/ | ||
setState: function(params) { | ||
params = params || {}; | ||
* @fires 'nb-changed' | ||
* @returns {Object} nb.block | ||
*/ | ||
setState: function(params) { | ||
params = params || {}; | ||
if (this.value !== params.value) { | ||
var selected; | ||
if (this.value !== params.value) { | ||
var selected; | ||
if (params.value) { | ||
selected = this.$control.find('option[value="' + params.value + '"]'); | ||
} else { | ||
selected = this.$control.find('option:contains(' + params.text + ')'); | ||
} | ||
if (params.value) { | ||
selected = this.$control.find('option[value="' + params.value + '"]'); | ||
} else { | ||
selected = this.$control.find('option:contains(' + params.text + ')'); | ||
} | ||
if (selected.length !== 0) { | ||
this.$selected.prop('selected', false); | ||
if (selected.length !== 0) { | ||
this.$selected.prop('selected', false); | ||
this.$selected = selected; | ||
this.$selected = selected; | ||
this.$selected.prop('selected', true); | ||
this.$selected.prop('selected', true); | ||
this.value = this.$selected.val(); | ||
this.value = this.$selected.val(); | ||
this.text = this.$selected.text(); | ||
this.text = this.$selected.text(); | ||
this._setText(this.text); | ||
this._setText(this.text); | ||
this.trigger('nb-changed', this); | ||
this.trigger('nb-changed', this); | ||
this.$control.val(params.value); | ||
this.$control.val(params.value); | ||
} | ||
} | ||
} | ||
return this; | ||
}, | ||
return this; | ||
}, | ||
/** | ||
* Returns state of the select | ||
* | ||
* @return {Object} - | ||
* { | ||
/** | ||
* Returns state of the select | ||
* | ||
* @return {Object} - | ||
* { | ||
* value: '..' | ||
* text: '..' | ||
* } | ||
*/ | ||
getState: function() { | ||
return { | ||
value: this.value, | ||
text: this.text | ||
}; | ||
}, | ||
*/ | ||
getState: function() { | ||
return { | ||
value: this.value, | ||
text: this.text | ||
}; | ||
}, | ||
/** | ||
* Get name of the select | ||
* @returns {String|Object} name | ||
*/ | ||
getName: function() { | ||
return this.$control.prop('name'); | ||
}, | ||
/** | ||
* Get name of the select | ||
* @returns {String|Object} name | ||
*/ | ||
getName: function() { | ||
return this.$control.prop('name'); | ||
}, | ||
/** | ||
* Changes a value of control, text on the button and select value it the fallback | ||
* @param {string} name | ||
* @fires 'nb-name-set' | ||
* @returns {Object} nb.block | ||
*/ | ||
setName: function(name) { | ||
this.$control.prop('name', name); | ||
this.trigger('nb-name-set', this); | ||
return this; | ||
}, | ||
/** | ||
* Changes a value of control, text on the button and select value it the fallback | ||
* @param {string} name | ||
* @fires 'nb-name-set' | ||
* @returns {Object} nb.block | ||
*/ | ||
setName: function(name) { | ||
this.$control.prop('name', name); | ||
this.trigger('nb-name-set', this); | ||
return this; | ||
}, | ||
/** | ||
* Disables the select | ||
* @fires 'nb-disabled' | ||
* @returns {Object} nb.block | ||
*/ | ||
disable: function() { | ||
if (this.isEnabled()) { | ||
this.$node.addClass('nb-is-disabled'); | ||
if (!nb.IE_LT9) { | ||
this.$node.autocomplete('disable'); | ||
/** | ||
* Disables the select | ||
* @fires 'nb-disabled' | ||
* @returns {Object} nb.block | ||
*/ | ||
disable: function() { | ||
if (this.isEnabled()) { | ||
this.$node.addClass('nb-is-disabled'); | ||
if (!nb.IE_LT9) { | ||
this.$node.autocomplete('disable'); | ||
} | ||
this.$control.attr('disabled', 'disabled'); | ||
this.trigger('nb-disabled', this); | ||
} | ||
this.$control.attr('disabled', 'disabled'); | ||
this.trigger('nb-disabled', this); | ||
} | ||
return this; | ||
}, | ||
return this; | ||
}, | ||
/** | ||
* Enables the select | ||
* @fires 'nb-enabled' | ||
* @returns {Object} nb.block | ||
*/ | ||
enable: function() { | ||
if (!this.isEnabled()) { | ||
this.$node.removeClass('nb-is-disabled'); | ||
if (!nb.IE_LT9) { | ||
this.$node.autocomplete('enable'); | ||
/** | ||
* Enables the select | ||
* @fires 'nb-enabled' | ||
* @returns {Object} nb.block | ||
*/ | ||
enable: function() { | ||
if (!this.isEnabled()) { | ||
this.$node.removeClass('nb-is-disabled'); | ||
if (!nb.IE_LT9) { | ||
this.$node.autocomplete('enable'); | ||
} | ||
this.$control.removeAttr('disabled'); | ||
this.trigger('nb-enabled', this); | ||
} | ||
this.$control.removeAttr('disabled'); | ||
this.trigger('nb-enabled', this); | ||
} | ||
return this; | ||
}, | ||
return this; | ||
}, | ||
/** | ||
* Return state of the select | ||
* @returns {Boolean} | ||
*/ | ||
isEnabled: function() { | ||
return !this.$node.hasClass('nb-is-disabled'); | ||
}, | ||
/** | ||
* Return state of the select | ||
* @returns {Boolean} | ||
*/ | ||
isEnabled: function() { | ||
return !this.$node.hasClass('nb-is-disabled'); | ||
}, | ||
/* | ||
* Set new items for select | ||
* @params {Array} source New source | ||
* @fires 'nb-source-changed' | ||
* @returns {Object} nb.block | ||
*/ | ||
setSource: function(source) { | ||
/* | ||
* Set new items for select | ||
* @params {Array} source New source | ||
* @fires 'nb-source-changed' | ||
* @returns {Object} nb.block | ||
*/ | ||
setSource: function(source) { | ||
if (!source) { | ||
return this; | ||
} | ||
if (!source) { | ||
return this; | ||
} | ||
if (!(source instanceof Array)) { | ||
source = [source]; | ||
} | ||
// find all selected items | ||
var selected = []; | ||
source.forEach(function(item) { | ||
if (item.selected) { | ||
selected.push(item); | ||
if (!(source instanceof Array)) { | ||
source = [source]; | ||
} | ||
}); | ||
// leave only last selected item (this is native browser behaviour) | ||
selected.slice(0, -1).forEach(function(item) { | ||
item.selected = false; | ||
}); | ||
// find all selected items | ||
var selected = []; | ||
source.forEach(function(item) { | ||
if (item.selected) { | ||
selected.push(item); | ||
} | ||
}); | ||
// render options with yate to prevent XSS | ||
var html = yr.run(this.getYateModuleName(), { | ||
items: source | ||
}, 'nb-select-options'); | ||
// leave only last selected item (this is native browser behaviour) | ||
selected.slice(0, -1).forEach(function(item) { | ||
item.selected = false; | ||
}); | ||
// set new source for select | ||
this.$control.empty().append(html); | ||
// render options with yate to prevent XSS | ||
var html = yr.run(this.getYateModuleName(), { | ||
items: source | ||
}, 'nb-select-options'); | ||
this._updateFromSelect(); | ||
this.trigger('nb-source-changed', this); | ||
return this; | ||
}, | ||
// set new source for select | ||
this.$control.empty().append(html); | ||
/* | ||
* Get items from select | ||
* @returns {Array} source | ||
*/ | ||
getSource: function() { | ||
return $.map(this.$control.children('option'), function(node) { | ||
var $node = $(node); | ||
return { | ||
text: $node.text(), | ||
value: $node.val(), | ||
selected: $node.prop('selected') | ||
}; | ||
}); | ||
}, | ||
this._updateFromSelect(); | ||
this.trigger('nb-source-changed', this); | ||
return this; | ||
}, | ||
/* | ||
* Add items to select | ||
* @param {Array|Object} items | ||
* @param {Number} index to insert | ||
* @fires 'nb-source-changed' | ||
* @returns {Object} nb.block | ||
*/ | ||
addToSource: function(items, index) { | ||
var source = this.getSource(); | ||
/* | ||
* Get items from select | ||
* @returns {Array} source | ||
*/ | ||
getSource: function() { | ||
return $.map(this.$control.children('option'), function(node) { | ||
var $node = $(node); | ||
return { | ||
text: $node.text(), | ||
value: $node.val(), | ||
selected: $node.prop('selected') | ||
}; | ||
}); | ||
}, | ||
if (!(items instanceof Array)) { | ||
items = [items]; | ||
} | ||
/* | ||
* Add items to select | ||
* @param {Array|Object} items | ||
* @param {Number} index to insert | ||
* @fires 'nb-source-changed' | ||
* @returns {Object} nb.block | ||
*/ | ||
addToSource: function(items, index) { | ||
var source = this.getSource(); | ||
var selectedItemValue = null; | ||
if (!(items instanceof Array)) { | ||
items = [items]; | ||
} | ||
var insertion = items.filter(function(item) { | ||
var newItem = source.indexOf(item) === -1; | ||
if (newItem) { | ||
if (item.selected) { | ||
// stores last selected item | ||
selectedItemValue = item.value; | ||
var selectedItemValue = null; | ||
var insertion = items.filter(function(item) { | ||
var newItem = source.indexOf(item) === -1; | ||
if (newItem) { | ||
if (item.selected) { | ||
// stores last selected item | ||
selectedItemValue = item.value; | ||
} | ||
return true; | ||
} | ||
return true; | ||
return false; | ||
}, this); | ||
if (isNaN(index)) { | ||
index = source.length; | ||
} | ||
return false; | ||
}, this); | ||
if (isNaN(index)) { | ||
index = source.length; | ||
} | ||
insertion.forEach(function(item, i) { | ||
source.splice(index + i, 0, item); | ||
}, this); | ||
insertion.forEach(function(item, i) { | ||
source.splice(index + i, 0, item); | ||
}, this); | ||
this.setSource(source); | ||
this.setSource(source); | ||
// set state from new items | ||
if (selectedItemValue) { | ||
// use #setState() to fire 'nb-changed' event | ||
this.setState({ | ||
value: selectedItemValue | ||
}); | ||
} | ||
this.trigger('nb-source-changed', this); | ||
return this; | ||
}, | ||
// set state from new items | ||
if (selectedItemValue) { | ||
// use #setState() to fire 'nb-changed' event | ||
this.setState({ | ||
value: selectedItemValue | ||
}); | ||
} | ||
this.trigger('nb-source-changed', this); | ||
return this; | ||
}, | ||
/* | ||
* Remove items to select | ||
* @param {Array|Object|number} items or index | ||
* @fires 'nb-source-changed' | ||
* @returns {Object} nb.block | ||
*/ | ||
removeFromSource: function(param) { | ||
var source = this.getSource(); | ||
/* | ||
* Remove items to select | ||
* @param {Array|Object|number} items or index | ||
* @fires 'nb-source-changed' | ||
* @returns {Object} nb.block | ||
*/ | ||
removeFromSource: function(param) { | ||
var source = this.getSource(); | ||
var index; | ||
var index; | ||
if (typeof param == 'number' || typeof param == 'string') { | ||
index = parseInt(param); | ||
} else if (!(param instanceof Array)) { | ||
param = [param]; | ||
} | ||
if (typeof param == 'number' || typeof param == 'string') { | ||
index = parseInt(param); | ||
} else if (!(param instanceof Array)) { | ||
param = [param]; | ||
} | ||
if (index || index === 0) { | ||
source.splice(index, 1); | ||
} else { | ||
param.forEach(function(item) { | ||
source = source.filter(function(obj) { | ||
return obj.text != item.text && obj.value != item.value; | ||
}); | ||
}, this); | ||
} | ||
if (index || index === 0) { | ||
source.splice(index, 1); | ||
} else { | ||
param.forEach(function(item) { | ||
source = source.filter(function(obj) { | ||
return obj.text != item.text && obj.value != item.value; | ||
}); | ||
}, this); | ||
} | ||
this.setSource(source); | ||
this.trigger('nb-source-changed', this); | ||
return this; | ||
}, | ||
this.setSource(source); | ||
this.trigger('nb-source-changed', this); | ||
return this; | ||
}, | ||
/** | ||
* Focus the select | ||
* @fires 'nb-focused' | ||
* @returns {Object} nb.block | ||
*/ | ||
focus: function() { | ||
if (this.isEnabled()) { | ||
this.$node.focus(); | ||
} | ||
this.trigger('nb-focused', this); | ||
return this; | ||
}, | ||
/** | ||
* Focus the select | ||
* @fires 'nb-focused' | ||
* @returns {Object} nb.block | ||
*/ | ||
focus: function() { | ||
if (this.isEnabled()) { | ||
this.$node.focus(); | ||
} | ||
this.trigger('nb-focused', this); | ||
return this; | ||
}, | ||
/** | ||
* Blur the select | ||
* @fires 'nb-blured' | ||
* @returns {Object} nb.block | ||
*/ | ||
blur: function() { | ||
if (this.isEnabled()) { | ||
this.$node.blur(); | ||
} | ||
this.trigger('nb-blured', this); | ||
return this; | ||
}, | ||
/** | ||
* Blur the select | ||
* @fires 'nb-blured' | ||
* @returns {Object} nb.block | ||
*/ | ||
blur: function() { | ||
if (this.isEnabled()) { | ||
this.$node.blur(); | ||
} | ||
this.trigger('nb-blured', this); | ||
return this; | ||
}, | ||
/** | ||
* Sets option to the jUI widget | ||
* http://api.jqueryui.com/autocomplete/#method-option | ||
* @param {Object.<string, number>} option — { | ||
/** | ||
* Sets option to the jUI widget | ||
* http://api.jqueryui.com/autocomplete/#method-option | ||
* @param {Object.<string, number>} option — { | ||
* name: value — имя и значение опцииопции | ||
* } | ||
* @fires 'nb-option-set' | ||
* @returns {Object} nb.block | ||
*/ | ||
setOption: function(option) { | ||
this.$node.autocomplete('option', option); | ||
this.trigger('nb-option-set', this); | ||
return this; | ||
}, | ||
* @fires 'nb-option-set' | ||
* @returns {Object} nb.block | ||
*/ | ||
setOption: function(option) { | ||
this.$node.autocomplete('option', option); | ||
this.trigger('nb-option-set', this); | ||
return this; | ||
}, | ||
/** | ||
* Gets option of the jUI widget | ||
* http://api.jqueryui.com/autocomplete/#method-option | ||
* @param {String} option | ||
* @returns {String} option value | ||
*/ | ||
getOption: function(option) { | ||
return this.$node.autocomplete('option', option); | ||
}, | ||
/** | ||
* Gets option of the jUI widget | ||
* http://api.jqueryui.com/autocomplete/#method-option | ||
* @param {String} option | ||
* @returns {String} option value | ||
*/ | ||
getOption: function(option) { | ||
return this.$node.autocomplete('option', option); | ||
}, | ||
/** | ||
* Destroy the select | ||
* @fires 'nb-destroyed' | ||
*/ | ||
destroy: function() { | ||
if (this.$node && this.$node.data('uiAutocomplete')) { | ||
this.$node.autocomplete('destroy'); | ||
this.$dropdown.empty().appendTo(this.$node); | ||
/** | ||
* Destroy the select | ||
* @fires 'nb-destroyed' | ||
*/ | ||
destroy: function() { | ||
if (this.$node && this.$node.data('uiAutocomplete')) { | ||
this.$node.autocomplete('destroy'); | ||
this.$dropdown.empty().appendTo(this.$node); | ||
} | ||
this.trigger('nb-destroyed', this); | ||
this.nbdestroy(); | ||
} | ||
this.trigger('nb-destroyed', this); | ||
this.nbdestroy(); | ||
} | ||
}, 'base'); | ||
}, | ||
'base' | ||
) | ||
; |
@@ -25,2 +25,3 @@ ## Yate | ||
* `'selected'` {boolean} | ||
* `'separator'` {boolean} | ||
* `'group'` {array} - group of options, array of items in `optgroup` | ||
@@ -27,0 +28,0 @@ |
@@ -9,3 +9,3 @@ { | ||
"description": "Yate/Stylus/jQuery-UI library for Yandex corporate style", | ||
"version": "0.3.15", | ||
"version": "0.3.16", | ||
"homepage": "http://yandex-ui.github.io/nanoislands/", | ||
@@ -19,9 +19,9 @@ "repository": { | ||
"stylobate": "0.23.x", | ||
"stylobate-islands": "0.25.x" | ||
"stylobate-islands": "0.26.x" | ||
}, | ||
"devDependencies": { | ||
"yate": "0.0.64", | ||
"yate": "0.0.70", | ||
"borschik": "0.4.x", | ||
"autoprefixer": "1.x", | ||
"stylus": "0.42.x", | ||
"stylus": "0.43.x", | ||
"csso": "1.3.x", | ||
@@ -28,0 +28,0 @@ "load-grunt-tasks": "~0.2.x", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
1457142
32538
+ Addedstylobate-islands@0.26.1(transitive)
- Removedstylobate-islands@0.25.1(transitive)
Updatedstylobate-islands@0.26.x