Updates.
This commit is contained in:
parent
d416f83afd
commit
7d54769859
|
@ -0,0 +1,180 @@
|
|||
title: Backbone.js
|
||||
---
|
||||
|
||||
### Binding events
|
||||
|
||||
.on('event', callback);
|
||||
.on('event', callback, context);
|
||||
|
||||
.on({
|
||||
'event1': callback,
|
||||
'event2': callback
|
||||
});
|
||||
|
||||
.on('all', callback);
|
||||
|
||||
.once('event', callback); /* Only happens once */
|
||||
|
||||
### Unbinding events
|
||||
|
||||
|
||||
object.off("change", onChange); // just the `onChange` callback
|
||||
object.off("change"); // all "change" callbacks
|
||||
object.off(null, onChange); // `onChange` callback for all events
|
||||
object.off(null, null, context); // all callbacks for `context` all events
|
||||
object.off(); // all
|
||||
|
||||
### Events
|
||||
|
||||
object.trigger('event')
|
||||
|
||||
view.listenTo(object, event, callback)
|
||||
view.stopListening()
|
||||
|
||||
### List of events
|
||||
|
||||
* Collection:
|
||||
* `add` (model, collection, options)
|
||||
* `remove` (model, collection, options)
|
||||
* `reset` (collection, options)
|
||||
* `sort` (collection, options)
|
||||
|
||||
* Model:
|
||||
* `change` (model, options)
|
||||
* `change:[attr]` (model, value, options)
|
||||
* `destroy` (model, collection, options)
|
||||
* `error` (model, xhr, options)
|
||||
|
||||
* Model and collection:
|
||||
* `request` (model, xhr, options)
|
||||
* `sync` (model, resp, options)
|
||||
|
||||
* Router:
|
||||
* `route:[name]` (params)
|
||||
* `route` (router, route, params)
|
||||
|
||||
### Views
|
||||
|
||||
// All attributes are optional
|
||||
var View = Backbone.View.extend({
|
||||
model: doc,
|
||||
|
||||
tagName: 'div',
|
||||
className: 'document-item',
|
||||
id: "document-" + doc.id,
|
||||
attributes: { href: '#' },
|
||||
|
||||
el: 'body',
|
||||
|
||||
events: {
|
||||
'click button.save': 'save',
|
||||
'click .cancel': function() { ... },
|
||||
'click': 'onclick'
|
||||
},
|
||||
|
||||
constructor: function() { ... },
|
||||
render: function() { ... }
|
||||
});
|
||||
|
||||
view = new View();
|
||||
view = new View({ el: ... });
|
||||
|
||||
view.$el.show();
|
||||
view.$("input");
|
||||
|
||||
view.remove();
|
||||
|
||||
view.delegateEvents();
|
||||
view.undelegateEvents();
|
||||
|
||||
### Model
|
||||
|
||||
// All attributes are optional
|
||||
var Model = Backbone.Model.extend({
|
||||
defaults: {
|
||||
'author': 'unknown'
|
||||
},
|
||||
idAttribute: '_id',
|
||||
parse: function() {
|
||||
}
|
||||
});
|
||||
|
||||
var obj = new Model({ title: "Lolita", author: "Nabokov" });
|
||||
|
||||
var obj = new Model({ collection: ... });
|
||||
|
||||
obj.id
|
||||
obj.cid //=> "c38" (client-side ID)
|
||||
|
||||
obj.clone()
|
||||
|
||||
obj.hasChanged('title')
|
||||
obj.changedAttributes() /* false, or hash */
|
||||
obj.previousAttributes() /* false, or hash */
|
||||
obj.previous('title')
|
||||
|
||||
obj.isNew()
|
||||
|
||||
obj.set({ title: 'A Study in Pink' });
|
||||
obj.set({ title: 'A Study in Pink' }, { validate: true, silent: true });
|
||||
obj.unset('title')
|
||||
|
||||
obj.get('title')
|
||||
obj.has('title')
|
||||
obj.escape('title') /* Like .get() but HTML-escaped */
|
||||
|
||||
obj.clear()
|
||||
obj.clear({ silent: true })
|
||||
|
||||
obj.save()
|
||||
obj.save({ attributes })
|
||||
obj.save(null, {
|
||||
silent: true, patch: true, wait: true,
|
||||
success: callback, error: callback
|
||||
})
|
||||
|
||||
obj.destroy()
|
||||
obj.destroy({
|
||||
wait: true,
|
||||
success: callback, error: callback
|
||||
})
|
||||
|
||||
obj.toJSON()
|
||||
|
||||
obj.fetch()
|
||||
obj.fetch({ success: callback, error: callback })
|
||||
|
||||
### Model: validation
|
||||
|
||||
var Model = Backbone.Model.extend({
|
||||
validate: function(attrs, options) {
|
||||
if (attrs.end < attrs.start) {
|
||||
return "Can't end before it starts";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
obj.validationError //=> "Can't end before it starts"
|
||||
obj.isValid()
|
||||
obj.on('invalid', function(model, error) { ... })
|
||||
|
||||
// Triggered on:
|
||||
obj.save()
|
||||
obj.set({...}, { validate: true })
|
||||
|
||||
### Model: custom URLs
|
||||
|
||||
var Model = Backbone.Model.extend({
|
||||
// Single URL (string or function)
|
||||
url: '/account',
|
||||
url: function() { return '/account'; },
|
||||
|
||||
// Both of these two work the same way
|
||||
url: function() { return '/books/' + this.id }),
|
||||
urlRoot: '/books'
|
||||
});
|
||||
|
||||
var obj = new Model({ url: ... });
|
||||
var obj = new Model({ urlRoot: ... });
|
||||
|
||||
|
1
bash.md
1
bash.md
|
@ -192,3 +192,4 @@ References
|
|||
----------
|
||||
|
||||
* http://wiki.bash-hackers.org/
|
||||
* http://wiki.bash-hackers.org/syntax/shellvars
|
||||
|
|
3
css.md
3
css.md
|
@ -94,6 +94,9 @@ Webkit extensions
|
|||
### UIWebView optimizations
|
||||
|
||||
/* http://www.bitsandpix.com/entry/ios-webkit-uiwebview-remove-tapclick-highlightborder-with-css/ */
|
||||
/*
|
||||
http://www.yuiblog.com/blog/2010/10/01/quick-tip-customizing-the-mobile-safari-tap-highlight-color/
|
||||
*/
|
||||
|
||||
* {
|
||||
-webkit-tap-highlight-color: rgba(0,0,0,0);
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
title: Google Analytics
|
||||
----
|
||||
|
||||
### Track events
|
||||
|
||||
// [..., category, action, label, value (int), noninteraction (bool)]
|
||||
_gaq.push(['_trackEvent', 'Videos', 'Play', 'Birthday video', true])
|
||||
_gaq.push(['_trackEvent', 'Projects', 'Donate', 'Project name'])
|
||||
_gaq.push(['_trackEvent', 'Accounts', 'Login'])
|
||||
|
||||
### Variables
|
||||
|
||||
// [..., index, name, value, scope (optional)]
|
||||
_gaq.push(['_setCustomVar', 1, 'Logged in', 'Yes', 2]);
|
||||
|
||||
// Scope = 1 (visitor), 2 (session), 3 (page, default)
|
||||
|
||||
https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables
|
||||
https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
|
2
html.md
2
html.md
|
@ -78,7 +78,7 @@ Only do this if you're not placing the site in the root!
|
|||
|
||||
### Google jQuery
|
||||
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
||||
|
||||
### Unsupported message
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
### BDD
|
||||
|
||||
mocha.setup('bdd');
|
||||
|
||||
describe('something', function() {
|
||||
beforeEach(function() {
|
||||
});
|
||||
|
||||
it('should work', function() {
|
||||
});
|
||||
});
|
||||
|
||||
### Async
|
||||
|
||||
it('should save', function(done) {
|
||||
var user = new User();
|
||||
user.save(function(err) {
|
||||
if (err) throw err;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
### Chai: Shoulds
|
||||
|
||||
chai.should();
|
||||
|
||||
foo.should.be.a('string');
|
||||
foo.should.equal('bar');
|
||||
foo.should.have.length(3);
|
||||
tea.should.have.property('flavors').with.length(3);
|
||||
|
|
@ -43,6 +43,10 @@ http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html
|
|||
time_tag Date.yesterday, 'Yesterday' #=> <time datetime="2010-11-03">Yesterday<%rtime>
|
||||
time_tag Date.today, :pubdate => true #=> <time datetime="2010-11-04" pubdate="pubdate">November 04, 2010</time>
|
||||
|
||||
time_tag Date.today, \
|
||||
:format => :short_date # (en.time.formats.short_date)
|
||||
|
||||
|
||||
### Files
|
||||
|
||||
= form_for @post, :multipart => true do |f|
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
title: Rsync
|
||||
|
||||
rsync --progress -avz --exclude '.Trashes' --exclude '.Spotlight-V100' --exclude '.fseventsd'
|
Loading…
Reference in New Issue