A timeline of the last four years of detecting good old window.localStorage.
October 2009: 5059daa
A timeline of the last four years of detecting good old window.localStorage.
October 2009: 5059daa
The reflow appens as many times as there are frames per seconds. It recalculate all positions that change in order to diplay them. Basically, when you scroll you execute a function where you move things between two reflows. But there are functions that triggers reflows such as jQuery offset, scroll... So there are two things to take care about when you dynamically change objects in javascript to avoid too many reflows:
| (function addXhrProgressEvent($) { | |
| var originalXhr = $.ajaxSettings.xhr; | |
| $.ajaxSetup({ | |
| xhr: function() { | |
| var req = originalXhr(), that = this; | |
| if (req) { | |
| if (typeof req.addEventListener == "function" && that.progress !== undefined) { | |
| req.addEventListener("progress", function(evt) { | |
| that.progress(evt); | |
| }, false); |
| var open = window.XMLHttpRequest.prototype.open, | |
| send = window.XMLHttpRequest.prototype.send, | |
| onReadyStateChange; | |
| function openReplacement(method, url, async, user, password) { | |
| var syncMode = async !== false ? 'async' : 'sync'; | |
| console.warn( | |
| 'Preparing ' + | |
| syncMode + | |
| ' HTTP request : ' + |
| // create pub-sub functionality | |
| Backbone.pubSub = _.extend({}, Backbone.Events); | |
| // view one needs to trigger an event in view2 | |
| View1 = Backbone.View.extend({ | |
| triggerView2Event : function() { | |
| Backbone.pubSub.trigger('view2event', { 'some' : 'data' } ); | |
| }) |
| var parser = document.createElement('a'); | |
| parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
| parser.protocol; // => "http:" | |
| parser.hostname; // => "example.com" | |
| parser.port; // => "3000" | |
| parser.pathname; // => "/pathname/" | |
| parser.search; // => "?search=test" | |
| parser.hash; // => "#hash" | |
| parser.host; // => "example.com:3000" |
| [ | |
| {name: 'Afghanistan', code: 'AF'}, | |
| {name: 'Åland Islands', code: 'AX'}, | |
| {name: 'Albania', code: 'AL'}, | |
| {name: 'Algeria', code: 'DZ'}, | |
| {name: 'American Samoa', code: 'AS'}, | |
| {name: 'AndorrA', code: 'AD'}, | |
| {name: 'Angola', code: 'AO'}, | |
| {name: 'Anguilla', code: 'AI'}, | |
| {name: 'Antarctica', code: 'AQ'}, |
| <!doctype html> | |
| <!-- http://taylor.fausak.me/2015/01/27/ios-8-web-apps/ --> | |
| <html> | |
| <head> | |
| <title>iOS 8 web app</title> | |
| <!-- CONFIGURATION --> |
| initialize: -> | |
| @bind 'all', @_trackPageview | |
| _trackPageview: -> | |
| url = Backbone.history.getFragment() | |
| _gaq.push(['_trackPageview', "/#{url}"]) |
Generally one implements notifications by listening for events on specific models but if one wishes to have a single global message interchange, it could be done as follows:
var pubsub = new Backbone.Model;
View1 = Backbone.View.extend({
initialize: function(){
pubsub.bind('custom event', callback);
}
// ...