From bda9f68e261202f00a996e4a8af53cfb056b85de Mon Sep 17 00:00:00 2001 From: Grant Eagon Date: Wed, 25 Oct 2017 16:20:29 -0400 Subject: [PATCH 1/2] make npm module bump npm version --- off-canvas.js | 123 ++++++++++++++++++++++++++++++-------------------- package.json | 2 +- 2 files changed, 74 insertions(+), 51 deletions(-) diff --git a/off-canvas.js b/off-canvas.js index 5acaa24..ec390a9 100644 --- a/off-canvas.js +++ b/off-canvas.js @@ -4,53 +4,76 @@ * License: MIT */ -'use strict'; - -angular.module('cn.offCanvas', []) - .factory('cnOffCanvas', function($compile, $rootScope, $controller, $http, $templateCache, $q) { - return function (config) { - var container = angular.element(config.container || document.body), - containerClass = config.containerClass || 'is-off-canvas-opened', - controller = config.controller || angular.noop, - controllerAs = config.controllerAs, - element = null, - html, deferred, scope, ctrl; - - if ((+!!config.template) + (+!!config.templateUrl) !== 1) { - throw new Error('You must specify either a `template` or a `templateUrl` to create an off-canvas navigation.'); - } - - if (config.template) { - deferred = $q.defer(); - deferred.resolve(config.template); - html = deferred.promise; - } else { - html = $http.get(config.templateUrl, { - cache: $templateCache - }).then(function(response) { - return response.data; - }); - } - - html.then(function(html) { - scope = $rootScope.$new(); - ctrl = $controller(controller, {$scope: scope}); - if (controllerAs) { - scope[controllerAs] = ctrl; - } - element = angular.element(html); - container.prepend(element); - $compile(element)(scope); - }) - - function toggle() { - this.isOpened = !this.isOpened; - container.toggleClass(containerClass); - } - - return { - toggle: toggle, - isOpened: false - } - } - }); +'format amd'; +/* global define */ + +(function () { + 'use strict'; + + function isUndefinedOrNull(val) { + return angular.isUndefined(val) || val === null; + } + + function cnOffCanvas(angular) { + + angular.module('cn.offCanvas', []) + .factory('cnOffCanvas', function($compile, $rootScope, $controller, $http, $templateCache, $q) { + return function (config) { + var container = angular.element(config.container || document.body), + containerClass = config.containerClass || 'is-off-canvas-opened', + controller = config.controller || angular.noop, + controllerAs = config.controllerAs, + element = null, + html, deferred, scope, ctrl; + + if ((+!!config.template) + (+!!config.templateUrl) !== 1) { + throw new Error('You must specify either a `template` or a `templateUrl` to create an off-canvas navigation.'); + } + + if (config.template) { + deferred = $q.defer(); + deferred.resolve(config.template); + html = deferred.promise; + } else { + html = $http.get(config.templateUrl, { + cache: $templateCache + }).then(function(response) { + return response.data; + }); + } + + html.then(function(html) { + scope = $rootScope.$new(); + ctrl = $controller(controller, {$scope: scope}); + if (controllerAs) { + scope[controllerAs] = ctrl; + } + element = angular.element(html); + container.prepend(element); + $compile(element)(scope); + }) + + function toggle() { + this.isOpened = !this.isOpened; + container.toggleClass(containerClass); + } + + return { + toggle: toggle, + isOpened: false + } + } + }); + + return 'cn.OffCanvas'; + } + + var isElectron = window && window.process && window.process.type; + if (typeof define === 'function' && define.amd) { + define(['angular'], cnOffCanvas); + } else if (typeof module !== 'undefined' && module && module.exports && (typeof require === 'function') && !isElectron) { + module.exports = cnOffCanvas(require('angular')); + } else { + cnOffCanvas(angular); + } +})(); diff --git a/package.json b/package.json index 941bb34..479d7d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-off-canvas", - "version": "0.1.0", + "version": "0.1.2", "description": "easily add an off-canvas navigation to your angular app", "main": "off-canvas.js", "scripts": { From d38724474e7bc5de2ab01ffec1ac11c3e6438661 Mon Sep 17 00:00:00 2001 From: Grant Eagon Date: Thu, 16 Nov 2017 16:07:17 -0500 Subject: [PATCH 2/2] add strict dependency injection --- off-canvas.js | 87 ++++++++++++++++++++++++----------------------- off-canvas.min.js | 2 +- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/off-canvas.js b/off-canvas.js index ec390a9..4a9986a 100644 --- a/off-canvas.js +++ b/off-canvas.js @@ -17,54 +17,57 @@ function cnOffCanvas(angular) { angular.module('cn.offCanvas', []) - .factory('cnOffCanvas', function($compile, $rootScope, $controller, $http, $templateCache, $q) { - return function (config) { - var container = angular.element(config.container || document.body), - containerClass = config.containerClass || 'is-off-canvas-opened', - controller = config.controller || angular.noop, - controllerAs = config.controllerAs, - element = null, - html, deferred, scope, ctrl; + .factory('cnOffCanvas', cnOffCanvasFactory); - if ((+!!config.template) + (+!!config.templateUrl) !== 1) { - throw new Error('You must specify either a `template` or a `templateUrl` to create an off-canvas navigation.'); - } + cnOffCanvasFactory.$inject = ['$compile', '$rootScope', '$controller', '$http', '$templateCache', '$q']; - if (config.template) { - deferred = $q.defer(); - deferred.resolve(config.template); - html = deferred.promise; - } else { - html = $http.get(config.templateUrl, { - cache: $templateCache - }).then(function(response) { - return response.data; - }); - } + function cnOffCanvasFactory ($compile, $rootScope, $controller, $http, $templateCache, $q) { + return function (config) { + var container = angular.element(config.container || document.body), + containerClass = config.containerClass || 'is-off-canvas-opened', + controller = config.controller || angular.noop, + controllerAs = config.controllerAs, + element = null, + html, deferred, scope, ctrl; - html.then(function(html) { - scope = $rootScope.$new(); - ctrl = $controller(controller, {$scope: scope}); - if (controllerAs) { - scope[controllerAs] = ctrl; - } - element = angular.element(html); - container.prepend(element); - $compile(element)(scope); - }) + if ((+!!config.template) + (+!!config.templateUrl) !== 1) { + throw new Error('You must specify either a `template` or a `templateUrl` to create an off-canvas navigation.'); + } - function toggle() { - this.isOpened = !this.isOpened; - container.toggleClass(containerClass); - } + if (config.template) { + deferred = $q.defer(); + deferred.resolve(config.template); + html = deferred.promise; + } else { + html = $http.get(config.templateUrl, { + cache: $templateCache + }).then(function(response) { + return response.data; + }); + } - return { - toggle: toggle, - isOpened: false - } - } - }); + html.then(function(html) { + scope = $rootScope.$new(); + ctrl = $controller(controller, {$scope: scope}); + if (controllerAs) { + scope[controllerAs] = ctrl; + } + element = angular.element(html); + container.prepend(element); + $compile(element)(scope); + }) + function toggle() { + this.isOpened = !this.isOpened; + container.toggleClass(containerClass); + } + + return { + toggle: toggle, + isOpened: false + } + } + } return 'cn.OffCanvas'; } diff --git a/off-canvas.min.js b/off-canvas.min.js index f7b93b6..113392e 100644 --- a/off-canvas.min.js +++ b/off-canvas.min.js @@ -1 +1 @@ -"use strict";angular.module("cn.offCanvas",[]).factory("cnOffCanvas",["$compile","$rootScope","$controller","$http","$templateCache","$q",function($compile,$rootScope,$controller,$http,$templateCache,$q){return function(config){function toggle(){this.isOpened=!this.isOpened,container.toggleClass(containerClass)}if(+!!config.template+ +!!config.templateUrl!==1)throw new Error;var html,container=angular.element(config.container||document.body),containerClass=config.containerClass||"is-off-canvas-opened",controller=config.controller||angular.noop,controllerAs=config.controllerAs,element=null;if(config.template){var deferred=$q.defer();deferred.resolve(config.template),html=deferred.promise}else html=$http.get(config.templateUrl,{cache:$templateCache}).then(function(response){return response.data});return html.then(function(html){var scope=$rootScope.$new(),ctrl=$controller(controller,{$scope:scope});controllerAs&&(scope[controllerAs]=ctrl),element=angular.element(html),container.prepend(element),$compile(element)(scope)}),{toggle:toggle,isOpened:!1}}}]); +"format amd";!function(){"use strict";function cnOffCanvas(angular){function cnOffCanvasFactory($compile,$rootScope,$controller,$http,$templateCache,$q){return function(config){function toggle(){this.isOpened=!this.isOpened,container.toggleClass(containerClass)}var html,deferred,scope,ctrl,container=angular.element(config.container||document.body),containerClass=config.containerClass||"is-off-canvas-opened",controller=config.controller||angular.noop,controllerAs=config.controllerAs,element=null;if(+!!config.template+ +!!config.templateUrl!==1)throw new Error("You must specify either a `template` or a `templateUrl` to create an off-canvas navigation.");return config.template?(deferred=$q.defer(),deferred.resolve(config.template),html=deferred.promise):html=$http.get(config.templateUrl,{cache:$templateCache}).then(function(response){return response.data}),html.then(function(html){scope=$rootScope.$new(),ctrl=$controller(controller,{$scope:scope}),controllerAs&&(scope[controllerAs]=ctrl),element=angular.element(html),container.prepend(element),$compile(element)(scope)}),{toggle:toggle,isOpened:!1}}}return angular.module("cn.offCanvas",[]).factory("cnOffCanvas",cnOffCanvasFactory),cnOffCanvasFactory.$inject=["$compile","$rootScope","$controller","$http","$templateCache","$q"],"cn.OffCanvas"}var isElectron=window&&window.process&&window.process.type;"function"==typeof define&&define.amd?define(["angular"],cnOffCanvas):"undefined"!=typeof module&&module&&module.exports&&"function"==typeof require&&!isElectron?module.exports=cnOffCanvas(require("angular")):cnOffCanvas(angular)}(); \ No newline at end of file