diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..0ee7932 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,64 @@ +module.exports = function(grunt) { + + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + + files : { + src: ['src/angular-help-overlay.js'] + }, + + jshint: { + all: { + src: '<%= files.src %>' + } + }, + + concat: { + dist: { + src: '<%= files.src %>', + dest: 'lib/<%= pkg.name %>.js' + } + }, + + uglify: { + options: { + preserveComments: false, + banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n', + report: 'min', + compress: { + drop_console: true + } + }, + dist: { + files: { + 'lib/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>'] + } + } + }, + + watch : { + js: { + files: '<%= files.src %>', + tasks: ['jshint', 'concat'] + } + }, + + connect: { + server: { + options: { + port: 8000, + base: '.', + keepalive: true + } + } + } + }); + + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-contrib-connect'); + + grunt.registerTask('default', ['jshint', 'concat', 'uglify']); +}; \ No newline at end of file diff --git a/example/index.html b/example/index.html index 319c1e6..0c729d4 100644 --- a/example/index.html +++ b/example/index.html @@ -24,16 +24,16 @@ - -
+ +
-

Chardin.js

Simple overlay instructions for your apps.

- See it in action + See it in action Or open it again

diff --git a/lib/angular-help-overlay.js b/lib/angular-help-overlay.js index 1aeb980..b5146e6 100644 --- a/lib/angular-help-overlay.js +++ b/lib/angular-help-overlay.js @@ -1,36 +1,37 @@ -'use strict'; +/*global angular:false */ 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: '=', - helpStart: '&', - helpStop: '&' + overlayStart: '&overlayStartCallback', + overlayStop: '&overlayStopCallback' }, link: function (scope, element, attrs) { $document.on('chardinJs:start', function (event) { - if (angular.isFunction(scope.helpStart)) { - scope.helpStart(event); + if (angular.isFunction(scope.overlayStart)) { + scope.overlayStart(event); } - console.log('START'); if (scope.helpOverlay === false) { scope.$apply(function () { + noop = true; scope.helpOverlay = true; }); } }); $document.on('chardinJs:stop', function (event) { - if (angular.isFunction(scope.helpStop)) { - scope.helpStop(event); + if (angular.isFunction(scope.overlayStop)) { + scope.overlayStop(event); } - console.log('STOP'); if (scope.helpOverlay === true) { scope.$apply(function () { + noop = true; scope.helpOverlay = false; }); } @@ -38,7 +39,9 @@ angular.module('angularHelpOverlay', []).directive('helpOverlay', ['$document', scope.$watch('helpOverlay', function (newValue, oldValue) { if (newValue !== oldValue) { - if (newValue === true) { + if (noop === true) { + noop = false; + } else if (newValue === true) { element.chardinJs('start'); } else if (newValue === false) { element.chardinJs('stop'); diff --git a/lib/angular-help-overlay.min.js b/lib/angular-help-overlay.min.js new file mode 100644 index 0000000..4f3603f --- /dev/null +++ b/lib/angular-help-overlay.min.js @@ -0,0 +1,2 @@ +/*! angular-help-overlay 2014-07-06 */ +angular.module("angularHelpOverlay",[]).directive("helpOverlay",["$document",function(a){var b=!1;return{restrict:"A",scope:{helpOverlay:"=",overlayStart:"&overlayStartCallback",overlayStop:"&overlayStopCallback"},link:function(c,d){a.on("chardinJs:start",function(a){angular.isFunction(c.overlayStart)&&c.overlayStart(a),c.helpOverlay===!1&&c.$apply(function(){b=!0,c.helpOverlay=!0})}),a.on("chardinJs:stop",function(a){angular.isFunction(c.overlayStop)&&c.overlayStop(a),c.helpOverlay===!0&&c.$apply(function(){b=!0,c.helpOverlay=!1})}),c.$watch("helpOverlay",function(a,c){a!==c&&(b===!0?b=!1:a===!0?d.chardinJs("start"):a===!1&&d.chardinJs("stop"))})}}}]); \ No newline at end of file diff --git a/src/angular-help-overlay.js b/src/angular-help-overlay.js new file mode 100644 index 0000000..b5146e6 --- /dev/null +++ b/src/angular-help-overlay.js @@ -0,0 +1,53 @@ +/*global angular:false */ + +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'); + } + } + }); + } + }; +}]); \ No newline at end of file