Permalink
Browse files

Switched to manifest_version 2

  • Loading branch information...
1 parent 1c66336 commit 6e22b58e13e9a72e0e1e8a3dda367efcf640b35f @gornostal committed Aug 12, 2012
View
4 js/libs/underscore/underscore-min.js
@@ -31,4 +31,6 @@ u,function(a,b){return"'+\n_.escape("+w(b)+")+\n'"}).replace(d.interpolate||u,fu
b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var x=function(a,c){return c?b(a).chain():a},M=function(a,c){m.prototype[a]=function(){var a=i.call(arguments);J.call(a,this._wrapped);return x(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return x(d,
this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return x(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain=true;return this};m.prototype.value=function(){return this._wrapped}}).call(this);
-define([], function(){return _;});
+if (typeof define === "function" && define.amd) {
+ define('underscore', [], function () { return _; });
+}
View
34 js/modules/getTemplate.js
@@ -0,0 +1,34 @@
+define(function () {
+
+ var iframe = document.createElement('iframe'),
+ callbacks = [];
+
+ iframe.src = 'sandboxed/template-renderer.html';
+ iframe.style.display = 'none';
+ document.body.appendChild(iframe);
+
+ window.addEventListener('message', function (event) {
+ callbacks.forEach(function (item, idx) {
+ if (item && item.id == event.data.id) {
+ item.callback(event.data.result);
+ delete callbacks[idx];
+ }
+ });
+ });
+
+ return function (templateName, template) {
+ return function (context, callback) {
+ var id = Math.random();
+ callbacks.push({
+ id: id,
+ callback: callback
+ });
+ iframe.contentWindow.postMessage({
+ id: id,
+ templateName: templateName,
+ template: template,
+ context: context
+ }, '*');
+ };
+ };
+});
View
14 js/views/options.js
@@ -5,25 +5,27 @@ define([
'oauth',
'text!templates/options.html',
'modules/badge',
- 'collections/tweets'
-], function ($, _, Backbone, OAuth, optionsTemplate, Badge, tweets) {
+ 'collections/tweets',
+ 'modules/getTemplate'
+], function ($, _, Backbone, OAuth, optionsTemplate, Badge, tweets, getTemplate) {
- var oauth = new OAuth();
+ var oauth = new OAuth(),
+ template = getTemplate('optionsTemplate', optionsTemplate);
var OptionsView = Backbone.View.extend({
el: 'body',
- template: _.template(optionsTemplate),
-
events: {
'click a.sign-out': 'signOut',
'click a.sign-in': 'signIn'
},
render: function () {
var token = oauth.getAccessToken();
- $('#ph').html(this.template(token || {screen_name: null}));
+ template(token || {screen_name: null}, function (html) {
+ $('#ph').html(html);
+ });
},
signOut: function () {
View
2 js/views/popup.js
@@ -95,9 +95,11 @@ define([
$tweets = $('#home-timeline .tweet'),
top = $('#home-timeline').height() - 800;
+ $('#loading-tweets').hide();
$timeline.addClass('autoload');
$timeline.bind('scroll.autoload', function () {
if ($(this).scrollTop() > top) {
+ $('#loading-tweets').show();
$timeline.unbind('scroll.autoload');
that.loadOlderTweets($tweets.last().data('post_id'));
}
View
18 js/views/tweet.js
@@ -7,20 +7,21 @@ define([
'twitter',
'helpers/prettyDate',
'oauth',
+ 'modules/getTemplate',
'modules/jquery/imagePreview',
'bootstrap'
-], function ($, _, Backbone, tweetTemplate, parseEntities, TwitterApi, prettyDate, OAuth) {
+], function ($, _, Backbone, tweetTemplate, parseEntities,
+ TwitterApi, prettyDate, OAuth, getTemplate) {
var oauth = new OAuth(),
twitter = new TwitterApi(oauth),
- userId = oauth.getAccessToken().user_id;
+ userId = oauth.getAccessToken().user_id,
+ template = getTemplate('tweetTemplate', tweetTemplate);
var TweetView = Backbone.View.extend({
tagName: "div",
- template: _.template(tweetTemplate),
-
events: {
'click .actions .delete': 'deleteTweet',
'click .actions .favorite': 'toggleFavorite',
@@ -33,12 +34,15 @@ define([
render: function () {
if (!document.getElementById(this.model.id)) {
- var obj = this.model.toJSON();
+ var obj = this.model.toJSON(),
+ that = this;
if (typeof obj.retweeted_status != 'object') {
obj.retweeted_status = null;
}
- $(this.el).html(this.template(parseEntities(obj)));
- this.bindEventListeners();
+ template(parseEntities(obj), function (html) {
+ $(that.el).html(html);
+ that.bindEventListeners();
+ });
}
return this;
},
View
20 manifest.json
@@ -1,23 +1,33 @@
{
"name": "Twittext",
"description": "A lightweight Google Chrome extension for Twitter",
- "background_page": "background.html",
-
+ "background": {
+ "page": "background.html"
+ },
+ "manifest_version": 2,
"browser_action": {
"default_icon": "img/icon_19.png",
"default_title": "Twittext",
- "popup": "popup.html"
+ "default_popup": "popup.html"
},
"icons": {
"128": "img/icon_128.png",
"19": "img/icon_19.png",
"48": "img/icon_48.png"
},
"options_page": "options.html",
- "version": "1.5.0",
+ "version": "1.6.0",
"permissions": [
"tabs",
+ "background",
"https://api.twitter.com/",
"https://userstream.twitter.com/"
- ]
+ ],
+ "web_accessible_resources": [
+ "background.html",
+ "sandboxed/template-renderer.html"
+ ],
+ "sandbox": {
+ "pages": ["sandboxed/template-renderer.html"]
+ }
}
View
2 popup.html
@@ -77,7 +77,7 @@ <h4 class="whats-happening">What's happening?</h4>
</div>
<div id="home-timeline" class="tweets"></div>
- <div class="loading-tweets">
+ <div class="loading-tweets" id="loading-tweets">
<div>
An error has occurred while loading tweets.<br />
<a href="#" class="try-again">Try again.</a>
View
25 sandboxed/template-renderer.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Sandboxed Template Renderer</title>
+ <script src="/js/libs/underscore/underscore-min.js"></script>
+</head>
+<body>
+ <script>
+ var templates = {};
+ window.addEventListener('message', function (event) {
+ var template;
+ if (typeof templates[event.data.templateName] == 'undefined') {
+ template = _.template(event.data.template);
+ templates[event.data.templateName] = template;
+ } else {
+ template = templates[event.data.templateName];
+ }
+ event.source.postMessage({
+ id: event.data.id,
+ result: template(event.data.context)
+ }, event.origin);
+ });
+ </script>
+</html>

0 comments on commit 6e22b58

Please sign in to comment.