PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/js/demo.js

https://bitbucket.org/webcred/brizinga
JavaScript | 34 lines | 31 code | 1 blank | 2 comment | 7 complexity | 78e1900259f886b001ddf6e84683239d MD5 | raw file
  1. String.prototype.format = function() { a = this; for ( k in arguments ) { a = a.replace("{" + k + "}", arguments[k]); } return a; };
  2. window.demo = {
  3. 'version': '3.0-rc1',
  4. 'ga': '',
  5. 'primaryUrl': 'http://code.google.com/p/jquery-ui-map/',
  6. 'url': 'http://jquery-ui-map.googlecode.com/',
  7. 'forum': 'http://groups.google.com/group/jquery-ui-map-discuss/feed/rss_v2_0_msgs.xml',
  8. 'subscribe': 'http://groups.google.com/group/jquery-ui-map-discuss/boxsubscribe',
  9. 'exception': 'Unable to load due to either poor internet connection or some CDN\'s aren\'t as responsive as we would like them to be. Try refreshing the page :D.',
  10. 'init': function() {
  11. //window._gaq = [['_setAccount', this.ga], ['_trackPageview'], ['_trackPageLoadTime']];
  12. //Modernizr.load({ 'test': ( location.href.indexOf(this.url) > -1 ), 'yep': 'http://www.google-analytics.com/ga.js' });
  13. this.test('Backbone', function() {
  14. $('#forum').append('<h2>Forum</h2><ul id="forum_posts"></ul><h2>Subscribe</h2><form id="forum_subscribe" class="subscribe" action="#"><label for="email">E-mail:</label><input id="email" type="text" name="email" /><input type="submit" name="sub" value="Subscribe" /></form>');
  15. ForumCollection = Backbone.Collection.extend({ 'url': 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q={0}'.format(encodeURIComponent(demo.forum)), 'parse': function(response) { return response.responseData.feed.entries; } });
  16. ForumPost = Backbone.View.extend({ 'tagName': 'li', 'className': 'group-item', 'template': _.template('<a href="<%=link%>"><%=title%></a></h3>'), 'render': function() { $(this.el).html(this.template(this.model.toJSON())); return this; } });
  17. Forum = Backbone.View.extend({ 'el': $("#forum"), 'initialize': function() { this.col = new ForumCollection(); this.col.bind('reset', this.load, this); this.col.fetch(); }, 'add': function(post) { var view = new ForumPost({'model': post}); $('#forum_posts').append(view.render().el); }, 'load': function () { this.col.each(this.add); $('#forum_subscribe').attr('action', demo.subscribe); $(this.el).show(); } });
  18. var app = new Forum();
  19. });
  20. this.test('prettyPrint', function() { prettyPrint(); });
  21. $('#version').text(this.version);
  22. },
  23. 'redirect': function(url) { alert('This page is deprecated. Please update your URL. Redirecting to new page.'); window.location = url; },
  24. 'col': [],
  25. 'tests': [],
  26. 'test': function(a, b) { if ( window[a] ) { b(); } },
  27. 'add': function(a, b) { if (b) { this.col[a] = b; } else { this.col.push(a); } return this; },
  28. 'load': function(a) { var self = this; if (a) { self.col[a](); } else { $.each(self.col, function(i,d) { try { d(); } catch (err) { alert(self.exception); } }); } },
  29. 'timeStart': function(key, desc) { this.tests[key] = { 'start': new Date().getTime(), 'desc': desc }; },
  30. 'timeEnd': function(key) { this.tests[key].elapsed = new Date().getTime(); },
  31. 'report': function(id) { var i = 1; for ( var k in this.tests ) { var t = this.tests[k]; $(id).append('<div class="benchmark rounded"><div class="benchmark-result lt">' + (t.elapsed - t.start) + ' ms</div><div class="lt"><p class="benchmark-iteration">Benchmark case ' + i + '</p><p class="benchmark-title">' + t.desc + '</p></div></div>'); i++; }; }
  32. };
  33. demo.init();