Skip to content

Commit

Permalink
added closure and proper dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Thompson committed Jul 16, 2017
1 parent 1cef686 commit c4ed770
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 105 deletions.
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "bower_components"
}
4 changes: 2 additions & 2 deletions example/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ angular.module('app', ['angularHelpOverlay']).controller('MainCtrl', function ($

$scope.toggleHelp = function() {
$scope.showHelp = !$scope.showHelp;
/*var picture = $('.jumbotron img');
var picture = $('.jumbotron img');
if (picture.is(':visible')) {
return ($('body').data('chardinJs')).toggle();
} else {
Expand All @@ -22,7 +22,7 @@ angular.module('app', ['angularHelpOverlay']).controller('MainCtrl', function ($
}, 600, function() {
return ($('body').data('chardinJs')).toggle();
});
}*/
}
};

});
2 changes: 1 addition & 1 deletion example/js/demo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 62 additions & 50 deletions lib/angular-help-overlay.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,65 @@
/*global angular:false */
!(function () {

angular.module('angularHelpOverlay', []).directive('helpOverlay', ['$document', function ($document) {
var noop = false; // Special flag in case we get an a chardinJs change event outside of our control.
return {
restrict: 'A',
scope: {
helpOverlay: '=',
overlayStart: '&overlayStartCallback',
overlayStop: '&overlayStopCallback'
},
link: function (scope, element, attrs) {

$document.on('chardinJs:start', function (event) {
if (angular.isFunction(scope.overlayStart)) {
scope.overlayStart(event);
}

if (scope.helpOverlay === false) {
scope.$apply(function () {
noop = true;
scope.helpOverlay = true;
});
}
});

$document.on('chardinJs:stop', function (event) {
if (angular.isFunction(scope.overlayStop)) {
scope.overlayStop(event);
}

if (scope.helpOverlay === true) {
scope.$apply(function () {
noop = true;
scope.helpOverlay = false;
});
}
});

scope.$watch('helpOverlay', function (newValue, oldValue) {
if (newValue !== oldValue) {
if (noop === true) {
noop = false;
} else if (newValue === true) {
$(element).chardinJs('start');
} else if (newValue === false) {
$(element).chardinJs('stop');
angular.module('angularHelpOverlay', [])
.directive('helpOverlay', HelpOverlay);

HelpOverlay.$inject = ['$document'];

//angular.module('angularHelpOverlay', []).directive('helpOverlay', ['$document', function ($document) {

function HelpOverlay($document) {
var noop = false; // Special flag in case we get an a chardinJs change event outside of our control.
return {
restrict: 'A',
//controller: HelpOverlayController,
//controllerAs: 'vm',
scope: {
helpOverlay: '=',
overlayStart: '&overlayStartCallback',
overlayStop: '&overlayStopCallback'
},
link: function (scope, element, attrs) {

$(document).on('chardinJs:start', function (event) {
if (angular.isFunction(scope.overlayStart)) {
scope.overlayStart(event);
}
}
});
}
};
}]);

if (scope.helpOverlay === false) {
scope.$apply(function () {
noop = true;
scope.helpOverlay = true;
});
}
});

$(document).on('chardinJs:stop', function (event) {
if (angular.isFunction(scope.overlayStop)) {
scope.overlayStop(event);
}

if (scope.helpOverlay === true) {
scope.$apply(function () {
noop = true;
scope.helpOverlay = false;
});
}
});

scope.$watch('helpOverlay', function (newValue, oldValue) {
if (newValue !== oldValue) {
if (noop === true) {
noop = false;
} else if (newValue === true) {
$(element).chardinJs('start');
} else if (newValue === false) {
$(element).chardinJs('stop');
}
}
});
}
};
}

})();
4 changes: 2 additions & 2 deletions lib/angular-help-overlay.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 62 additions & 50 deletions src/angular-help-overlay.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,65 @@
/*global angular:false */
!(function () {

angular.module('angularHelpOverlay', []).directive('helpOverlay', ['$document', function ($document) {
var noop = false; // Special flag in case we get an a chardinJs change event outside of our control.
return {
restrict: 'A',
scope: {
helpOverlay: '=',
overlayStart: '&overlayStartCallback',
overlayStop: '&overlayStopCallback'
},
link: function (scope, element, attrs) {

$(document).on('chardinJs:start', function (event) {
if (angular.isFunction(scope.overlayStart)) {
scope.overlayStart(event);
}

if (scope.helpOverlay === false) {
scope.$apply(function () {
noop = true;
scope.helpOverlay = true;
});
}
});

$(document).on('chardinJs:stop', function (event) {
if (angular.isFunction(scope.overlayStop)) {
scope.overlayStop(event);
}

if (scope.helpOverlay === true) {
scope.$apply(function () {
noop = true;
scope.helpOverlay = false;
});
}
});

scope.$watch('helpOverlay', function (newValue, oldValue) {
if (newValue !== oldValue) {
if (noop === true) {
noop = false;
} else if (newValue === true) {
$(element).chardinJs('start');
} else if (newValue === false) {
$(element).chardinJs('stop');
angular.module('angularHelpOverlay', [])
.directive('helpOverlay', HelpOverlay);

HelpOverlay.$inject = ['$document'];

//angular.module('angularHelpOverlay', []).directive('helpOverlay', ['$document', function ($document) {

function HelpOverlay($document) {
var noop = false; // Special flag in case we get an a chardinJs change event outside of our control.
return {
restrict: 'A',
//controller: HelpOverlayController,
//controllerAs: 'vm',
scope: {
helpOverlay: '=',
overlayStart: '&overlayStartCallback',
overlayStop: '&overlayStopCallback'
},
link: function (scope, element, attrs) {

$(document).on('chardinJs:start', function (event) {
if (angular.isFunction(scope.overlayStart)) {
scope.overlayStart(event);
}
}
});
}
};
}]);

if (scope.helpOverlay === false) {
scope.$apply(function () {
noop = true;
scope.helpOverlay = true;
});
}
});

$(document).on('chardinJs:stop', function (event) {
if (angular.isFunction(scope.overlayStop)) {
scope.overlayStop(event);
}

if (scope.helpOverlay === true) {
scope.$apply(function () {
noop = true;
scope.helpOverlay = false;
});
}
});

scope.$watch('helpOverlay', function (newValue, oldValue) {
if (newValue !== oldValue) {
if (noop === true) {
noop = false;
} else if (newValue === true) {
$(element).chardinJs('start');
} else if (newValue === false) {
$(element).chardinJs('stop');
}
}
});
}
};
}

})();

0 comments on commit c4ed770

Please sign in to comment.