Created
March 25, 2012 15:44
-
-
Save mignev/2197610 to your computer and use it in GitHub Desktop.
SpineJS JavaScript api fix: Simple example for properties in spinejs models, controllers and etc.
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>App</title> | |
<meta name="viewport" content="width=device-width; initial-scale=1.0; minimum-scale=1; maximum-scale=1.0; user-scalable=0;"/> | |
<meta name="apple-mobile-web-app-capable" content="yes" /> | |
<meta name="format-detection" content="telephone=no" /> | |
<link rel="stylesheet" href="/application.css" type="text/css" charset="utf-8"> | |
<script src="/application.js" type="text/javascript" charset="utf-8"></script> | |
<script type="text/javascript" charset="utf-8"> | |
var jQuery = require("jqueryify"); | |
var exports = this; | |
jQuery(function(){ | |
require("lib/setup"); | |
Product = Spine.Model.sub({ | |
active: null, | |
activate: function() { return this.active = true; }, | |
getStatus: function() { return this.active; } | |
}); | |
Product.configure('Product', 'name'); | |
Product.extend(Spine.Model.Ajax); | |
Product.url = 'http://localhost/asd.php'; | |
Product.fetch() | |
Product.bind('refresh change', function() { | |
var theProd = Product.find(1); | |
theProd.activate(); | |
console.log(theProd.getStatus()); // -> true | |
console.log(Product.find(1).getStatus()); // -> true | |
}); | |
}); | |
</script> | |
<!-- Getting started script - should be removed --> | |
<!--script src="http://maccman-spine.herokuapp.com/mobile/start.js" type="text/javascript" charset="utf-8"></script--> | |
</head> | |
<body> | |
</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
### | |
...... | |
Module.create = Module.sub = | |
Controller.create = Controller.sub = | |
Model.sub = (instances, statics) -> | |
class result extends this | |
constructor: -> | |
for name, value of instances when typeof value is 'function' | |
@[name] = _bind(@[name], @) | |
super | |
_bind = (fn, me) -> | |
() -> fn.apply(me, arguments) | |
result.include(instances) if instances | |
result.extend(statics) if statics | |
result.unbind?() | |
result | |
...... | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment