/*globals $,ibuyproperties*/ ibuyproperties.helpers=(function(){ function toJSO(input) { var obj = {}; if (ibuyproperties.isDebugMode) { console.log("Converting form data to JSON"); } input.find("[name]").each(function (pos,theElement) { if (ibuyproperties.isDebugMode) { console.log("Inspecting",$(theElement)); } var name = $(theElement).attr('name'); var isButton=false; var isCheckbox="checkbox"===$(theElement).attr('type'); var type = ["text","number"].indexOf($(theElement).attr('type') > -1)?$(theElement).attr('type'):undefined; if (type==="button") { isButton=true; } if (ibuyproperties.isDebugMode) { console.log("Element name/type/but/cbx",name,type,isButton,isCheckbox,$(theElement)); } if (isCheckbox) { obj[name]=$(theElement).is(':checked')?true:false; } else if(isButton){ obj[name]=$(theElement).hasClass('active')?true:false; } else { obj[name]=$(theElement).val(); } }); return obj; } return { toJSO:toJSO }; }());