Minor fixes
This commit is contained in:
parent
bd113dd46e
commit
2fd5f293f0
File diff suppressed because one or more lines are too long
|
@ -2,7 +2,7 @@
|
|||
* @license MIT
|
||||
* @fileOverview Favico animations
|
||||
* @author Miroslav Magda, http://blog.ejci.net
|
||||
* @version 0.3.4
|
||||
* @version 0.3.5
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -34,13 +34,14 @@
|
|||
animation : 'slide',
|
||||
elementId : false
|
||||
};
|
||||
var _opt, _orig, _h, _w, _canvas, _context, _img, _ready, _lastBadge, _running, _readyCb, _stop, _browser;
|
||||
var _opt, _orig, _h, _w, _canvas, _context, _img, _ready, _lastBadge, _running, _readyCb, _stop, _browser, _animTimeout, _drawTimeout;
|
||||
|
||||
_browser = {};
|
||||
_browser.ff = (/firefox/i.test(navigator.userAgent.toLowerCase()));
|
||||
_browser.chrome = (/chrome/i.test(navigator.userAgent.toLowerCase()));
|
||||
_browser.opera = (/opera/i.test(navigator.userAgent.toLowerCase()));
|
||||
_browser.ie = (/msie/i.test(navigator.userAgent.toLowerCase())) || (/trident/i.test(navigator.userAgent.toLowerCase()));
|
||||
_browser.ff = typeof InstallTrigger != 'undefined';
|
||||
_browser.chrome = !!window.chrome;
|
||||
_browser.opera = !!window.opera || navigator.userAgent.indexOf('Opera') >= 0;
|
||||
_browser.ie = /*@cc_on!@*/false;
|
||||
_browser.safari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
|
||||
_browser.supported = (_browser.chrome || _browser.ff || _browser.opera);
|
||||
|
||||
var _queue = [];
|
||||
|
@ -136,6 +137,9 @@
|
|||
*/
|
||||
icon.reset = function() {
|
||||
//reset
|
||||
if (!_ready) {
|
||||
return;
|
||||
}
|
||||
_queue = [];
|
||||
_lastBadge = false;
|
||||
_context.clearRect(0, 0, _w, _h);
|
||||
|
@ -144,6 +148,8 @@
|
|||
link.setIcon(_canvas);
|
||||
//webcam('stop');
|
||||
//video('stop');
|
||||
window.clearTimeout(_animTimeout);
|
||||
window.clearTimeout(_drawTimeout);
|
||||
};
|
||||
/**
|
||||
* Start animation
|
||||
|
@ -164,16 +170,23 @@
|
|||
};
|
||||
if (_queue.length > 0) {
|
||||
_running = true;
|
||||
var run = function() {
|
||||
// apply options for this animation
|
||||
['type', 'animation', 'bgColor', 'textColor', 'fontFamily', 'fontStyle'].forEach(function(a) {
|
||||
if ( a in _queue[0].options) {
|
||||
_opt[a] = _queue[0].options[a];
|
||||
}
|
||||
});
|
||||
animation.run(_queue[0].options, function() {
|
||||
finished();
|
||||
}, false);
|
||||
};
|
||||
if (_lastBadge) {
|
||||
animation.run(_lastBadge.options, function() {
|
||||
animation.run(_queue[0].options, function() {
|
||||
finished();
|
||||
}, false);
|
||||
run();
|
||||
}, true);
|
||||
} else {
|
||||
animation.run(_queue[0].options, function() {
|
||||
finished();
|
||||
}, false);
|
||||
run();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -258,13 +271,13 @@
|
|||
_context.clearRect(0, 0, _w, _h);
|
||||
_context.drawImage(_img, 0, 0, _w, _h);
|
||||
_context.beginPath();
|
||||
_context.font = "bold " + Math.floor(opt.h * (opt.n > 99 ? 0.9 : 1)) + "px sans-serif";
|
||||
_context.font = _opt.fontStyle + " " + Math.floor(opt.h * (opt.n > 99 ? 0.9 : 1)) + "px " + _opt.fontFamily;
|
||||
_context.textAlign = 'center';
|
||||
_context.fillStyle = 'rgba(' + _opt.bgColor.r + ',' + _opt.bgColor.g + ',' + _opt.bgColor.b + ',' + opt.o + ')';
|
||||
_context.fillRect(opt.x, opt.y, opt.w, opt.h);
|
||||
_context.fillStyle = 'rgba(' + _opt.textColor.r + ',' + _opt.textColor.g + ',' + _opt.textColor.b + ',' + opt.o + ')';
|
||||
//_context.fillText((more) ? '9+' : opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15));
|
||||
if ((typeof opt.n)==='number' && opt.len > 3) {
|
||||
if (( typeof opt.n) === 'number' && opt.n > 999) {
|
||||
_context.fillText(((opt.n > 9999) ? 9 : Math.floor(opt.n / 1000) ) + 'k+', Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.2));
|
||||
} else {
|
||||
_context.fillText(opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15));
|
||||
|
@ -275,19 +288,36 @@
|
|||
/**
|
||||
* Set badge
|
||||
*/
|
||||
var badge = function(number, animType) {
|
||||
var badge = function(number, opts) {
|
||||
opts = (( typeof opts) === 'string' ? {
|
||||
animation : opts
|
||||
} : opts) || {};
|
||||
_readyCb = function() {
|
||||
try {
|
||||
if ( typeof (number) === 'number' ? (number > 0) : (number !== '')) {
|
||||
if (animation.types['' + animType]) {
|
||||
_opt.animation = animType;
|
||||
}
|
||||
_queue.push({
|
||||
var q = {
|
||||
type : 'badge',
|
||||
options : {
|
||||
n : number
|
||||
}
|
||||
};
|
||||
if ('animation' in opts && animation.types['' + opts.animation]) {
|
||||
q.options.animation = '' + opts.animation;
|
||||
}
|
||||
if ('type' in opts && type['' + opts.type]) {
|
||||
q.options.type = '' + opts.type;
|
||||
}
|
||||
['bgColor', 'textColor'].forEach(function(o) {
|
||||
if ( o in opts) {
|
||||
q.options[o] = hexToRgb(opts[o]);
|
||||
}
|
||||
});
|
||||
['fontStyle', 'fontFamily'].forEach(function(o) {
|
||||
if ( o in opts) {
|
||||
q.options[o] = opts[o];
|
||||
}
|
||||
});
|
||||
_queue.push(q);
|
||||
if (_queue.length > 100) {
|
||||
throw 'Too many badges requests in queue.';
|
||||
}
|
||||
|
@ -414,7 +444,7 @@
|
|||
} catch(e) {
|
||||
|
||||
}
|
||||
setTimeout(drawVideo, animation.duration, video);
|
||||
_drawTimeout = setTimeout(drawVideo, animation.duration, video);
|
||||
link.setIcon(_canvas);
|
||||
}
|
||||
|
||||
|
@ -429,7 +459,7 @@
|
|||
var getLink = function() {
|
||||
var link = document.getElementsByTagName('head')[0].getElementsByTagName('link');
|
||||
for (var l = link.length, i = (l - 1); i >= 0; i--) {
|
||||
if ((/icon/i).test(link[i].getAttribute('rel'))) {
|
||||
if ((/(^|\s)icon(\s|$)/i).test(link[i].getAttribute('rel'))) {
|
||||
return link[i];
|
||||
}
|
||||
}
|
||||
|
@ -450,7 +480,7 @@
|
|||
}
|
||||
//check if image and link url is on same domain. if not raise error
|
||||
url = (_opt.elementId) ? elm.src : elm.href;
|
||||
if (url.indexOf(document.location.hostname) === -1) {
|
||||
if (url.substr(0, 5) !== 'data:' && url.indexOf(document.location.hostname) === -1) {
|
||||
throw new Error('Error setting favicon. Favicon image is on different domain (Icon: ' + url + ', Domain: ' + document.location.hostname + ')');
|
||||
}
|
||||
elm.setAttribute('type', 'image/png');
|
||||
|
@ -762,7 +792,7 @@
|
|||
};
|
||||
if ((step < animationType.length) && (step >= 0)) {
|
||||
type[_opt.type](merge(opt, animationType[step]));
|
||||
setTimeout(function() {
|
||||
_animTimeout = setTimeout(function() {
|
||||
if (revert) {
|
||||
step = step - 1;
|
||||
} else {
|
||||
|
@ -784,7 +814,10 @@
|
|||
video : video,
|
||||
image : image,
|
||||
webcam : webcam,
|
||||
reset : icon.reset
|
||||
reset : icon.reset,
|
||||
browser : {
|
||||
supported : _browser.supported
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -487,17 +487,17 @@ $(function() {
|
|||
}
|
||||
favico.badge("!");
|
||||
if (settings.badge && Notification.permission == "granted") {
|
||||
var n = new Notification(msg.from + " says:", {
|
||||
var notify = new Notification(msg.from + " says:", {
|
||||
body: msg.text.trim(),
|
||||
icon: "/img/logo-64.png"
|
||||
});
|
||||
n.onclick = function() {
|
||||
notify.onclick = function() {
|
||||
window.focus();
|
||||
button.click();
|
||||
this.close();
|
||||
};
|
||||
window.setTimeout(function() {
|
||||
n.close();
|
||||
notify.close();
|
||||
}, 5 * 1000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@ templates['chan'] = template({"1":function(depth0,helpers,partials,data) {
|
|||
+ escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
|
||||
+ "\" class=\"chan "
|
||||
+ escapeExpression(((helper = (helper = helpers.type || (depth0 != null ? depth0.type : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"type","hash":{},"data":data}) : helper)))
|
||||
+ "\">\n <span class=\"badge\">";
|
||||
+ "\">\n <span class=\"badge\" data-count=\""
|
||||
+ escapeExpression(((helper = (helper = helpers.unread || (depth0 != null ? depth0.unread : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"unread","hash":{},"data":data}) : helper)))
|
||||
+ "\">";
|
||||
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.unread : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
|
||||
if (stack1 != null) { buffer += stack1; }
|
||||
return buffer + "</span>\n <span class=\"close\"></span>\n "
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{#each channels}}
|
||||
<button data-id="{{id}}" data-target="#chan-{{id}}" data-title="{{name}}" class="chan {{type}}">
|
||||
<span class="badge">{{#if unread}}{{unread}}{{/if}}</span>
|
||||
<span class="badge" data-count="{{unread}}">{{#if unread}}{{unread}}{{/if}}</span>
|
||||
<span class="close"></span>
|
||||
{{name}}
|
||||
</button>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "shout",
|
||||
"description": "A web IRC client",
|
||||
"version": "0.32.1",
|
||||
"version": "0.32.2",
|
||||
"author": "Mattias Erming",
|
||||
"preferGlobal": true,
|
||||
"bin": {
|
||||
|
|
Loading…
Reference in New Issue