mofron-comp-text
Advanced tools
Comparing version 0.4.0 to 0.4.1
100
index.js
@@ -5,2 +5,3 @@ /** | ||
*/ | ||
require("mofron-event-click"); | ||
@@ -15,8 +16,8 @@ /** | ||
* | ||
* @param prm_opt : (string) text contents | ||
* @param prm_opt : (object) component option | ||
* @param prm : (string) text contents | ||
* @param opt : (object) component option | ||
*/ | ||
constructor (prm_opt) { | ||
constructor (prm, opt) { | ||
try { | ||
super(); | ||
super(prm); | ||
this.name('Text'); | ||
@@ -27,9 +28,7 @@ | ||
this.m_text = null; | ||
this.m_link = new Array( | ||
null, /* url */ | ||
null /* new tab flag */ | ||
); | ||
/* set prameter / option */ | ||
this.prmOpt(prm_opt); | ||
/* set option */ | ||
if (null !== opt) { | ||
this.option(opt); | ||
} | ||
} catch (e) { | ||
@@ -48,24 +47,16 @@ console.error(e.stack); | ||
try { | ||
/* init vdom contents */ | ||
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'); | ||
} | ||
if ('string' != (typeof prm)) { | ||
throw new Error('invalid parameter'); | ||
} | ||
this.vdom().addChild(conts); | ||
this.target(conts); | ||
/* set text contents */ | ||
if (null === this.text()) { | ||
this.text(prm); | ||
} else { | ||
this.text(this.text()); | ||
/* init vdom contents */ | ||
var text = new mofron.util.Dom('div', this); | ||
this.vdom().addChild(text); | ||
this.target(text); | ||
var txt_conts = this.text(); | ||
if (null === txt_conts) { | ||
txt_conts = prm; | ||
} | ||
text.text(txt_conts); | ||
@@ -91,15 +82,14 @@ /* set font theme */ | ||
try { | ||
if (undefined === val) { | ||
/* getter */ | ||
var _val = (val === undefined) ? null : val; | ||
if (null === _val) { | ||
return this.m_text; | ||
} | ||
/* setter */ | ||
if ('string' !== (typeof val)) { | ||
if ('string' !== (typeof _val)) { | ||
throw new Error('invalid parameter'); | ||
} | ||
if (null === this.vdom()) { | ||
if (false === this.isRendered()) { | ||
this.m_text = val; | ||
} else { | ||
this.target().text(val); | ||
return; | ||
} | ||
this.target().text(_val); | ||
} catch (e) { | ||
@@ -140,21 +130,24 @@ console.error(e.stack); | ||
/** | ||
* link url setter / getter | ||
* set link text | ||
* | ||
* @param url : (string) link url | ||
* @param tab : (bool) new tab flag | ||
* @return (object) [0] -> (string) url, [1] -> (boolean) new tab flag | ||
*/ | ||
link (url, tab) { | ||
setLink (url, tab) { | ||
try { | ||
if (undefined === url) { | ||
/* getter */ | ||
return this.m_link; | ||
} | ||
/* setter */ | ||
var _tab = (tab === undefined) ? false : tab; | ||
if (('string' !== typeof url) || ('boolean' !== typeof _tab)) { | ||
throw new Error('invalid parameter'); | ||
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'); | ||
}); | ||
} | ||
this.m_link[0] = url; | ||
this.m_link[1] = _tab; | ||
this.style('cursor', 'pointer'); | ||
this.addEvent(click); | ||
} catch (e) { | ||
@@ -174,11 +167,10 @@ console.error(e.stack); | ||
try { | ||
if (undefined === clr) { | ||
/* getter */ | ||
var _clr = (clr === undefined) ? null : clr; | ||
if (null === _clr) { | ||
return mofron.func.getColorObj(this.style('color')); | ||
} | ||
/* setter */ | ||
if ('object' !== (typeof clr)) { | ||
if ('object' !== (typeof _clr)) { | ||
throw new Error('invalid parameter'); | ||
} | ||
this.style('color', clr.getStyle()); | ||
this.style('color', _clr.getStyle()); | ||
} catch (e) { | ||
@@ -227,3 +219,3 @@ console.error(e.stack); | ||
this.m_font = _fnt; | ||
this.target().addClass(fnt.getThemeClass()); | ||
this.target().className(fnt.getThemeClass()); | ||
} catch (e) { | ||
@@ -230,0 +222,0 @@ console.error(e.stack); |
{ | ||
"name": "mofron-comp-text", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "text component for mofron", | ||
@@ -24,3 +24,5 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://github.com/simpart/mofron-comp-text#readme" | ||
"homepage": "https://github.com/simpart/mofron-comp-text#readme", | ||
"devDependencies": { | ||
} | ||
} |
8732
202