mofron-comp-text
Advanced tools
Comparing version 0.3.12 to 0.4.0
58
index.js
@@ -5,3 +5,2 @@ /** | ||
*/ | ||
require("mofron-event-click"); | ||
@@ -27,2 +26,6 @@ /** | ||
this.m_text = null; | ||
this.m_link = new Array( | ||
null, /* url */ | ||
null /* new tab flag */ | ||
); | ||
@@ -45,5 +48,16 @@ /* set prameter / option */ | ||
/* init vdom contents */ | ||
var text = new mofron.util.Dom('div', this); | ||
this.vdom().addChild(text); | ||
this.target(text); | ||
var conts = null; | ||
var link = this.link(); | ||
if (null === link[0]) { | ||
conts = new mofron.util.Dom('div', this); | ||
} else { | ||
conts = new mofron.util.Dom('a', this); | ||
conts.attr('href', link[0]); | ||
if (true === link[1]) { | ||
conts.attr('target', '_blank'); | ||
} | ||
} | ||
this.vdom().addChild(conts); | ||
this.target(conts); | ||
@@ -124,24 +138,21 @@ /* set text contents */ | ||
/** | ||
* set link text | ||
* link url setter / getter | ||
* | ||
* @param url : (string) link url | ||
* @param tab : (bool) new tab flag | ||
* @return (object) [0] -> (string) url, [1] -> (boolean) new tab flag | ||
*/ | ||
setLink (url, tab) { | ||
link (url, tab) { | ||
try { | ||
if (undefined === url) { | ||
/* getter */ | ||
return this.m_link; | ||
} | ||
/* setter */ | ||
var _tab = (tab === undefined) ? false : tab; | ||
var click = null; | ||
if (false === _tab) { | ||
click = new mofron.event.Click(function(){ | ||
window.location.href = url; | ||
}); | ||
} else { | ||
click = new mofron.event.Click(function(){ | ||
window.open(url, '_blank'); | ||
}); | ||
if (('string' !== typeof url) || ('boolean' !== typeof _tab)) { | ||
throw new Error('invalid parameter'); | ||
} | ||
this.style('cursor', 'pointer'); | ||
this.addEvent(click); | ||
this.m_link[0] = url; | ||
this.m_link[1] = _tab; | ||
} catch (e) { | ||
@@ -161,10 +172,11 @@ console.error(e.stack); | ||
try { | ||
var _clr = (clr === undefined) ? null : clr; | ||
if (null === _clr) { | ||
if (undefined === clr) { | ||
/* getter */ | ||
return mofron.func.getColorObj(this.style('color')); | ||
} | ||
if ('object' !== (typeof _clr)) { | ||
/* setter */ | ||
if ('object' !== (typeof clr)) { | ||
throw new Error('invalid parameter'); | ||
} | ||
this.style('color', _clr.getStyle()); | ||
this.style('color', clr.getStyle()); | ||
} catch (e) { | ||
@@ -171,0 +183,0 @@ console.error(e.stack); |
{ | ||
"name": "mofron-comp-text", | ||
"version": "0.3.12", | ||
"version": "0.4.0", | ||
"description": "text component for mofron", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
9032
212