diff options
author | Rogan Creswick <creswick@gmail.com> | 2013-01-02 15:31:43 -0800 |
---|---|---|
committer | Rogan Creswick <creswick@gmail.com> | 2013-01-02 15:31:43 -0800 |
commit | 91c8d16838b39c7726f6c0a0fb333f5ba38d2494 (patch) | |
tree | 136df17525e5e62f3ddc5b7a6dc71ffd31e2aa42 /tools/addon-sdk-1.12/examples/library-detector | |
parent | f7b228c479bac8828e521a2826d7f57f150da877 (diff) |
updated addon-sdk to 1.12
Diffstat (limited to 'tools/addon-sdk-1.12/examples/library-detector')
13 files changed, 259 insertions, 0 deletions
diff --git a/tools/addon-sdk-1.12/examples/library-detector/README.md b/tools/addon-sdk-1.12/examples/library-detector/README.md new file mode 100755 index 0000000..72285ac --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/README.md @@ -0,0 +1,13 @@ +<!-- This Source Code Form is subject to the terms of the Mozilla Public + - License, v. 2.0. If a copy of the MPL was not distributed with this + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> + +This is a port to the SDK of the +[Library Detector add-on](https://addons.mozilla.org/en-US/firefox/addon/library-detector/). +The original Library Detector is written by +[Paul Bakaus](http://paulbakaus.com/) and made available under the +[MIT License](http://www.opensource.org/licenses/mit-license.php). + +It only recognizes a subset of the libraries recognized by the original, +just to keep the SDK download package size and on-disk footprint as small +as possible. diff --git a/tools/addon-sdk-1.12/examples/library-detector/data/icons/closure.ico b/tools/addon-sdk-1.12/examples/library-detector/data/icons/closure.ico Binary files differnew file mode 100755 index 0000000..a8c91a0 --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/data/icons/closure.ico diff --git a/tools/addon-sdk-1.12/examples/library-detector/data/icons/jquery.ico b/tools/addon-sdk-1.12/examples/library-detector/data/icons/jquery.ico Binary files differnew file mode 100755 index 0000000..8df8f38 --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/data/icons/jquery.ico diff --git a/tools/addon-sdk-1.12/examples/library-detector/data/icons/jquery_ui.ico b/tools/addon-sdk-1.12/examples/library-detector/data/icons/jquery_ui.ico Binary files differnew file mode 100755 index 0000000..77e3bd2 --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/data/icons/jquery_ui.ico diff --git a/tools/addon-sdk-1.12/examples/library-detector/data/icons/modernizr.ico b/tools/addon-sdk-1.12/examples/library-detector/data/icons/modernizr.ico Binary files differnew file mode 100755 index 0000000..c37d438 --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/data/icons/modernizr.ico diff --git a/tools/addon-sdk-1.12/examples/library-detector/data/icons/mootools.png b/tools/addon-sdk-1.12/examples/library-detector/data/icons/mootools.png Binary files differnew file mode 100755 index 0000000..2a5df7d --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/data/icons/mootools.png diff --git a/tools/addon-sdk-1.12/examples/library-detector/data/icons/yui.ico b/tools/addon-sdk-1.12/examples/library-detector/data/icons/yui.ico Binary files differnew file mode 100755 index 0000000..06acd8a --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/data/icons/yui.ico diff --git a/tools/addon-sdk-1.12/examples/library-detector/data/library-detector.js b/tools/addon-sdk-1.12/examples/library-detector/data/library-detector.js new file mode 100755 index 0000000..af3a88e --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/data/library-detector.js @@ -0,0 +1,97 @@ +/* +The code in this file is adapted from the original +Library Detector add-on +(https://addons.mozilla.org/en-US/firefox/addon/library-detector/) written by +Paul Bakaus (http://paulbakaus.com/) and made available under the +MIT License (http://www.opensource.org/licenses/mit-license.php). +*/ + +var LD_tests = { + + 'jQuery': { + test: function(win) { + var jq = win.jQuery || win.$ || win.$jq || win.$j; + if(jq && jq.fn && jq.fn.jquery) { + return { version: jq.fn.jquery }; + } else { + return false; + } + } + }, + + 'jQuery UI': { + //phonehome: 'http://jqueryui.com/phone_home', + test: function(win) { + + var jq = win.jQuery || win.$ || win.$jq || win.$j; + if(jq && jq.fn && jq.fn.jquery && jq.ui) { + + var plugins = 'accordion,datepicker,dialog,draggable,droppable,progressbar,resizable,selectable,slider,menu,grid,tabs'.split(','), concat = []; + for (var i=0; i < plugins.length; i++) { if(jq.ui[plugins[i]]) concat.push(plugins[i].substr(0,1).toUpperCase() + plugins[i].substr(1)); }; + + return { version: jq.ui.version, details: concat.length ? 'Plugins used: '+concat.join(',') : '' }; + } else { + return false; + } + + } + }, + + 'MooTools': { + test: function(win) { + if(win.MooTools && win.MooTools.version) { + return { version: win.MooTools.version }; + } else { + return false; + } + } + }, + + 'YUI': { + test: function(win) { + if(win.YAHOO && win.YAHOO.VERSION) { + return { version: win.YAHOO.VERSION }; + } else { + return false; + } + } + }, + + 'Closure': { + test: function(win) { + if(win.goog) { + return { version: '2.0' }; + } + return false; + } + }, + + 'Modernizr': { + test: function(win) { + if(win.Modernizr) { + return { version: win.Modernizr._version }; + } + return false; + } + }, + + +}; + +function testLibraries() { + var win = unsafeWindow; + var libraryList = []; + for(var i in LD_tests) { + var passed = LD_tests[i].test(win); + if (passed) { + let libraryInfo = { + name: i, + version: passed.version + }; + libraryList.push(libraryInfo); + } + } + self.postMessage(libraryList); +} + +testLibraries();
\ No newline at end of file diff --git a/tools/addon-sdk-1.12/examples/library-detector/data/panel.html b/tools/addon-sdk-1.12/examples/library-detector/data/panel.html new file mode 100644 index 0000000..2829006 --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/data/panel.html @@ -0,0 +1,16 @@ +<!-- This Source Code Form is subject to the terms of the Mozilla Public + - License, v. 2.0. If a copy of the MPL was not distributed with this + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> + +<html> +<head> + <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> + <title>Library detector</title> + <script type="text/javascript"> + addon.on('message', function (libraryInfo) { + document.body.innerHTML = libraryInfo; + }); + </script> +</head> +<body></body> +</html> diff --git a/tools/addon-sdk-1.12/examples/library-detector/data/widget.html b/tools/addon-sdk-1.12/examples/library-detector/data/widget.html new file mode 100755 index 0000000..4ca5b50 --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/data/widget.html @@ -0,0 +1,50 @@ +<!-- This Source Code Form is subject to the terms of the Mozilla Public + - License, v. 2.0. If a copy of the MPL was not distributed with this + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> + +<html> +<head> + <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> + <title>Library detector</title> + <style type="text/css" media="all"> + img { + display: inline; + width: 16px; + height: 16px; + } + </style> + <script type="text/javascript"> + var icons = { + 'jQuery' : 'jquery.ico', + 'jQuery UI' : 'jquery_ui.ico', + 'MooTools' : 'mootools.png', + 'YUI' : 'yui.ico', + 'Closure' : 'closure.ico', + 'Modernizr': 'modernizr.ico', + }; + + // Listen for mouse events over icons, in order to send a message up to + // the panel and update its content with library name and version + window.addEventListener('mouseover', function (event) { + if (event.target.tagName == 'IMG') { + addon.port.emit('setLibraryInfo', event.target.title); + } + }, false); + + addon.port.on('update', function (libraries) { + // Cleanup previous content + document.body.innerHTML = ''; + + // Create new updated list of icons + libraries.forEach(function(library) { + var img = document.createElement('img'); + img.setAttribute('src', 'icons/' + icons[library.name]); + img.setAttribute('title', library.name + "<br>Version: " + + library.version); + document.body.appendChild(img); + }); + }); + </script> +</head> +<body></body> +</html> diff --git a/tools/addon-sdk-1.12/examples/library-detector/lib/main.js b/tools/addon-sdk-1.12/examples/library-detector/lib/main.js new file mode 100755 index 0000000..3f2b0c5 --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/lib/main.js @@ -0,0 +1,67 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const tabs = require('tabs'); +const widgets = require('widget'); +const data = require('self').data; +const pageMod = require('page-mod'); +const panel = require('panel'); + +const ICON_WIDTH = 16; + +function updateWidgetView(tab) { + let widgetView = widget.getView(tab.window); + if (!tab.libraries) { + tab.libraries = []; + } + widgetView.port.emit("update", tab.libraries); + widgetView.width = tab.libraries.length * ICON_WIDTH; +} + +var widget = widgets.Widget({ + id: "library-detector", + label: "Library Detector", + contentURL: data.url("widget.html"), + panel: panel.Panel({ + width: 240, + height: 60, + contentURL: data.url("panel.html") + }) +}); + +widget.port.on('setLibraryInfo', function(libraryInfo) { + widget.panel.postMessage(libraryInfo); +}); + +pageMod.PageMod({ + include: "*", + contentScriptWhen: 'end', + contentScriptFile: (data.url('library-detector.js')), + onAttach: function(worker) { + worker.on('message', function(libraryList) { + if (!worker.tab.libraries) { + worker.tab.libraries = []; + } + libraryList.forEach(function(library) { + if (worker.tab.libraries.indexOf(library) == -1) { + worker.tab.libraries.push(library); + } + }); + if (worker.tab == tabs.activeTab) { + updateWidgetView(worker.tab); + } + }); + } +}); + +tabs.on('activate', function(tab) { + updateWidgetView(tab); +}); + +/* +For change of location +*/ +tabs.on('ready', function(tab) { + tab.libraries = []; +});
\ No newline at end of file diff --git a/tools/addon-sdk-1.12/examples/library-detector/package.json b/tools/addon-sdk-1.12/examples/library-detector/package.json new file mode 100755 index 0000000..6d868ff --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/package.json @@ -0,0 +1,9 @@ +{ + "name": "library-detector-sdk", + "license": "MPL 2.0", + "author": "", + "version": "0.1", + "fullName": "library-detector-sdk", + "id": "jid1-R4rSVNkBANnvGQ", + "description": "a basic add-on" +} diff --git a/tools/addon-sdk-1.12/examples/library-detector/test/test-main.js b/tools/addon-sdk-1.12/examples/library-detector/test/test-main.js new file mode 100644 index 0000000..72fedf4 --- /dev/null +++ b/tools/addon-sdk-1.12/examples/library-detector/test/test-main.js @@ -0,0 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +exports.testMain = function(test) { + test.pass("TODO: Write some tests."); +}; |