Created
August 28, 2014 16:11
-
-
Save cherifGsoul/645db39ab8e8b24505d9 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/yuyumu/2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="main"> | |
</div> | |
<script type="text/x-stache-template" id="app"> | |
<ui-app> | |
<ul> | |
<li> <a href="#!home">Home</li> | |
<li> <a href="#!contacts">Contacts</li> | |
</ul> | |
</ui-app> | |
</script> | |
<script type="text/x-stache-template" id="manager"> | |
<ui-manager defaultpage="home"> | |
</ui-manager> | |
</script> | |
<script type="text/x-stache-template" id="home"> | |
<ui-page title="Home">{{title}}</ui-page> | |
</script> | |
<script type="text/x-stache-template" id="contacts"> | |
<ui-page title="Contacts">{{title}}</ui-page> | |
</script> | |
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
<script src="http://canjs.com/release/2.1.3/can.jquery.js"></script> | |
<script src="http://canjs.com/release/2.1.3/can.stache.js"></script> | |
<script src="http://canjs.com/release/2.1.3/can.map.define.js"></script> | |
<script id="jsbin-javascript"> | |
can.Map.extend('AppState',{ | |
define:{ | |
defaultpage:{ | |
set:function(val){ | |
return val; | |
} | |
}, | |
page:{ | |
set:function(val){ | |
if(!val) | |
return this.attr('defaultpage') | |
return val; | |
} | |
} | |
} | |
}); | |
can.Component.extend('UIApp',{ | |
tag:'ui-app', | |
init:function(el,options){ | |
var scope=this.scope; | |
can.route.map(scope); | |
can.route(':page'); | |
can.route('',{page:scope.attr('defaultpage')}); | |
can.route.ready(); | |
}, | |
scope:AppState, | |
events:{ | |
inserted:function(el,ev){ | |
el.append(can.view('manager', this.scope)); | |
} | |
}, | |
helpers:{} | |
}); | |
can.Component.extend('UIManager',{ | |
tag:'ui-manager', | |
scope:{ | |
popPage:function(){ | |
}, | |
goTo:function(el,page){ | |
el.html(can.view(page,this)); | |
} | |
}, | |
events:{ | |
inserted:function(el,ev){ | |
var scope=this.scope; | |
this.scope.goTo(el,scope.attr('defaultpage')); | |
}, | |
'{can.route} page':function(route,ev){ | |
this.scope.goTo(this.element,route.attr('page')); | |
} | |
} | |
}); | |
can.Component.extend('UIPage',{ | |
tag:'ui-page' | |
}); | |
$('#main').html(can.view('app')); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="main"> | |
</div> | |
<script type="text/x-stache-template" id="app"> | |
<ui-app> | |
<ul> | |
<li> <a href="#!home">Home</li> | |
<li> <a href="#!contacts">Contacts</li> | |
</ul> | |
</ui-app> | |
<\/script> | |
<script type="text/x-stache-template" id="manager"> | |
<ui-manager defaultpage="home"> | |
</ui-manager> | |
<\/script> | |
<script type="text/x-stache-template" id="home"> | |
<ui-page title="Home">{{title}}</ui-page> | |
<\/script> | |
<script type="text/x-stache-template" id="contacts"> | |
<ui-page title="Contacts">{{title}}</ui-page> | |
<\/script> | |
<script src="//code.jquery.com/jquery-1.11.0.min.js"><\/script> | |
<script src="//canjs.com/release/2.1.3/can.jquery.js"><\/script> | |
<script src="//canjs.com/release/2.1.3/can.stache.js"><\/script> | |
<script src="//canjs.com/release/2.1.3/can.map.define.js"><\/script> | |
</body> | |
</html></script> | |
<script id="jsbin-source-javascript" type="text/javascript">can.Map.extend('AppState',{ | |
define:{ | |
defaultpage:{ | |
set:function(val){ | |
return val; | |
} | |
}, | |
page:{ | |
set:function(val){ | |
if(!val) | |
return this.attr('defaultpage') | |
return val; | |
} | |
} | |
} | |
}); | |
can.Component.extend('UIApp',{ | |
tag:'ui-app', | |
init:function(el,options){ | |
var scope=this.scope; | |
can.route.map(scope); | |
can.route(':page'); | |
can.route('',{page:scope.attr('defaultpage')}); | |
can.route.ready(); | |
}, | |
scope:AppState, | |
events:{ | |
inserted:function(el,ev){ | |
el.append(can.view('manager', this.scope)); | |
} | |
}, | |
helpers:{} | |
}); | |
can.Component.extend('UIManager',{ | |
tag:'ui-manager', | |
scope:{ | |
popPage:function(){ | |
}, | |
goTo:function(el,page){ | |
el.html(can.view(page,this)); | |
} | |
}, | |
events:{ | |
inserted:function(el,ev){ | |
var scope=this.scope; | |
this.scope.goTo(el,scope.attr('defaultpage')); | |
}, | |
'{can.route} page':function(route,ev){ | |
this.scope.goTo(this.element,route.attr('page')); | |
} | |
} | |
}); | |
can.Component.extend('UIPage',{ | |
tag:'ui-page' | |
}); | |
$('#main').html(can.view('app')); | |
</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
can.Map.extend('AppState',{ | |
define:{ | |
defaultpage:{ | |
set:function(val){ | |
return val; | |
} | |
}, | |
page:{ | |
set:function(val){ | |
if(!val) | |
return this.attr('defaultpage') | |
return val; | |
} | |
} | |
} | |
}); | |
can.Component.extend('UIApp',{ | |
tag:'ui-app', | |
init:function(el,options){ | |
var scope=this.scope; | |
can.route.map(scope); | |
can.route(':page'); | |
can.route('',{page:scope.attr('defaultpage')}); | |
can.route.ready(); | |
}, | |
scope:AppState, | |
events:{ | |
inserted:function(el,ev){ | |
el.append(can.view('manager', this.scope)); | |
} | |
}, | |
helpers:{} | |
}); | |
can.Component.extend('UIManager',{ | |
tag:'ui-manager', | |
scope:{ | |
popPage:function(){ | |
}, | |
goTo:function(el,page){ | |
el.html(can.view(page,this)); | |
} | |
}, | |
events:{ | |
inserted:function(el,ev){ | |
var scope=this.scope; | |
this.scope.goTo(el,scope.attr('defaultpage')); | |
}, | |
'{can.route} page':function(route,ev){ | |
this.scope.goTo(this.element,route.attr('page')); | |
} | |
} | |
}); | |
can.Component.extend('UIPage',{ | |
tag:'ui-page' | |
}); | |
$('#main').html(can.view('app')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment