/**
* セレクトボックス風 選択リスト
*
* @param method
* @returns {*}
*/
_jq_.fn._my_select_list_ = function(method) {
var _this_ = this,
_class_name_ = 'active',
_methods_ = {
init : function(self) {
var __self__ = _jq_(self),
__select_tag__ = __self__.find('select');
//子要素にselectタグがあったら
if(__select_tag__.length){
var __select_item__ = __self__.find('.select_item');
//初期表示がなかったら
if( !__select_item__.length){
__select_item__ = __self__.append(
_jq_('
').addClass('select_item').html(
__select_item_text__(
__select_tag__.find('option:selected').text(),
__select_tag__.attr('data-item-prefix'),
__select_tag__.attr('data-item-suffix')
)
)
);
}
//表示リストの作成
var __select_list__ = _jq_('
').addClass('select_list');
__select_tag__.find('option').each(function (i2, e2) {
__select_list__.append(
_jq_('- ')
.html(_jq_(e2).text())
.attr('data-select-value', _jq_(e2).val())
.addClass( (_jq_(e2).val() === __select_tag__.val()) ? _class_name_ : '' )
);
});
__self__.append(__select_list__);
//選択部分クリック
_jq_(__self__.find('.select_item')).on('click', function (__event__) {
__event__.stopPropagation();
__event__.preventDefault();
if( typeof _method_ !== "undefined" ){
//開閉式を非表示に
_method_.change_open_list();
}
_methods_.change_list(__select_tag__);
//自身以外のセレクトリストを非表示に
_jq_('.select_box .select_item').removeClass(_class_name_);
_jq_(this).addClass(_class_name_);
return false;
});
//選択リストクリック
__select_list__.on('click', 'li',function (__event__) {
__event__.stopPropagation();
__event__.preventDefault();
//リストを非表示にする
_jq_(__self__.find('.select_item')).removeClass(_class_name_);
_jq_(__self__.find('.select_list li')).removeClass(_class_name_);
//表示を選択されたものに変更する
__select_tag__.val(_jq_(this).attr('data-select-value'));
_jq_(this).addClass(_class_name_);
_jq_(__self__.find('.select_item')).html(
__select_item_text__(
__select_tag__.find('option:selected').text(),
__select_tag__.attr('data-item-prefix'),
__select_tag__.attr('data-item-suffix')
)
);
__select_tag__.change();
return false;
});
}
},
change_list: function (self) {
var __self__ = _jq_(self),
__list_item__ = _jq_(__self__.nextAll('.select_list'));
__list_item__.children().remove();
_jq_(__self__.next('.select_item')).html(
__select_item_text__(
__self__.find('option:selected').text(),
__self__.attr('data-item-prefix'),
__self__.attr('data-item-suffix')
)
);
_jq_(__self__.find('option')).each(function (i2, e2) {
__list_item__.append(
_jq_('
- ')
.html(_jq_(e2).text())
.attr('data-select-value', _jq_(e2).val())
.addClass( (_jq_(e2).val() === __self__.val()) ? 'active' : '' )
);
});
}
};
function __select_item_text__(text, prefix, suffix) {
var _text_ = text;
if(prefix !== undefined && prefix !== null && prefix !== ''){
_text_ = (prefix + _text_);
}
if(suffix !== undefined && suffix !== null && suffix !== ''){
_text_ = (_text_ + suffix);
}
return _text_;
}
return this.each(function() {
var _this_ = _jq_(this);
if ( _methods_[method] ) {
return _methods_[ method ].apply( _this_, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return _methods_.init.apply( _this_, arguments );
} else {
_jq_.error( 'Method ' + method + ' does not exist' );
}
});
};