This repository was archived by the owner on Aug 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-base-controller.js
More file actions
100 lines (79 loc) · 2.97 KB
/
angular-base-controller.js
File metadata and controls
100 lines (79 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! BaseController.js
//! version : 0.0.0
//! authors : Ben Babics
//! license : MIT
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.BaseController = factory()
}(this, function () { 'use strict';
function BaseController() {
var args, fn, index, key, i, len, dependencies, members, collaborators;
args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
collaborators = [];
dependencies = this.constructor.$inject;
for (index = i = 0, len = dependencies.length; i < len; index = ++i) {
key = dependencies[index];
this[key] = collaborators[index] = args[index];
}
members = this.constructor.prototype;
for (key in members) {
fn = members[key];
if (typeof fn !== 'function') continue;
if ((key === 'constructor' || key === 'initialize') || key[0] === '_') continue;
fn = (function(context, fn) {
return function() {
return fn.apply(context, arguments);
};
})(this, fn);
this[key] = fn;
if (key.lastIndexOf('handle', 0) >= 0) {
this.$scope[key] = fn;
}
}
this.defineListeners.apply(this, collaborators);
this.initialize.apply(this, collaborators);
this.defineScope.apply(this, collaborators);
(function(context) {
context.$scope.$on('$destroy', function(evt) {
context.destroy(evt, context.$scope);
});
})(this);
}
BaseController.extend = function(protoProps) {
var parent = this,
collaborators = protoProps.inject || [];
delete protoProps.inject;
function child() {
child.__super__.constructor.apply(this, arguments);
}
for (var key in parent) {
if ({}.hasOwnProperty.call(parent, key)) {
child[key] = parent[key];
}
}
function Surrogate() {
this.constructor = child;
}
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate();
child.__super__ = parent.prototype;
for (var key in protoProps) {
if ({}.hasOwnProperty.call(protoProps, key)) {
child.prototype[key] = protoProps[key];
}
}
if (collaborators.indexOf('$scope') < 0) {
collaborators.unshift('$scope');
}
child.$inject = collaborators;
return child;
};
// Abstract Methods
BaseController.prototype.initialize = function() {};
BaseController.prototype.defineScope = function() {};
BaseController.prototype.defineListeners = function() {};
BaseController.prototype.destroy = function() {};
// Expose BaseController
return BaseController;
}));