Skip to content

Instantly share code, notes, and snippets.

@twocity
Created September 18, 2014 09:09
Show Gist options
  • Select an option

  • Save twocity/fba1e06867c9d54e1bc4 to your computer and use it in GitHub Desktop.

Select an option

Save twocity/fba1e06867c9d54e1bc4 to your computer and use it in GitHub Desktop.
var s2t = function(str) {
var _str = '';
var po;
for(var i=0; i < str.length; i++) {
if((po = sMap.indexOf(str.charAt(i))) != -1)
_str += tMap.charAt(po);
else
_str += str.charAt(i);
}
return _str;
}
var $ = function(name) {
if (name.substr(0, 1) == '#') {
return document.getElementById(name.substr(1));
} else if (name.substr(0, 1) == '.') {
return document.getElementsByClassName(name.substr(1));
} else {
return document.getElementsByTagName(name);
}
}
function hack(type,objec) {
var ua = navigator.userAgent;
if (type == 'shadow' && ua.indexOf('Android 4.3') > 0) {
$('#dish').className='';
}
}
function addClass(theClass) {
if (this.length) {
for (i = 0; i < this.length; i++) {
this[i].addClass(theClass);
}
return;
}
if (this.className != '') {
this.className += ' ' + theClass;
} else {
this.className = theClass;
}
}
Object.prototype.addClass = addClass;
function removeClass(theClass) {
if (this.length) {
for (i = 0; i < this.length; i++) {
this[i].removeClass(theClass);
}
return;
}
var oldClass = this.className;
if (!oldClass) return;
var regExp = new RegExp('\\s?'+theClass+'\\b');
if (oldClass.indexOf(theClass) != -1) {
this.className = oldClass.replace(regExp,'');
}
}
Object.prototype.removeClass = removeClass;
var cleanForShot = function() {
$('a').removeClass('focus');
$('a').removeClass('autofocus');
if ($('#poi').innerHTML.length <= 0
|| $('#poi').innerHTML.indexOf('选择用餐地点') != -1
|| $('#poi').innerHTML.indexOf('選擇用餐地點') != -1) {
$('#poi').style.display = 'none';
}
if ($('#dish').innerHTML.length <= 0
|| $('#dish').innerHTML.indexOf('添加美食名称') != -1
|| $('#dish').innerHTML.indexOf('添加美食名稱') != -1) {
$('#dish').style.display = 'none';
}
if ($('#comment').innerHTML.length <= 0
|| $('#comment').innerHTML.indexOf('对美食的评价') != -1
|| $('#comment').innerHTML.indexOf('對美食的評價') != -1) {
$('#comment').style.display = 'none';
}
}
var autoFlash = function() {
$('a').addClass('autofocus');
setTimeout(function () {
$('a').removeClass('autofocus');
}, 500);
}
var focusLabel = function(id) {
$('a').removeClass('focus');
var $item = $('#' + id);
$item.addClass('focus');
//shiftY($item);
}
var shiftY = function($item) {
var offsetTop = $item.offsetTop + $item.offsetParent.offsetTop;
call('focus', offsetTop < 150 ?
Math.max(offsetTop - 30, 0) :
Math.min(320, offsetTop + $item.offsetHeight + 30));
}
var setLabel = function(id, value) {
$('a').removeClass('focus');
var $item = $('#' + id);
value = value.replace(/\(([^()]*)\)/g, "($1)");
$item.innerHTML = trans ? s2t(value) : value;
//shiftY($item);
if (id == 'comment' && (!value || !value.length)) {
$item.innerHTML = trans ? s2t('对美食的评价') : '对美食的评价';
}
}
var call = function(action, value) {
//console.log(action, value);
document.location = 'matcha-wm-action://' + action + '/' + value;
}
$('#wm').onclick = function () {
call('blur', 'bg');
return false;
};
$('#dish').onclick = function (e) {
call('click', 'dish');
e.stopPropagation();
};
$('#poi').onclick = function (e) {
call('click', 'poi');
e.stopPropagation();
};
$('#comment').onclick = function (e) {
call('click', 'comment');
e.stopPropagation();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment