(function($){
$.extend($.fn, {
htmlColor: function(config){
return this.each(function(){
var h = this, t = $(this), o = t.find('option');
t.on({
'control.init': function(){
var gr = $('
', {'data-toggle': 'buttons', 'class':'jvcolor hikashop'}),
a = undefined;
o.each(function(i, item){
var value = item.value,
option = $(item),
label = $('', {
'class': ['btn', 'btn-'+item.text, (item.selected ? 'active' : '')].join(' ') ,
html: $(' ', {type: 'radio'})
})
;
label.on({
'click.hikashopcolor': function(){
/* set value for control in form */
t.trigger('control-receive', [value]);
//t.trigger('control-image', [i]);
t.trigger('control-field', [value]);
/* forward value to control source */
o.filter('[selected]').each(function(){
$(this).attr('selected', false);
});
option.attr('selected', true);
}
});
gr.append(label);
});
gr.button();
gr.insertAfter(t);
},
'control-receive': function(e, value){
t.val(value);
},
'control-field': function(e, cid){
$.each(['id','name','code','image','price','quantity','description','weight','url','width','length','height','contact','custom_info','files'], function(i, name){
var prefix = '#'+['hikashop_product', name].join('_'),
main = $([prefix, 'main'].join('_')),
sub = $([prefix, cid].join('_'));
if(sub.length && $.trim(sub.html())) {
main.html(sub.html());
/* setup slider for thumb image */
name != 'image' || main.find('ul').jcarousel();
}
});
},
'control.hide': function(){
t.addClass('jvcolor-hide');
}
});
t.trigger('control.init');
t.trigger('control.hide');
});
}
});
})(jQuery);
jQuery(function($){
$.each(JV.characteristic, function(i, item){
var ctrl = $('#hikashop_product_characteristic_'+item.characteristic_id);
if(ctrl.length) ctrl.htmlColor({
image_wrapper: '#hikashop_small_image_div',
images: '#hikashop_small_image_div [onmouseover^="return window.localPage.changeImage"]'
});
})
});