From abab7090dbbc19cadeb08aefafc72057a37b33dd Mon Sep 17 00:00:00 2001 From: Adam Schroeder Date: Tue, 5 Sep 2017 09:25:35 -0500 Subject: [PATCH 1/3] Returning canvas, featherEditor from onSaveButtonClickedCb --- angular-aviary.js | 266 +++++++++++++++++++++++----------------------- 1 file changed, 135 insertions(+), 131 deletions(-) diff --git a/angular-aviary.js b/angular-aviary.js index 83bcab9..db7bbb9 100644 --- a/angular-aviary.js +++ b/angular-aviary.js @@ -7,149 +7,153 @@ 'format amd'; /* global define */ -(function () { - 'use strict'; - - function ngAviary(angular, Aviary) { - - ngAviaryDirective.$inject = ['ngAviary']; - function ngAviaryDirective(ngAviary) { - return { - restrict: 'A', - scope: { - targetSelector: '@', - targetSrc: '@', - onSave: '&', - onSaveButtonClicked: '&', - onClose: '&' - }, - link: function (scope, element, attrs) { - - var targetImage = window.document.querySelector(scope.targetSelector); - - element.bind('click', function(e) { - e.preventDefault(); - return launchEditor(); - }); - - // Callbacks obj - var cbs = { - onSaveButtonClicked: onSaveButtonClickedCb, - onSave: onSaveCb, - onError: onErrorCb, - onClose: onCloseCb - }; - - var featherEditor = new Aviary.Feather( - angular.extend({}, ngAviary.configuration, cbs) - ); - - function launchEditor() { - featherEditor.launch({ - image: targetImage, - url: scope.targetSrc || targetImage.src - }); - return false; - } - - function onSaveButtonClickedCb(imageID) { - // User onSaveButtonClicked callback - (scope.onSaveButtonClicked || angular.noop)({id: imageID}); - } - - function onSaveCb(imageID, newURL) { - // User onSave callback - (scope.onSave || angular.noop)({ - id: imageID, - newURL: newURL - }); - - if(scope.closeOnSave || ngAviary.configuration.closeOnSave){ - featherEditor.close(); - } - } - - function onErrorCb(errorObj) { - // User errback - (scope.onError || angular.noop)({ - error: errorObj - }); - } - - function onCloseCb(isDirty) { - // User onClose callback - (scope.onClose || angular.noop)({ - isDirty: isDirty - }); - } +(function() { + 'use strict'; + + function ngAviary(angular, Aviary) { + + ngAviaryDirective.$inject = ['ngAviary']; + + function ngAviaryDirective(ngAviary) { + return { + restrict: 'A', + scope: { + targetSelector: '@', + targetSrc: '@', + onSave: '&', + onSaveButtonClicked: '&', + onClose: '&' + }, + link: function(scope, element, attrs) { + + var targetImage = window.document.querySelector(scope.targetSelector); + + element.bind('click', function(e) { + e.preventDefault(); + return launchEditor(); + }); + + // Callbacks obj + var cbs = { + onSaveButtonClicked: onSaveButtonClickedCb, + onSave: onSaveCb, + onError: onErrorCb, + onClose: onCloseCb + }; + + var featherEditor = new Aviary.Feather( + angular.extend({}, ngAviary.configuration, cbs) + ); + + function launchEditor() { + featherEditor.launch({ + image: targetImage, + url: scope.targetSrc || targetImage.src + }); + return false; + } + + function onSaveButtonClickedCb(imageID) { + var canvasId = ngAviary.configuration.adobeCanvasSelector || '#avpw_canvas_element'; + var canvas = angular.element(document.querySelector(canvasId))[0]; + + // User onSaveButtonClicked callback + return (scope.onSaveButtonClicked || angular.noop)({ id: imageID, canvas: canvas, featherEditor: featherEditor }); + } + + function onSaveCb(imageID, newURL) { + // User onSave callback + (scope.onSave || angular.noop)({ + id: imageID, + newURL: newURL + }); + + if (scope.closeOnSave || ngAviary.configuration.closeOnSave) { + featherEditor.close(); + } + } + + function onErrorCb(errorObj) { + // User errback + (scope.onError || angular.noop)({ + error: errorObj + }); + } + + function onCloseCb(isDirty) { + // User onClose callback + (scope.onClose || angular.noop)({ + isDirty: isDirty + }); + } + } + }; } - }; - } - function ngAviaryProvider(){ - /* jshint validthis:true */ + function ngAviaryProvider() { + /* jshint validthis:true */ - var defaults = { - apiKey: null - }; + var defaults = { + apiKey: null + }; - var requiredKeys = [ - 'apiKey' - ]; + var requiredKeys = [ + 'apiKey' + ]; - var config; + var config; - this.configure = function(params) { - // Can only be configured once - if (config) { - throw new Error('Already configured.'); - } + this.configure = function(params) { + // Can only be configured once + if (config) { + throw new Error('Already configured.'); + } - // Check if it is an `object` - if (!(params instanceof Object)) { - throw new TypeError('Invalid argument: `config` must be an `Object`.'); - } + // Check if it is an `object` + if (!(params instanceof Object)) { + throw new TypeError('Invalid argument: `config` must be an `Object`.'); + } - // Extend default configuration - config = angular.extend({}, defaults, params); + // Extend default configuration + config = angular.extend({}, defaults, params); - // Check if all required keys are set - angular.forEach(requiredKeys, function(key) { - if (!config[key]) { - throw new Error('Missing parameter:', key); - } - }); + // Check if all required keys are set + angular.forEach(requiredKeys, function(key) { + if (!config[key]) { + throw new Error('Missing parameter:', key); + } + }); - return config; - }; + return config; + }; - this.$get = function() { - if(!config) { - throw new Error('ngAviary must be configured first.'); - } + this.$get = function() { + if (!config) { + throw new Error('ngAviary must be configured first.'); + } - var getConfig = (function() { - return config; - })(); + var getConfig = (function() { + return config; + })(); - return { - configuration: getConfig - }; - }; + return { + configuration: getConfig + }; + }; + } + + return angular + .module('ngAviary', []) + .directive('ngAviary', ngAviaryDirective) + .provider('ngAviary', ngAviaryProvider); } - return angular - .module('ngAviary', []) - .directive('ngAviary', ngAviaryDirective) - .provider('ngAviary', ngAviaryProvider); - } - - if (typeof define === 'function' && define.amd) { - define(['angular', 'Aviary'], ngAviary); - } else if (typeof module !== 'undefined' && module && module.exports) { - ngAviary(angular, require('Aviary')); - module.exports = 'ngAviary'; - } else { - ngAviary(angular, (typeof global !== 'undefined' ? global : window).Aviary); - } -})(); + if (typeof define === 'function' && define.amd) { + define(['angular', 'Aviary'], ngAviary); + } else if (typeof module !== 'undefined' && module && module.exports) { + ngAviary(angular, require('Aviary')); + module.exports = 'ngAviary'; + } else { + ngAviary(angular, (typeof global !== 'undefined' ? global : window).Aviary); + } +})(); \ No newline at end of file From d8c9fc46dc25ef0aca0c8a3633791804cab463e2 Mon Sep 17 00:00:00 2001 From: Adam Schroeder Date: Tue, 5 Sep 2017 09:32:05 -0500 Subject: [PATCH 2/3] Revert my formatting changes --- angular-aviary.js | 269 +++++++++++++++++++++++----------------------- 1 file changed, 134 insertions(+), 135 deletions(-) diff --git a/angular-aviary.js b/angular-aviary.js index db7bbb9..ca732e5 100644 --- a/angular-aviary.js +++ b/angular-aviary.js @@ -7,153 +7,152 @@ 'format amd'; /* global define */ -(function() { - 'use strict'; - - function ngAviary(angular, Aviary) { - - ngAviaryDirective.$inject = ['ngAviary']; - - function ngAviaryDirective(ngAviary) { - return { - restrict: 'A', - scope: { - targetSelector: '@', - targetSrc: '@', - onSave: '&', - onSaveButtonClicked: '&', - onClose: '&' - }, - link: function(scope, element, attrs) { - - var targetImage = window.document.querySelector(scope.targetSelector); - - element.bind('click', function(e) { - e.preventDefault(); - return launchEditor(); - }); - - // Callbacks obj - var cbs = { - onSaveButtonClicked: onSaveButtonClickedCb, - onSave: onSaveCb, - onError: onErrorCb, - onClose: onCloseCb - }; - - var featherEditor = new Aviary.Feather( - angular.extend({}, ngAviary.configuration, cbs) - ); - - function launchEditor() { - featherEditor.launch({ - image: targetImage, - url: scope.targetSrc || targetImage.src - }); - return false; - } - - function onSaveButtonClickedCb(imageID) { - var canvasId = ngAviary.configuration.adobeCanvasSelector || '#avpw_canvas_element'; - var canvas = angular.element(document.querySelector(canvasId))[0]; - - // User onSaveButtonClicked callback - return (scope.onSaveButtonClicked || angular.noop)({ id: imageID, canvas: canvas, featherEditor: featherEditor }); - } - - function onSaveCb(imageID, newURL) { - // User onSave callback - (scope.onSave || angular.noop)({ - id: imageID, - newURL: newURL - }); - - if (scope.closeOnSave || ngAviary.configuration.closeOnSave) { - featherEditor.close(); - } - } - - function onErrorCb(errorObj) { - // User errback - (scope.onError || angular.noop)({ - error: errorObj - }); - } - - function onCloseCb(isDirty) { - // User onClose callback - (scope.onClose || angular.noop)({ - isDirty: isDirty - }); - } - } - }; +(function () { + 'use strict'; + + function ngAviary(angular, Aviary) { + + ngAviaryDirective.$inject = ['ngAviary']; + function ngAviaryDirective(ngAviary) { + return { + restrict: 'A', + scope: { + targetSelector: '@', + targetSrc: '@', + onSave: '&', + onSaveButtonClicked: '&', + onClose: '&' + }, + link: function (scope, element, attrs) { + + var targetImage = window.document.querySelector(scope.targetSelector); + + element.bind('click', function(e) { + e.preventDefault(); + return launchEditor(); + }); + + // Callbacks obj + var cbs = { + onSaveButtonClicked: onSaveButtonClickedCb, + onSave: onSaveCb, + onError: onErrorCb, + onClose: onCloseCb + }; + + var featherEditor = new Aviary.Feather( + angular.extend({}, ngAviary.configuration, cbs) + ); + + function launchEditor() { + featherEditor.launch({ + image: targetImage, + url: scope.targetSrc || targetImage.src + }); + return false; + } + + function onSaveButtonClickedCb(imageID) { + var canvasId = ngAviary.configuration.adobeCanvasSelector || '#avpw_canvas_element'; + var canvas = angular.element(document.querySelector(canvasId))[0]; + + // User onSaveButtonClicked callback + return (scope.onSaveButtonClicked || angular.noop)({ id: imageID, canvas: canvas, featherEditor: featherEditor }); + } + + function onSaveCb(imageID, newURL) { + // User onSave callback + (scope.onSave || angular.noop)({ + id: imageID, + newURL: newURL + }); + + if(scope.closeOnSave || ngAviary.configuration.closeOnSave){ + featherEditor.close(); + } + } + + function onErrorCb(errorObj) { + // User errback + (scope.onError || angular.noop)({ + error: errorObj + }); + } + + function onCloseCb(isDirty) { + // User onClose callback + (scope.onClose || angular.noop)({ + isDirty: isDirty + }); + } } + }; + } - function ngAviaryProvider() { - /* jshint validthis:true */ - - var defaults = { - apiKey: null - }; - - var requiredKeys = [ - 'apiKey' - ]; + function ngAviaryProvider(){ + /* jshint validthis:true */ - var config; + var defaults = { + apiKey: null + }; - this.configure = function(params) { - // Can only be configured once - if (config) { - throw new Error('Already configured.'); - } + var requiredKeys = [ + 'apiKey' + ]; - // Check if it is an `object` - if (!(params instanceof Object)) { - throw new TypeError('Invalid argument: `config` must be an `Object`.'); - } + var config; - // Extend default configuration - config = angular.extend({}, defaults, params); + this.configure = function(params) { + // Can only be configured once + if (config) { + throw new Error('Already configured.'); + } - // Check if all required keys are set - angular.forEach(requiredKeys, function(key) { - if (!config[key]) { - throw new Error('Missing parameter:', key); - } - }); + // Check if it is an `object` + if (!(params instanceof Object)) { + throw new TypeError('Invalid argument: `config` must be an `Object`.'); + } - return config; - }; + // Extend default configuration + config = angular.extend({}, defaults, params); - this.$get = function() { - if (!config) { - throw new Error('ngAviary must be configured first.'); - } + // Check if all required keys are set + angular.forEach(requiredKeys, function(key) { + if (!config[key]) { + throw new Error('Missing parameter:', key); + } + }); - var getConfig = (function() { - return config; - })(); + return config; + }; - return { - configuration: getConfig - }; - }; + this.$get = function() { + if(!config) { + throw new Error('ngAviary must be configured first.'); } - return angular - .module('ngAviary', []) - .directive('ngAviary', ngAviaryDirective) - .provider('ngAviary', ngAviaryProvider); - } + var getConfig = (function() { + return config; + })(); - if (typeof define === 'function' && define.amd) { - define(['angular', 'Aviary'], ngAviary); - } else if (typeof module !== 'undefined' && module && module.exports) { - ngAviary(angular, require('Aviary')); - module.exports = 'ngAviary'; - } else { - ngAviary(angular, (typeof global !== 'undefined' ? global : window).Aviary); + return { + configuration: getConfig + }; + }; } -})(); \ No newline at end of file + + return angular + .module('ngAviary', []) + .directive('ngAviary', ngAviaryDirective) + .provider('ngAviary', ngAviaryProvider); + } + + if (typeof define === 'function' && define.amd) { + define(['angular', 'Aviary'], ngAviary); + } else if (typeof module !== 'undefined' && module && module.exports) { + ngAviary(angular, require('Aviary')); + module.exports = 'ngAviary'; + } else { + ngAviary(angular, (typeof global !== 'undefined' ? global : window).Aviary); + } +})(); From 811163ffb0ca77ba79495a4a066ff9e300787a42 Mon Sep 17 00:00:00 2001 From: Adam Schroeder Date: Tue, 5 Sep 2017 10:58:09 -0500 Subject: [PATCH 3/3] Getting image element when user clicks launchEditor --- angular-aviary.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/angular-aviary.js b/angular-aviary.js index ca732e5..5908281 100644 --- a/angular-aviary.js +++ b/angular-aviary.js @@ -25,8 +25,6 @@ }, link: function (scope, element, attrs) { - var targetImage = window.document.querySelector(scope.targetSelector); - element.bind('click', function(e) { e.preventDefault(); return launchEditor(); @@ -45,6 +43,8 @@ ); function launchEditor() { + var targetImage = window.document.querySelector(scope.targetSelector); + featherEditor.launch({ image: targetImage, url: scope.targetSrc || targetImage.src