-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
102 lines (96 loc) · 2.48 KB
/
index.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
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
101
102
/**
* @file mofron-event-link/index.js
* @brief enable link to target component
* ## event function parameter
* - component: event target component object
* - event: "click" event object by addEventListener
* - mixed: user specified parameter
* @license MIT
*/
const Click = require('mofron-event-click');
module.exports = class extends Click {
/**
* initialize event
*
* @param (mixed) url parameter
* key-value: event config
* @param (boolean) newtab parameter
* @short url,newtab
* @type private
*/
constructor (p1, p2) {
try {
super();
this.modname("Link");
this.shortForm("url", "newtab");
this.confmng().add("url", { type: "string", init: "./" });
this.confmng().add("newtab", { type: "boolean", init: false });
if (0 < arguments.length) {
this.config(p1, p2);
}
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* event contents
* set url jump event to click handler
*
* @type private
*/
contents (tgt_dom) {
try {
super.contents(tgt_dom);
let link = this;
this.listener(
() => {
try {
if (true === link.newtab()) {
window.open(link.url(), '_blank');
} else {
window.location.href = link.url();
}
} catch (e) {
console.error(e.stack);
throw e;
}
},
this
);
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* jump url
*
* @param (string) jump url (default is './')
* @type parameter
*/
url (prm) {
try {
return this.confmng("url", prm);
} catch (e) {
console.error(e.stack);
throw e;
}
}
/**
* newtab flag
*
* @param (boolean) true: jump to url by newtab (default)
* false: jump to url by current tab
* @type parameter
*/
newtab (prm) {
try {
return this.confmng("newtab",prm);
} catch (e) {
console.error(e.stack);
throw e;
}
}
}
/* end of file */