-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtext-gradient-default.js
64 lines (57 loc) · 1.88 KB
/
text-gradient-default.js
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
/* @module TextGradientDefault
* text-gradient v0.2.0
*/
(function(factory) {
'use strict';
if (typeof exports === 'object') {
module.exports = factory();
} else {
window.TextGradientDefault = factory();
}
}(function factory() {
'use strict';
return {
__wrapperElement: null,
/* Initialize.
* @override, private, abstract
*/
_init: function _init() {
this.__wrapperElement = document.createElement('span');
this._include(this.__wrapperElement.style, {
display: 'inline-block',
color: this.options.fallbackColor || this.options.to,
background: '-webkit-linear-gradient(' + this.options.direction + ', ' + this.options.to + ',' + this.options.from + ')',
webkitBackgroundClip: 'text',
webkitTextFillColor: 'transparent'
});
this.updateText(this.options.text);
this.element.appendChild(this.__wrapperElement);
},
/* Implementation to update the text contents of this.element keeping the gradient intact.
* @override, public, abstract
*/
updateText: function updateText(text) {
if (this._destroyed === true) {
return console.warn('TextGradient: calling on destroyed object');
}
this.__wrapperElement.textContent = this.options.text = text;
},
/* Implementation to remove the gradient and created elements.
* @method destroy <public, abstract> [Function]
*/
destroy: function destroy() {
if (this._destroyed === true) {
return console.warn('TextGradient: calling on destroyed object');
}
while(this.element.childNodes.length > 0) {
this.element.removeChild(this.element.childNodes[0]);
}
this.element.textContent = this.options.text;
this.element = null;
this.options = null;
this.__wrapperElement = null;
this._destroyed = true;
return null;
}
};
}));