Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Blog working with posts, next step tags, need to rethink the widgets …

…and interacion with controller data
  • Loading branch information...
commit f76687200a6c3517a3e6e410b0a15cbdb4a754ce 1 parent ec86d43
@Siedrix authored
View
7 blog/app/controllers/blog.js
@@ -1,9 +1,12 @@
Loki.Controller.set('Posts',{
'Single': {
'params' : '{:name}',
- 'data': 'blog/single/{:name}.php',
+ 'data': 'posts/single/{:name}.php',
'template' : 'blog/single',
- 'widgets' : ['List','Tags'],
+ 'widgets' : [
+ 'List'
+ // ,'Tags'
+ ],
before : function(){
$(config.mainArea).html('');
},
View
2  blog/config.js
@@ -25,7 +25,7 @@ development = {
application : {
blog :'noCache!app/controllers/blog.js',
list :'noCache!app/widgets/list.js',
- tags :'noCache!app/widgets/tags.js',
+ // tags :'noCache!app/widgets/tags.js',
main :'noCache!app/main.js'
},
templates:{
View
4 blog/json/posts/list.php
@@ -1,12 +1,14 @@
<?php
$array = array(
array(
+ 'id' => 1,
'title' => 'Blog app spec created',
'description' => 'Created a spec of how Loki.js blog ui should work',
'tags' => array('Loki.js','Specs')
),
array(
- 'title' => 'Loki.js first draft',
+ 'id' => 2,
+ 'title' => 'Loki.js first draft',
'description' => 'Eventually you will have a server to dance with',
'tags' => array('Loki.js','Code')
),
View
6 blog/templates/blog/list.html
@@ -1,10 +1,10 @@
<div class="item">
<h4> ${title} </h4>
- <p> ${desc} </p>
+ <p> ${description} </p>
<p>
{{each tags}}
- <span>${$value} </span>
+ <span>${$value}</span>
{{/each}}
</p>
- <p><a class="view">View Blogpost</a></p>
+ <p><a href="#!/Posts/Single/${id}" class="view-more">View Blogpost</a></p>
</div>
View
2  blog/templates/widgets/sidebar/single.html
@@ -1 +1 @@
-<li>${title || tagName}</li>
+<li>${title}</li>
View
7 lib/loki-ajax.js
@@ -1,5 +1,7 @@
(function($L){
+ //This methods will be move to diferent modules
$L.extend({
+ //Move to Models
getData : function(options){
var dfd = $.Deferred();
@@ -18,14 +20,17 @@
return dfd.promise();
}else if(options.data){
//This is a hack
+ var context = this;
setTimeout(function(){
- dfd.resolveWith(null,options.data);
+ console.log('Do i get here?',options,dfd)
+ dfd.resolveWith(context,options.data);
},10)
return dfd.promise();
}else{
return null;
}
},
+ //Move to Views
render : function(options){
var target = options.target || config.mainArea;
var url = options.url || null;
View
11 lib/loki-controller.js
@@ -2,7 +2,8 @@
var _controllers = {};
//Dispatch controllers...
- $L.Events.on('Router::*::*',function(e){
+ $L.Events.on('Router::*::*',function(e,data){
+ console.log('From Router',e,data);
var hash = e.split("::");
hash.shift();
@@ -12,15 +13,18 @@
var controller = _controllers[hash[0]];
var action = _controllers[hash[0]][hash[1]];
//End uglyness
+
+ //Process extra url
+ var url = action.data.replace(/{:[^/]+}/g,data[0])
if(action.before){
action.before();
}
Loki.Widget.activate(action.widgets);
-
+
$L.render({
- url : action.data,
+ url : url,
template: action.template,
success:function(data){
if(action.after){
@@ -29,7 +33,6 @@
var afterRender = controller.key + '::' + action.key + '::AfterRender';
- console.log('From controller',afterRender, data);
$L.Events.emit(afterRender,data);
}
});
View
13 lib/loki-events.js
@@ -7,16 +7,15 @@
$L.extend({Events : Events});
//Bind hashchange to EventEmitter2
+ //Should be move to a Router Module
$(window).hashchange( function(){
var hash = location.hash.replace('#!/','').replace('#!','').split("/");
- if(!hash[0] || hash[0] == ""){
- hash[0] = 'Index';
- }
- if(!hash[1] || hash[1] == ""){
- hash[1] = 'Index';
- }
+ var controller = hash[0] || 'Index'
+ var action = hash[1] || 'Index';
- Loki.Events.emit('Router::'+hash.join('::'));
+ hash.splice(0,2).join('/')
+
+ Loki.Events.emit('Router::'+controller+'::'+action,hash);
});
})($L);
View
9 lib/loki-widget.js
@@ -11,7 +11,11 @@
activate : function(widgets){
_.each(widgets,function(name){
var widget = _widgets[name];
- widget.init();
+ console.log('Do i have a widget?',widget);
+ if(!widget.active){
+ widget.init();
+ widget.active = true;
+ }
_.each(widget.hooks,function(hook,onAction){
var path = onAction.split("::");
@@ -19,10 +23,7 @@
var path = path[0] + '::*::' + path[1];
}
- console.log('hook set for ', path)
Loki.Events.on(path,function(path, data){
- console.log('Hook()', arguments);
- console.log('What is widget inside Loki.Widget.js', widget)
hook(widget,data);
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.