provider.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @description
  3. * var app = angular.module('App', ['flow.provider'], function(flowFactoryProvider){
  4. * flowFactoryProvider.defaults = {target: '/'};
  5. * });
  6. * @name flowFactoryProvider
  7. */
  8. angular.module('flow.provider', [])
  9. .provider('flowFactory', function() {
  10. 'use strict';
  11. /**
  12. * Define the default properties for flow.js
  13. * @name flowFactoryProvider.defaults
  14. * @type {Object}
  15. */
  16. this.defaults = {};
  17. /**
  18. * Flow, MaybeFlow or NotFlow
  19. * @name flowFactoryProvider.factory
  20. * @type {function}
  21. * @return {Flow}
  22. */
  23. this.factory = function (options) {
  24. return new Flow(options);
  25. };
  26. /**
  27. * Define the default events
  28. * @name flowFactoryProvider.events
  29. * @type {Array}
  30. * @private
  31. */
  32. this.events = [];
  33. /**
  34. * Add default events
  35. * @name flowFactoryProvider.on
  36. * @function
  37. * @param {string} event
  38. * @param {Function} callback
  39. */
  40. this.on = function (event, callback) {
  41. this.events.push([event, callback]);
  42. };
  43. this.$get = function() {
  44. var fn = this.factory;
  45. var defaults = this.defaults;
  46. var events = this.events;
  47. return {
  48. 'create': function(opts) {
  49. // combine default options with global options and options
  50. var flow = fn(angular.extend({}, defaults, opts));
  51. angular.forEach(events, function (event) {
  52. flow.on(event[0], event[1]);
  53. });
  54. return flow;
  55. }
  56. };
  57. };
  58. });