Commit bf17b6e5 authored by Sindre Sorhus's avatar Sindre Sorhus

SammyJS: Fix paths, minify js, correct folder structure.

parent ca401cea
......@@ -22,7 +22,7 @@ p { position: absolute; top: 116px; left: 80px; margin: 0; padding: 0; width: 27
.new:hover { opacity: .75; }
.trashcan { position: absolute; top: 63px; left: 57px; width: 25px; height: 25px; cursor: pointer; background: url(assets/destroy.png) no-repeat; }
.trashcan { position: absolute; top: 63px; left: 57px; width: 25px; height: 25px; cursor: pointer; background: url(destroy.png) no-repeat; }
.trashcan:hover { opacity: .75; }
li .trashcan { float: right;
left: 95%;
......
......@@ -4,9 +4,9 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Sammy.js • TodoMVC</title>
<link rel="stylesheet" href="app.css">
<link rel="stylesheet" href="css/app.css">
<!--[if IE]>
<script src="../../assets/ie.js"></script>
<script src="../../../assets/ie.js"></script>
<![endif]-->
</head>
<body>
......@@ -31,11 +31,11 @@
<br />
based on some code by Brandon Aaron
</div>
<script src="../../assets/base.js"></script>
<script src="../../assets/jquery.min.js"></script>
<script src="lib/sammy.js"></script>
<script src="lib/sammy.template.js"></script>
<script src="lib/model.js"></script>
<script src="app.js"></script>
<script src="../../../assets/base.js"></script>
<script src="../../../assets/jquery.min.js"></script>
<script src="js/lib/sammy.js"></script>
<script src="js/lib/sammy.template.js"></script>
<script src="js/lib/model.js"></script>
<script src="js/app.js"></script>
</body>
</html>
\ No newline at end of file
Model={name:"model",init:function(){this._id=0;this._data=[];this._deserialize();return this},create:function(a,b){a.id=this._newId();var c=this._data[this._data.push(a)-1];!1!==b&&this.save();return this._clone(c)},first:function(){return this._clone(this._data[0])},last:function(){return this._clone(_data[this._data.length-1])},get:function(a){return this._clone(this._get(a))},getAll:function(){return this._clone(this._data)},filter:function(a,b){return this._clone(this._filter(a,b))},multiFilter:function(){return this._clone(this._multiFilter(filter))},
update:function(a,b,c){if(a=this._get(a)||!1)this._mixin(a,b),!1!==c&&this.save();return a},destroy:function(a,b){this._data.splice(this._indexOf(a),1);!1!==b&&this.save();return!0},destroyAll:function(a){this._data=[];!1!==a&&this.save();return!0},save:function(){this._serialize();return!0},_first:function(){return this._data[0]},_last:function(){return _data[this._data.length-1]},_get:function(a){return this._filter("id",a)[0]},_filter:function(a,b){var c=[],d,e,f="undefined"==typeof b;for(d in this._data)this._data.hasOwnProperty(d)&&
(e=this._data[d],(f||e[a]==b)&&c.push(e));return c},_multiFilter:function(a){var b=[],c,d,e;for(c in this._data)if(this._data.hasOwnProperty(c))for(d in e=this._data[c],a)a.hasOwnProperty(d)&&a[d]==e[d]&&b.push(e);return b},_indexOf:function(a){return this._data.indexOf(this._get(a))},_serialize:function(){localStorage[this.name]=JSON.stringify({prevId:this._id,data:this._data})},_deserialize:function(){var a=localStorage[this.name];a&&(a=JSON.parse(a),this._id=a.prevId,this._data=a.data)},_newId:function(){return this._id++},
_mixin:function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c])},_clone:function(a){var b=Object.prototype.toString.call(a),c=a;if("[object Object]"==b){var c={},d;for(d in a)a.hasOwnProperty(d)&&(c[d]=this._clone(a[d]))}else if("[object Array]"==b){c=[];b=0;for(d=a.length;b<d;b++)c[b]=this._clone(a[b])}return c}};"function"!==typeof Object.create&&(Object.create=function(a){function b(){}b.prototype=a;return new b});
\ No newline at end of file
This diff is collapsed.
(function(f){var d={};Sammy=Sammy||{};Sammy.Template=function(g,e){e||(e="template");g.helper(e,function(a,c,b){"undefined"==typeof b&&(b=a);a:{c=f.extend({},this,c);if(d[b])fn=d[b];else{if("undefined"==typeof a){a=!1;break a}fn=d[b]=new Function("obj",'var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push("'+a.replace(/[\r\t\n]/g," ").replace(/\"/g,'\\"').split("<%").join("\t").replace(/((^|%>)[^\t]*)/g,"$1\r").replace(/\t=(.*?)%>/g,'",$1,"').split("\t").join('");').split("%>").join('p.push("').split("\r").join("")+
"\");}return p.join('');")}a="undefined"!=typeof c?fn(c):fn}return a})}})(jQuery);
\ No newline at end of file
This diff is collapsed.
Model = {
name: 'model',
init: function() {
this._id = 0;
this._data = [];
this._deserialize();
return this;
},
create: function(attributes, save) {
attributes.id = this._newId();
var item = this._data[ (this._data.push(attributes)) - 1 ];
if (save !== false) {
this.save();
}
return this._clone(item);
},
first: function() {
return this._clone(this._data[0]);
},
last: function() {
return this._clone(_data[ this._data.length-1 ]);
},
get: function(id) {
return this._clone(this._get(id));
},
getAll: function() {
return this._clone(this._data);
},
filter: function(attribute, value) {
return this._clone(this._filter(attribute, value));
},
multiFilter: function(filters) {
return this._clone(this._multiFilter(filter));
},
update: function(id, attributes, save) {
var item = this._get(id) || false;
if (item) {
this._mixin(item, attributes);
if (save !== false) {
this.save();
}
}
return item;
},
destroy: function(id, save) {
this._data.splice(this._indexOf(id), 1);
if (save !== false) {
this.save();
}
return true;
},
destroyAll: function(save) {
this._data = [];
if (save !== false) {
this.save();
}
return true;
},
save: function() {
this._serialize();
return true;
},
_first: function() {
return this._data[0];
},
_last: function() {
return _data[ this._data.length-1 ];
},
_get: function(id) {
return this._filter('id', id)[0];
},
_filter: function(attribute, value) {
var items = [], key, item, undefValue = (typeof value == "undefined");
for (key in this._data) {
if (this._data.hasOwnProperty(key)) {
item = this._data[key];
if (undefValue || item[attribute] == value) {
items.push(item);
}
}
}
return items;
},
_multiFilter: function(filters) {
var items = [], key, attribute, item;
for (key in this._data) {
if (this._data.hasOwnProperty(key)) {
item = this._data[key];
for (attribute in filters) {
if (filters.hasOwnProperty(attribute)) {
if (filters[attribute] == item[attribute]) {
items.push(item);
}
}
}
}
}
return items;
},
_indexOf: function(id) {
return this._data.indexOf(this._get(id));
},
_serialize: function() {
var data = {
prevId: this._id,
data: this._data
};
localStorage[this.name] = JSON.stringify(data);
},
_deserialize: function() {
var data = localStorage[this.name];
if (data) {
data = JSON.parse(data);
this._id = data.prevId;
this._data = data.data;
}
},
_newId: function() {
return this._id++;
},
_mixin: function(to, from) {
for (var key in from) {
if (from.hasOwnProperty(key)) {
to[key] = from[key];
}
}
},
_clone: function(obj) {
var type = Object.prototype.toString.call(obj),
cloned = obj;
if (type == '[object Object]') {
cloned = {};
for (var key in obj) {
obj.hasOwnProperty(key) && (cloned[key] = this._clone(obj[key]));
}
} else if (type == '[object Array]') {
cloned = [];
for (var index = 0, length = obj.length; index < length; index++) {
cloned[index] = this._clone(obj[index]);
}
}
return cloned;
}
};
// http://javascript.crockford.com/prototypal.html
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
\ No newline at end of file
This diff is collapsed.
(function($) {
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
// adapted from: http://ejohn.org/blog/javascript-micro-templating/
// originally $.srender by Greg Borenstein http://ideasfordozens.com in Feb 2009
// modified for Sammy by Aaron Quint for caching templates by name
var srender_cache = {};
var srender = function(name, template, data) {
// target is an optional element; if provided, the result will be inserted into it
// otherwise the result will simply be returned to the caller
if (srender_cache[name]) {
fn = srender_cache[name];
} else {
if (typeof template == 'undefined') {
// was a cache check, return false
return false;
}
// Generate a reusable function that will serve as a template
// generator (and which will be cached).
fn = srender_cache[name] = new Function("obj",
"var p=[],print=function(){p.push.apply(p,arguments);};" +
// Introduce the data as local variables using with(){}
"with(obj){p.push(\"" +
// Convert the template into pure JavaScript
template
.replace(/[\r\t\n]/g, " ")
.replace(/\"/g, '\\"')
.split("<%").join("\t")
.replace(/((^|%>)[^\t]*)/g, "$1\r")
.replace(/\t=(.*?)%>/g, "\",$1,\"")
.split("\t").join("\");")
.split("%>").join("p.push(\"")
.split("\r").join("")
+ "\");}return p.join('');");
}
if (typeof data != 'undefined') {
return fn(data);
} else {
return fn;
}
};
Sammy = Sammy || {};
// <tt>Sammy.Template</tt> is a simple plugin that provides a way to create
// and render client side templates. The rendering code is based on John Resig's
// quick templates and Greg Borenstien's srender plugin.
// This is also a great template/boilerplate for Sammy plugins.
//
// Templates use <% %> tags to denote embedded javascript.
//
// === Examples
//
// Here is an example template (user.template):
//
// <div class="user">
// <div class="user-name"><%= user.name %></div>
// <% if (user.photo_url) { %>
// <div class="photo"><img src="<%= user.photo_url %>" /></div>
// <% } %>
// </div>
//
// Given that is a publicly accesible file, you would render it like:
//
// $.sammy(function() {
// // include the plugin
// this.use(Sammy.Template);
//
// this.get('#/', function() {
// // the template is rendered in the current context.
// this.user = {name: 'Aaron Quint'};
// // partial calls template() because of the file extension
// this.partial('user.template');
// })
// });
//
// You can also pass a second argument to use() that will alias the template
// method and therefore allow you to use a different extension for template files
// in <tt>partial()</tt>
//
// // alias to 'tpl'
// this.use(Sammy.Template, 'tpl');
//
// // now .tpl files will be run through srender
// this.get('#/', function() {
// this.partial('myfile.tpl');
// });
//
Sammy.Template = function(app, method_alias) {
// *Helper:* Uses simple templating to parse ERB like templates.
//
// === Arguments
//
// +template+:: A String template. '<% %>' tags are evaluated as Javascript and replaced with the elements in data.
// +data+:: An Object containing the replacement values for the template.
// data is extended with the <tt>EventContext</tt> allowing you to call its methods within the template.
// +name+:: An optional String name to cache the template.
//
var template = function(template, data, name) {
// use name for caching
if (typeof name == 'undefined') name = template;
return srender(name, template, $.extend({}, this, data));
};
// set the default method name/extension
if (!method_alias) method_alias = 'template';
// create the helper at the method alias
app.helper(method_alias, template);
};
})(jQuery);
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment