require(['hb'], function(hb) { new Product(hb); }); /** * @param * hb * @memberOf window * @returns Void */ var Product = function(hb) { /** * @memberOf Product * @returns Object */ var b = $('body'); /** * @memberOf Product * @returns Void */ var __construct = function() { initDelete(); initSelect(); }; /** * @memberOf Product * @returns Object */ var prep = { context : {}, template : hb.compile($('#hbtpl').html()) }; /** * @memberOf Product * @returns void */ var initDelete = function() { b.on('click', '.lm a.remove', function(e) { e.preventDefault(); $(this).parent().remove(); }); }; /** * @memberOf Product * @returns void */ var initSelect = function() { b.on('click', '.lm a.add', function(e) { e.preventDefault(); $('#popup').removeClass('hidden'); }); b.on('click', '#popup .child a', function(e) { e.preventDefault(); var el = $(this); prep.context = el.data(); if (!$('#lmp-' + el.data('id')).length) { var html = prep.template(prep.context); $('.lm:last').after(html); } $('#popup .close').trigger('click'); }); b.on('click', '#popup .close', function(e) { e.preventDefault(); $('#popup').addClass('hidden'); }); }; __construct(); }