2014-05-14 13:24:20 +00:00
|
|
|
/*
|
2015-07-01 08:31:14 +00:00
|
|
|
=require ../vendor/modernizr/modernizr.js
|
2015-07-01 09:51:03 +00:00
|
|
|
=require ../vendor/select2/js/select2.full.js
|
2015-07-01 08:31:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Select control
|
|
|
|
|
*
|
2014-05-14 13:24:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
(function($){
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Custom drop downs (Desktop only)
|
|
|
|
|
*/
|
|
|
|
|
$(document).render(function(){
|
|
|
|
|
if (Modernizr.touch)
|
|
|
|
|
return
|
|
|
|
|
|
2014-07-01 07:17:53 +00:00
|
|
|
var formatSelectOption = function(state) {
|
|
|
|
|
if (!state.id)
|
|
|
|
|
return state.text; // optgroup
|
|
|
|
|
|
|
|
|
|
var $option = $(state.element),
|
|
|
|
|
iconClass = $option.data('icon'),
|
|
|
|
|
imageSrc = $option.data('image')
|
|
|
|
|
|
|
|
|
|
if (iconClass)
|
|
|
|
|
return '<i class="select-icon '+iconClass+'"></i> ' + state.text
|
|
|
|
|
|
|
|
|
|
if (imageSrc)
|
|
|
|
|
return '<img class="select-image" src="'+imageSrc+'" alt="" /> ' + state.text
|
|
|
|
|
|
|
|
|
|
return state.text
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-01 10:00:10 +00:00
|
|
|
var selectOptions = {
|
|
|
|
|
templateResult: formatSelectOption,
|
|
|
|
|
templateSelection: formatSelectOption,
|
2015-07-15 07:56:02 +00:00
|
|
|
escapeMarkup: function(m) { return m },
|
|
|
|
|
width: 'style'
|
2015-07-01 10:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Bind custom select
|
|
|
|
|
*/
|
|
|
|
|
$('select.custom-select').each(function(){
|
|
|
|
|
var $element = $(this),
|
|
|
|
|
extraOptions = {}
|
|
|
|
|
|
|
|
|
|
// Prevent duplicate loading
|
|
|
|
|
if ($element.data('select2') != null) {
|
|
|
|
|
return true; // Continue
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-15 04:12:45 +00:00
|
|
|
$element.attr('data-disposable', 'data-disposable')
|
|
|
|
|
$element.one('dispose-control', function(){
|
|
|
|
|
if ($element.data('select2')) {
|
|
|
|
|
$element.select2('destroy')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2015-07-01 10:00:10 +00:00
|
|
|
if ($element.hasClass('select-no-search')) {
|
|
|
|
|
extraOptions.minimumResultsForSearch = Infinity
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$element.select2($.extend({}, selectOptions, extraOptions))
|
2014-07-01 07:17:53 +00:00
|
|
|
})
|
2014-09-29 04:15:49 +00:00
|
|
|
})
|
2014-07-01 07:17:53 +00:00
|
|
|
|
2014-09-29 04:15:49 +00:00
|
|
|
$(document).on('disable', 'select.custom-select', function(event, status){
|
|
|
|
|
$(this).select2('enable', !status)
|
2014-05-14 13:24:20 +00:00
|
|
|
})
|
2014-09-29 04:15:49 +00:00
|
|
|
|
|
|
|
|
$(document).on('focus', 'select.custom-select', function(event){
|
|
|
|
|
setTimeout($.proxy(function() { $(this).select2('focus') }, this), 10)
|
|
|
|
|
})
|
|
|
|
|
|
2014-05-14 13:24:20 +00:00
|
|
|
})(jQuery);
|