Dev: EntryBtn refactoring

This commit is contained in:
surunzi
2016-05-16 01:07:02 +08:00
parent b08f757d83
commit 6fb69e51ec
5 changed files with 99 additions and 66 deletions

6
eustia/pxToNum.js Normal file
View File

@@ -0,0 +1,6 @@
_('toNum');
function exports(str)
{
return toNum(str.replace('px', ''));
}

View File

@@ -50,10 +50,7 @@ export default class Highlight
var computedStyle = getComputedStyle(this._target, '');
function getNumStyle(name)
{
return pxToNum(computedStyle.getPropertyValue(name));
}
var getNumStyle = name => util.pxToNum(computedStyle.getPropertyValue(name));
var ml = getNumStyle('margin-left'),
mr = getNumStyle('margin-right'),
@@ -112,8 +109,3 @@ export default class Highlight
this._$content = this._$el.find('.eruda-content');
}
}
function pxToNum(str)
{
return util.toNum(str.replace('px', ''));
}

View File

@@ -4,13 +4,13 @@ import config from '../lib/config.es6'
require('./EntryBtn.scss');
export default class HomeBtn extends util.Emitter
export default class EntryBtn extends util.Emitter
{
constructor($parent)
{
super();
this._$parent = $parent;
this._$parent = $parent;
this._appendTpl();
this._makeDraggable();
this._initConfig();
@@ -22,7 +22,6 @@ export default class HomeBtn extends util.Emitter
var $parent = this._$parent;
$parent.append(require('./EntryBtn.hbs')());
this._$el = $parent.find('.eruda-home-btn');
}
_setPos(orientationChanged)
@@ -35,10 +34,7 @@ export default class HomeBtn extends util.Emitter
if (outOfRange ||
!cfg.get('rememberPos') ||
orientationChanged)
{
pos = defPost;
}
orientationChanged) pos = defPost;
this._$el.css({
left: pos.x,
@@ -62,8 +58,8 @@ export default class HomeBtn extends util.Emitter
if (cfg.get('rememberPos'))
{
cfg.set('pos', {
x: util.toNum(this._$el.css('left').replace('px', '')),
y: util.toNum(this._$el.css('top').replace('px', ''))
x: util.pxToNum(this._$el.css('left')),
y: util.pxToNum(this._$el.css('top'))
});
}
@@ -74,9 +70,7 @@ export default class HomeBtn extends util.Emitter
}
_makeDraggable()
{
this._draggabilly = new Draggabilly(this._$el.get(0), {
containment: true
});
this._draggabilly = new Draggabilly(this._$el.get(0), {containment: true});
}
_initConfig()
{
@@ -89,13 +83,10 @@ export default class HomeBtn extends util.Emitter
}
};
function getDefPos()
var getDefPos = () =>
{
var wh = window.innerHeight,
ww = window.innerWidth;
return {
x: ww - 50,
y: wh - 50
x: window.innerWidth - 50,
y: window.innerHeight - 50
};
};
}

View File

@@ -11,10 +11,6 @@
font-size: 25px;
text-align: center;
line-height: 40px;
span {
position: relative;
top: 1px;
}
&.active, &:active {
opacity: .8;
}

View File

@@ -1367,6 +1367,42 @@ module.exports = (function ()
* |methods|object |Public methods |
* |statics|object |Static methods |
* |return |function|Function used to create instances|
*
* ```javascript
* var People = Class({
* initialize: function (name, age)
* {
* this.name = name;
* this.age = age;
* },
* introduce: function ()
* {
* return 'I am ' + this.name + ', ' + this.age + ' years old.'.
* }
* });
*
* var Student = People.extend({
* initialize: function (name, age, school)
* {
* this.callSuper('initialize', name, age);
*
* this.school = school.
* },
* introduce: function ()
* {
* return this.callSuper('introduce') + '\n I study at ' + this.school + '.'.
* }
* }, {
* is: function (obj)
* {
* return obj instanceof Student;
* }
* });
*
* var a = new Student('allen', 17, 'Hogwarts');
* a.introduce(); // -> 'I am allen, 17 years old. \n I study at Hogwarts.'
* Student.is(a); // -> true
* ```
*/
var regCallSuper = /callSuper/;
@@ -2345,6 +2381,52 @@ module.exports = (function ()
return exports;
})({});
/* ------------------------------ toNum ------------------------------ */
var toNum = _.toNum = (function (exports)
{
/* Convert value to a number.
*
* |Name |Type |Desc |
* |------------------------------|
* |val |* |Value to process|
* |return|number|Resulted number |
*
* ```javascript
* toNum('5'); // -> 5
* ```
*/
exports = function (val)
{
if (isNum(val)) return val;
if (isObj(val))
{
var temp = isFn(val.valueOf) ? val.valueOf() : val;
val = isObj(temp) ? (temp + '') : temp;
}
if (!isStr(val)) return val === 0 ? val : +val;
return +val;
};
return exports;
})({});
/* ------------------------------ pxToNum ------------------------------ */
var pxToNum = _.pxToNum = (function (exports)
{
function exports(str)
{
return toNum(str.replace('px', ''));
}
return exports;
})({});
/* ------------------------------ rtrim ------------------------------ */
var rtrim = _.rtrim = (function (exports)
@@ -2423,40 +2505,6 @@ module.exports = (function ()
return exports;
})({});
/* ------------------------------ toNum ------------------------------ */
var toNum = _.toNum = (function (exports)
{
/* Convert value to a number.
*
* |Name |Type |Desc |
* |------------------------------|
* |val |* |Value to process|
* |return|number|Resulted number |
*
* ```javascript
* toNum('5'); // -> 5
* ```
*/
exports = function (val)
{
if (isNum(val)) return val;
if (isObj(val))
{
var temp = isFn(val.valueOf) ? val.valueOf() : val;
val = isObj(temp) ? (temp + '') : temp;
}
if (!isStr(val)) return val === 0 ? val : +val;
return +val;
};
return exports;
})({});
/* ------------------------------ toStr ------------------------------ */
var toStr = _.toStr = (function (exports)