Permalink
Browse files

npm module, CommonJS, and AMD support. includes global / module jquer…

…y reference detection.
  • Loading branch information...
1 parent 73dffa7 commit 2f6e6dfc413e46eb318bcbc508bc7c6bc6e96c9d @petemill petemill committed May 5, 2016
Showing with 55 additions and 3 deletions.
  1. +1 −0 .gitignore
  2. +31 −0 package.json
  3. +23 −3 screentime.js
View
@@ -0,0 +1 @@
+node_modules
View
@@ -0,0 +1,31 @@
+{
+ "name": "screentime",
+ "version": "1.0.0",
+ "description": "Screentime ==========",
+ "main": "screentime.js",
+ "directories": {
+ "example": "examples",
+ "test": "test"
+ },
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/petemill/screentime.git"
+ },
+ "keywords": [
+ "analytics",
+ "elements",
+ "time"
+ ],
+ "author": "",
+ "license": "ISC",
+ "bugs": {
+ "url": "https://github.com/petemill/screentime/issues"
+ },
+ "homepage": "https://github.com/petemill/screentime#readme",
+ "dependencies": {
+ "jquery": "^2.2.3"
+ }
+}
View
@@ -4,8 +4,28 @@
* Copyright (c) 2015 Rob Flaherty (@robflaherty)
* Licensed under the MIT and GPL licenses.
*/
-
-(function($, window, document) {
+ /* Universal module definition */
+
+ (function(factory) {
+
+ //attempt to get global reference to jQuery
+ //if it's available, we shouldn't ask for the reference from elsewhere
+ var jQueryRef;
+ if (window && window.jQuery) {
+ jQueryRef = window.jQuery;
+ }
+ //either call this module's factory or return the output
+ if (!jQueryRef && typeof define === 'function' && define.amd) {
+ // AMD
+ define(['jquery'], factory);
+ } else if (typeof module === 'object' && module.exports) {
+ // CommonJS, use global jQuery ref or load from module
+ module.exports = factory(jQueryRef || require('jquery'));
+ } else {
+ // Browser globals
+ factory(jQuery);
+ }
+ }(function($) {
var defaults = {
fields: [],
@@ -230,4 +250,4 @@
};
-})(jQuery, window, document);
+}));

0 comments on commit 2f6e6df

Please sign in to comment.