window._helper = {
pack: function(data){
return JSON.stringify(data);
},
unpack: function(data){
try {
return JSON.parse(data);
} catch(ex) {
return null;
}
},
isNumber: function(value){
return (!isNaN(parseFloat(value)) && isFinite(value) && !this.isString && !this.isBoolean && !this.isObject && !this.isArray);
},
isArray: function (value){
return (!this.isNull(value) && (Object.prototype.toString.call(value) === '[object Array]'));
},
isObject: function(value){
return (!this.isEmpty(value) && (typeof value == 'object'));
},
isBoolean: function(value){
return (typeof value == 'boolean');
},
isString: function(value){
return (typeof value == 'string');
},
isNull: function(value){
return ((value === undefined) || (value === null));
},
isEmpty: function(value){
return ( this.isNull(value) || ((typeof value.length != 'undefined') && (value.length == 0)) );
}
};
window.storage = {
get: function(key, defValue, typeValue){
var val = (typeof localStorage[key] == "undefined" || typeof localStorage[key] == "null") ? _helper.pack(defValue) : localStorage[key];
val = _helper.unpack(val) == null ? defValue : _helper.unpack(val);
switch (typeValue){
case 'number':
if(_helper.isNull(val) || _helper.isEmpty(val))
val = 0;
if(!_helper.isNumber(val))
val = parseFloat(val);
this.set(key, val);
break;
case 'boolean':
val = (_helper.isBoolean(val)) ? val : (defValue ? true : false);
this.set(key, val);
break;
case 'object':
case 'array':
val = _helper.isObject(val) || _helper.isArray(val) ? val : (typeValue == "array" ? [] : {});
this.set(key, val);
break;
default:
this.set(key, val);
break;
}
return val;
},
set: function(key, value){
value = _helper.pack(value);
localStorage[key] = value;
}
};
function tpl($vars) {
$tpl = 'tpl/'.$vars['name'].'.tpl';
if(is_file($tpl)) {
$template = file_get_contents($tpl);
foreach($vars['getdata'] as $name => $data) {
$template = str_replace(array("%%".$name.".title%%", "%%".$name.".value%%"), array($data['title'], $data['value']), $template);
}
$template = preg_replace('/(%%.*?%%)/' ,'', $template);
return $template;
}else {
return false;
}
}
Разработка крутого, по определению топикстартера, дизайна НЕ МЕНЕЕ двух недель.