Permalink
Browse files

add browserAction menu (eg. disable/enable tabulator, show data sourc…

…es, ...)
  • Loading branch information...
presbrey committed Nov 1, 2012
1 parent de202e6 commit ffdc64a18279ca98d614c04a091bf14cbb0dc902
View
@@ -1,2 +1,3 @@
background.js
+popup.js
skin.js
View
@@ -1,7 +1,10 @@
# background.js
+enabled = !!1
+
onBeforeSendHeaders = do (types=['application/rdf+xml','text/n3','text/turtle']) ->
(d) ->
+ return if not enabled
setup = false
for elt in d.requestHeaders when elt.name.toLowerCase() is 'accept'
setup = true
@@ -36,6 +39,7 @@ skin = (d) ->
})
onHeadersReceived = (d) ->
+ return if not enabled
for header in d.responseHeaders
if header.name.match(/content-type/i) and header.value.match(/\/(n3|rdf|turtle)/)
return init d
@@ -118,4 +122,20 @@ class Server
delete @clients[id]
server = new Server
+
+toggleEnabled = ->
+ enabled = !enabled
+ if enabled
+ chrome.browserAction.setIcon
+ path: 'rdf_flyer.48-color.gif'
+ else
+ chrome.browserAction.setIcon
+ path: 'rdf_flyer.48-gray.gif'
+
+chrome.extension.onMessage.addListener (message, sender, respond) ->
+ if message.method in ['disable', 'enable']
+ do toggleEnabled
+ respond
+ enabled: enabled
+
install()
View
@@ -3,12 +3,12 @@
"content_security_policy": "script-src 'self' https://; object-src 'self'",
"description": "Linked Data Browser",
"icons": {
- "48": "rdf_flyer.48.gif"
+ "48": "rdf_flyer.48-color.gif"
},
"manifest_version": 2,
"name": "Tabulator",
- "page_action": {
- "default_icon": "rdf_flyer.48.gif",
+ "browser_action": {
+ "default_icon": "rdf_flyer.48-color.gif",
"default_popup": "popup.html",
"default_title": "Linked Data Browser"
},
View
@@ -0,0 +1,19 @@
+factory = (method, callback) ->
+ ->
+ chrome.extension.sendMessage
+ method: method,
+ callback
+
+getStatus = factory 'status', (r) ->
+ if r.enabled
+ $('#disable').show()
+ else
+ $('#enable').show()
+
+jQuery ->
+ buttons = document.querySelectorAll 'div.button'
+ for elt in buttons
+ elt.addEventListener 'click', (e) ->
+ do factory e.target.id, ->
+ do window.close
+ do getStatus
View
@@ -1,8 +1,42 @@
-<!DOCTYPE html>
+<!doctype html>
<html>
-<head>
-</head>
-<body>
-<script type="text/javascript" src="popup.js"></script>
+ <head>
+ <title>Tabulator Popup</title>
+ <style>
+ body {
+ overflow: hidden;
+ margin: 0px;
+ padding: 0px;
+ background: white;
+ }
+
+ div:first-child {
+ margin-top: 0px;
+ }
+
+ div.button {
+ cursor: pointer;
+ text-align: center;
+ padding: 1px 3px;
+ font-family: sans-serif;
+ font-size: 0.8em;
+ width: 100px;
+ margin-top: 1px;
+ background: #cccccc;
+ border: 1px solid black;
+ }
+
+ div.button:hover {
+ background: #aaaaaa;
+ }
+
+ </style>
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
+ <script src="popup.js"></script>
+ </head>
+ <body>
+ <div id="disable" class="button" style="display: none">Disable</div>
+ <div id="enable" class="button" style="display: none">Enable</div>
+ </body>
</body>
</html>
View
@@ -1 +0,0 @@
-document.write('TODO');
File renamed without changes.
View
Binary file not shown.
View
@@ -14,11 +14,6 @@ connect()
load = (uri) ->
window.document.title = uri
- chrome.tabs.getCurrent (tab) ->
- chrome.pageAction.setPopup
- popup: 'popup.html?uri='+encodeURIComponent(uri)
- tabId: tab.id
- chrome.pageAction.show tab.id
kb = tabulator.kb
subject = kb.sym(uri)
tabulator.outline.GotoSubject(subject, true, undefined, true, undefined)

0 comments on commit ffdc64a

Please sign in to comment.