function Templating(){ } Templating.parseTemplate=parseTemplate; if (!Templating) { function TemplateTank(){ var _templates = null; this.get_template=function(name){ var d=scanElm($(".__templates__")[0]); if(!_templates){ _templates={}; $.each(d,function(i,n){ //alert(n.match); // Rest is code var y=n.match(/[a-z0-9]{1,}/i)[0]; var u=n.replace(y,''); y=$.trim(y); _templates[y]=u; }); } return _templates[name]; } this.get_template_from_URI=function(uri,callback){ if(!_templates){ _templates={}; } if(_templates[uri]!=null){ //alert(uri); callback(_templates[uri]); }else{ now = new Date(); $.get("/template/ejs/"+uri+".ejs?"+now.toString(),{},function(data){ _templates[uri]=data; callback(_templates[uri]); }); } } }; TemplateTank = new TemplateTank(); } function scanElm(elm){ var rc = []; for(var c = 0; c < elm.childNodes.length; c++) { var child = elm.childNodes[c]; if (child.nodeType == 8){ rc.push(child.nodeValue); } }; return rc; } function parseTemplate(options){ var _string=sanatise(options.template); var _data=options.data; var _view=options.view || {}; var _del="[]"; var _left_caret=0; var _right_caret=0; var _code=""; //add_code("var output=\"\";"); while(_right_caret<_string.length){ var tag_left_caret=_string.indexOf("[%",_right_caret); if (tag_left_caret != -1) { add_code("output+=\""+_string.substring(_right_caret,tag_left_caret)+"\";"); var tag_right_caret = _string.indexOf("%]",tag_left_caret); var _adder=0; var _c=""; if(_string.substr(tag_left_caret,3)=="[%="){ _c="output+="+_string.substring(tag_left_caret+3,tag_right_caret)+";"; _adder=2; }else{ _c=_string.substring(tag_left_caret+2,tag_right_caret); _adder=2; } add_code(_c); _right_caret=tag_left_caret+(tag_right_caret-tag_left_caret)+_adder; }else{ add_code("output+=\""+_string.substr(_right_caret,_string.length-1)+"\";"); _right_caret=_string.length; } } // Evaluated the code on context of the data with(_view){ with(_data){ var output=""; //alert("Template\n\n"+_code); //alert(">> "+_code); try{ eval(_code); }catch(e){ alert(e); } //alert("Template\n\n"+output); return output; } } // Helper to append code to code string function add_code(string){ //alert(">>"+string); _code+=string;//+"\n"; } function sanatise(string){ var _string=string; _string=_string.replace(/\"/gi,'\\"'); // Replace quotes with \" to prevent eval breaking _string=_string.replace(/[\n\t\r]/gi,''); // Replace all tabs and newlines return _string; } } $.fn.x = function(n) { var result = null; this.each(function() { var o = this; if (n === undefined) { var x = 0; if (o.offsetParent) { while (o.offsetParent) { x += o.offsetLeft; o = o.offsetParent; } } if (result === null) { result = x; } else { result = Math.min(result, x); } } else { o.style.left = n + 'px'; } }); return result; }; $.fn.y = function(n) { var result = null; this.each(function() { var o = this; if (n === undefined) { var y = 0; if (o.offsetParent) { while (o.offsetParent) { y += o.offsetTop; o = o.offsetParent; } } if (result === null) { result = y; } else { result = Math.min(result, y); } } else { o.style.top = n + 'px'; } }); return result; }; /** * @author hedgehog */ function EventDelegator(options){ if(this.__EVENT_DELEGATOR__) return; this.__EVENT_DELEGATOR__=true; var _subscriptions={}; this.subscribe_to=function(event_key,event_delegate){ if(!_subscriptions[event_key]){ _subscriptions[event_key]=[]; } _subscriptions[event_key].push(event_delegate); }; this.unsubscribe_to=function(event_key,event_delegate){ $.each(_subscriptions[event_key],function(i,n){ if(event_delegate==n){ _subscriptions[event_key][i]=null; } }); } this.raise_event=function(event_name,args){ function each_subscription(index,item){ if(item){ item(args); } } if (_subscriptions[event_name]) { $.each(_subscriptions[event_name], each_subscription); } }; } /** * @author hedgehog */ function BaseView(scope){ EventDelegator.call(this,scope); this.render_template=function(template,data,callback){ TemplateTank.get_template_from_URI(template,function(_data){ callback(Templating.parseTemplate({ data:data, template:_data })); }); }; this.render_template_with_view=function(template,data,view,callback){ TemplateTank.get_template_from_URI(template,function(_data){ callback(Templating.parseTemplate({ data:data, view:view, template:_data })); }); }; this.render_template_from_markup=function(obj,callback){ var temp = Templating.parseTemplate({ data:obj.data, view:obj.view, template:obj.template }); callback(temp); }; } /** * @author hedgehog */ function BaseController(scope){ EventDelegator.call(this,scope); } /** * @author hedgehog */ function BaseModel(scope){ EventDelegator.call(this,scope); } // Static helper method to convert models that should be arrays into arrays BaseModel.to_array=function(obj){ if (obj.constructor.toString().indexOf("Array") == -1) obj=[obj]; return obj } function AvailabilityView(){} AvailabilityView.show_overlay=function(){}; $(function(e){ // Create overlay and append to body: $('
Checking Availability