Skip to content
Browse files

checkmark notifications in popup!

  • Loading branch information...
1 parent 34a5ba9 commit 94cecd8d33b8496274755cd3672ca41022ace5f7 @janeklb committed
Showing with 53 additions and 35 deletions.
  1. +1 −1 README
  2. BIN checkmark.gif
  3. +4 −3 content_script.js
  4. +1 −1 manifest.json
  5. +3 −0 popup.css
  6. +42 −29 popup.js
  7. +2 −1 scripts.json
View
2 README
@@ -1 +1 @@
-Load common JavaScript libraries into any page
+Load common JavaScript libraries into Chrome tabs/windows
View
BIN checkmark.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
7 content_script.js
@@ -19,7 +19,7 @@ var API = {
}
},
- attachScript: function(script, callback) {
+ attachScript: function(scriptSrc, notifyLoaded) {
var target = document.getElementsByTagName('head');
if (target.length == 0)
target = document.getElementsByTagName('body');
@@ -28,9 +28,10 @@ var API = {
var scriptEl = document.createElement('script');
scriptEl.type = 'text/javascript';
- scriptEl.src = script.src;
+ scriptEl.src = scriptSrc;
scriptEl.onload = function() {
- API._log("loaded", script.label, script.version, script.src);
+ API._log("loaded", scriptSrc);
+ notifyLoaded();
};
target[0].appendChild(scriptEl);
}
View
2 manifest.json
@@ -1,6 +1,6 @@
{
"name": "Chrome JSKit",
- "version": "0.2",
+ "version": "0.2.1",
"description": "Load common JavaScript libraries into any page",
"permissions": ["tabs"],
"content_scripts": [
View
3 popup.css
@@ -3,6 +3,9 @@ body { font-size: 0.8em; font-family: monospace; }
ul { padding-left: 16px; width: 200px; }
li a { margin: 0 4px;}
li a.load, li a.loadDev { cursor: pointer; color: #552211; }
+li img { vertical-align: middle; }
+li span { position: relative; }
+li span img { position: absolute; right: -16px; top: -2px; }
.f-l { float: left; }
.f-r { float: right; }
View
71 popup.js
@@ -1,6 +1,35 @@
$(function() {
- var Script = Backbone.Model.extend();
+ var Script = Backbone.Model.extend({
+ isLoaded: false,
+ isLoadedDev: false,
+ load: function(loadDev) {
+
+ if (this.isLoaded)
+ return;
+
+ var m = this;
+
+ // process any dependencies
+ if (m.attributes.dependencies && m.collection) {
+ var collection = m.collection;
+ _(m.attributes.dependencies).each(function(dependency) {
+ collection.get(dependency).load();
+ });
+ }
+
+ // attach this script to the open tab
+ chrome.tabs.getSelected(null, function(tab) {
+ chrome.tabs.sendRequest(tab.id, {
+ action: "attachScript",
+ params: loadDev ? m.attributes.src_dev : m.attributes.src
+ }, function() {
+ m.isLoaded = true;
+ m.trigger('loaded');
+ });
+ });
+ }
+ });
var Scripts = Backbone.Collection.extend({
model: Script,
url: 'scripts.json',
@@ -28,41 +57,25 @@ $(function() {
render: function() {
this.$el.empty();
- this.$el.append(this.make('span', {}, this.model.get('label')));
- this.$el.append(this.make('a', {'class': 'load f-r'}, 'Load'));
+ var label = this.make('span', {title: 'version:' + this.model.get('version')}, this.model.get('label'));
+ this.$el.append(label);
- if (this.model.get('src_dev'))
- this.$el.append(this.make('a', {'class': 'loadDev f-r'}, 'Load Dev'));
+ if (!this.model.isLoaded) {
+ this.$el.append(this.make('a', {'class': 'load f-r'}, 'Load'));
+
+ if (this.model.get('src_dev'))
+ this.$el.append(this.make('a', {'class': 'loadDev f-r'}, 'Load Dev'));
+ } else {
+ label.appendChild(this.make('img', {src: 'checkmark.gif'}));
+ }
return this;
},
-
load: function() {
-
- // process any dependencies
- var m = this.model;
- attributes = m.attributes;
- if (attributes.dependencies) {
- var collection = m.collection;
- _(attributes.dependencies).each(function(dependency) {
- console.log(collection.get(dependency));
-// collection.get(dependency).load();
- });
- }
-
- // attach this script to the open tab
- chrome.tabs.getSelected(null, function(tab) {
- chrome.tabs.sendRequest(tab.id, {
- action: "attachScript",
- params: attributes
- }, function() {
- m.trigger('loaded');
- });
- });
+ this.model.load(false);
},
-
loadDev: function() {
-
+ this.model.load(true);
}
});
View
3 scripts.json
@@ -39,7 +39,8 @@
"scriptaculous": {
"label": "script.aculo.us",
"src": "https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js",
- "version": "1.9.0"
+ "version": "1.9.0",
+ "dependencies": ["prototype"]
},
"swfobject": {
"label": "SWFObject",

0 comments on commit 94cecd8

Please sign in to comment.
Something went wrong with that request. Please try again.