| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
(function () { |
| 26 |
|
| 27 |
var Favico = (function (opt) { |
| 28 |
'use strict'; |
| 29 |
opt = (opt) ? opt : {}; |
| 30 |
var _def = { |
| 31 |
bgColor: '#d00', |
| 32 |
textColor: '#fff', |
| 33 |
fontFamily: 'sans-serif', |
| 34 |
fontStyle: 'bold', |
| 35 |
type: 'circle', |
| 36 |
position: 'down', |
| 37 |
animation: 'slide', |
| 38 |
elementId: false, |
| 39 |
dataUrl: false, |
| 40 |
win: window |
| 41 |
}; |
| 42 |
var _opt, _orig, _h, _w, _canvas, _context, _img, _ready, _lastBadge, _running, _readyCb, _stop, _browser, _animTimeout, _drawTimeout, _doc; |
| 43 |
|
| 44 |
_browser = {}; |
| 45 |
_browser.ff = typeof InstallTrigger != 'undefined'; |
| 46 |
_browser.chrome = !!window.chrome; |
| 47 |
_browser.opera = !!window.opera || navigator.userAgent.indexOf('Opera') >= 0; |
| 48 |
_browser.ie = false; |
| 49 |
_browser.safari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; |
| 50 |
_browser.supported = (_browser.chrome || _browser.ff || _browser.opera); |
| 51 |
|
| 52 |
var _queue = []; |
| 53 |
_readyCb = function () { |
| 54 |
}; |
| 55 |
_ready = _stop = false; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
var init = function () { |
| 60 |
|
| 61 |
_opt = merge(_def, opt); |
| 62 |
_opt.bgColor = hexToRgb(_opt.bgColor); |
| 63 |
_opt.textColor = hexToRgb(_opt.textColor); |
| 64 |
_opt.position = _opt.position.toLowerCase(); |
| 65 |
_opt.animation = (animation.types['' + _opt.animation]) ? _opt.animation : _def.animation; |
| 66 |
|
| 67 |
_doc = _opt.win.document; |
| 68 |
|
| 69 |
var isUp = _opt.position.indexOf('up') > -1; |
| 70 |
var isLeft = _opt.position.indexOf('left') > -1; |
| 71 |
|
| 72 |
|
| 73 |
if (isUp || isLeft) { |
| 74 |
for (var i = 0; i < animation.types['' + _opt.animation].length; i++) { |
| 75 |
var step = animation.types['' + _opt.animation][i]; |
| 76 |
|
| 77 |
if (isUp) { |
| 78 |
if (step.y < 0.6) { |
| 79 |
step.y = step.y - 0.4; |
| 80 |
} else { |
| 81 |
step.y = step.y - 2 * step.y + (1 - step.w); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
if (isLeft) { |
| 86 |
if (step.x < 0.6) { |
| 87 |
step.x = step.x - 0.4; |
| 88 |
} else { |
| 89 |
step.x = step.x - 2 * step.x + (1 - step.h); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
animation.types['' + _opt.animation][i] = step; |
| 94 |
} |
| 95 |
} |
| 96 |
_opt.type = (type['' + _opt.type]) ? _opt.type : _def.type; |
| 97 |
|
| 98 |
_orig = link.getIcon(); |
| 99 |
|
| 100 |
_canvas = document.createElement('canvas'); |
| 101 |
|
| 102 |
_img = document.createElement('img'); |
| 103 |
if (_orig.hasAttribute('href')) { |
| 104 |
_img.setAttribute('crossOrigin', 'anonymous'); |
| 105 |
|
| 106 |
_img.onload = function () { |
| 107 |
_h = (_img.height > 0) ? _img.height : 32; |
| 108 |
_w = (_img.width > 0) ? _img.width : 32; |
| 109 |
_canvas.height = _h; |
| 110 |
_canvas.width = _w; |
| 111 |
_context = _canvas.getContext('2d'); |
| 112 |
icon.ready(); |
| 113 |
}; |
| 114 |
_img.setAttribute('src', _orig.getAttribute('href')); |
| 115 |
} else { |
| 116 |
_img.onload = function () { |
| 117 |
_h = 32; |
| 118 |
_w = 32; |
| 119 |
_img.height = _h; |
| 120 |
_img.width = _w; |
| 121 |
_canvas.height = _h; |
| 122 |
_canvas.width = _w; |
| 123 |
_context = _canvas.getContext('2d'); |
| 124 |
icon.ready(); |
| 125 |
}; |
| 126 |
_img.setAttribute('src', ''); |
| 127 |
} |
| 128 |
|
| 129 |
}; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
var icon = {}; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
icon.ready = function () { |
| 138 |
_ready = true; |
| 139 |
icon.reset(); |
| 140 |
_readyCb(); |
| 141 |
}; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
icon.reset = function () { |
| 146 |
|
| 147 |
if (!_ready) { |
| 148 |
return; |
| 149 |
} |
| 150 |
_queue = []; |
| 151 |
_lastBadge = false; |
| 152 |
_running = false; |
| 153 |
_context.clearRect(0, 0, _w, _h); |
| 154 |
_context.drawImage(_img, 0, 0, _w, _h); |
| 155 |
|
| 156 |
link.setIcon(_canvas); |
| 157 |
|
| 158 |
|
| 159 |
window.clearTimeout(_animTimeout); |
| 160 |
window.clearTimeout(_drawTimeout); |
| 161 |
}; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
icon.start = function () { |
| 166 |
if (!_ready || _running) { |
| 167 |
return; |
| 168 |
} |
| 169 |
var finished = function () { |
| 170 |
_lastBadge = _queue[0]; |
| 171 |
_running = false; |
| 172 |
if (_queue.length > 0) { |
| 173 |
_queue.shift(); |
| 174 |
icon.start(); |
| 175 |
} else { |
| 176 |
|
| 177 |
} |
| 178 |
}; |
| 179 |
if (_queue.length > 0) { |
| 180 |
_running = true; |
| 181 |
var run = function () { |
| 182 |
|
| 183 |
['type', 'animation', 'bgColor', 'textColor', 'fontFamily', 'fontStyle'].forEach(function (a) { |
| 184 |
if (a in _queue[0].options) { |
| 185 |
_opt[a] = _queue[0].options[a]; |
| 186 |
} |
| 187 |
}); |
| 188 |
animation.run(_queue[0].options, function () { |
| 189 |
finished(); |
| 190 |
}, false); |
| 191 |
}; |
| 192 |
if (_lastBadge) { |
| 193 |
animation.run(_lastBadge.options, function () { |
| 194 |
run(); |
| 195 |
}, true); |
| 196 |
} else { |
| 197 |
run(); |
| 198 |
} |
| 199 |
} |
| 200 |
}; |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
var type = {}; |
| 206 |
var options = function (opt) { |
| 207 |
opt.n = ((typeof opt.n) === 'number') ? Math.abs(opt.n | 0) : opt.n; |
| 208 |
opt.x = _w * opt.x; |
| 209 |
opt.y = _h * opt.y; |
| 210 |
opt.w = _w * opt.w; |
| 211 |
opt.h = _h * opt.h; |
| 212 |
opt.len = ("" + opt.n).length; |
| 213 |
return opt; |
| 214 |
}; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
type.circle = function (opt) { |
| 220 |
opt = options(opt); |
| 221 |
var more = false; |
| 222 |
if (opt.len === 2) { |
| 223 |
opt.x = opt.x - opt.w * 0.4; |
| 224 |
opt.w = opt.w * 1.4; |
| 225 |
more = true; |
| 226 |
} else if (opt.len >= 3) { |
| 227 |
opt.x = opt.x - opt.w * 0.65; |
| 228 |
opt.w = opt.w * 1.65; |
| 229 |
more = true; |
| 230 |
} |
| 231 |
_context.clearRect(0, 0, _w, _h); |
| 232 |
_context.drawImage(_img, 0, 0, _w, _h); |
| 233 |
_context.beginPath(); |
| 234 |
_context.font = _opt.fontStyle + " " + Math.floor(opt.h * (opt.n > 99 ? 0.85 : 1)) + "px " + _opt.fontFamily; |
| 235 |
_context.textAlign = 'center'; |
| 236 |
if (more) { |
| 237 |
_context.moveTo(opt.x + opt.w / 2, opt.y); |
| 238 |
_context.lineTo(opt.x + opt.w - opt.h / 2, opt.y); |
| 239 |
_context.quadraticCurveTo(opt.x + opt.w, opt.y, opt.x + opt.w, opt.y + opt.h / 2); |
| 240 |
_context.lineTo(opt.x + opt.w, opt.y + opt.h - opt.h / 2); |
| 241 |
_context.quadraticCurveTo(opt.x + opt.w, opt.y + opt.h, opt.x + opt.w - opt.h / 2, opt.y + opt.h); |
| 242 |
_context.lineTo(opt.x + opt.h / 2, opt.y + opt.h); |
| 243 |
_context.quadraticCurveTo(opt.x, opt.y + opt.h, opt.x, opt.y + opt.h - opt.h / 2); |
| 244 |
_context.lineTo(opt.x, opt.y + opt.h / 2); |
| 245 |
_context.quadraticCurveTo(opt.x, opt.y, opt.x + opt.h / 2, opt.y); |
| 246 |
} else { |
| 247 |
_context.arc(opt.x + opt.w / 2, opt.y + opt.h / 2, opt.h / 2, 0, 2 * Math.PI); |
| 248 |
} |
| 249 |
_context.fillStyle = 'rgba(' + _opt.bgColor.r + ',' + _opt.bgColor.g + ',' + _opt.bgColor.b + ',' + opt.o + ')'; |
| 250 |
_context.fill(); |
| 251 |
_context.closePath(); |
| 252 |
_context.beginPath(); |
| 253 |
_context.stroke(); |
| 254 |
_context.fillStyle = 'rgba(' + _opt.textColor.r + ',' + _opt.textColor.g + ',' + _opt.textColor.b + ',' + opt.o + ')'; |
| 255 |
|
| 256 |
if ((typeof opt.n) === 'number' && opt.n > 999) { |
| 257 |
_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)); |
| 258 |
} else { |
| 259 |
_context.fillText(opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15)); |
| 260 |
} |
| 261 |
_context.closePath(); |
| 262 |
}; |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
type.rectangle = function (opt) { |
| 268 |
opt = options(opt); |
| 269 |
var more = false; |
| 270 |
if (opt.len === 2) { |
| 271 |
opt.x = opt.x - opt.w * 0.4; |
| 272 |
opt.w = opt.w * 1.4; |
| 273 |
more = true; |
| 274 |
} else if (opt.len >= 3) { |
| 275 |
opt.x = opt.x - opt.w * 0.65; |
| 276 |
opt.w = opt.w * 1.65; |
| 277 |
more = true; |
| 278 |
} |
| 279 |
_context.clearRect(0, 0, _w, _h); |
| 280 |
_context.drawImage(_img, 0, 0, _w, _h); |
| 281 |
_context.beginPath(); |
| 282 |
_context.font = _opt.fontStyle + " " + Math.floor(opt.h * (opt.n > 99 ? 0.9 : 1)) + "px " + _opt.fontFamily; |
| 283 |
_context.textAlign = 'center'; |
| 284 |
_context.fillStyle = 'rgba(' + _opt.bgColor.r + ',' + _opt.bgColor.g + ',' + _opt.bgColor.b + ',' + opt.o + ')'; |
| 285 |
_context.fillRect(opt.x, opt.y, opt.w, opt.h); |
| 286 |
_context.fillStyle = 'rgba(' + _opt.textColor.r + ',' + _opt.textColor.g + ',' + _opt.textColor.b + ',' + opt.o + ')'; |
| 287 |
|
| 288 |
if ((typeof opt.n) === 'number' && opt.n > 999) { |
| 289 |
_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)); |
| 290 |
} else { |
| 291 |
_context.fillText(opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15)); |
| 292 |
} |
| 293 |
_context.closePath(); |
| 294 |
}; |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
var badge = function (number, opts) { |
| 300 |
opts = ((typeof opts) === 'string' ? { |
| 301 |
animation: opts |
| 302 |
} : opts) || {}; |
| 303 |
_readyCb = function () { |
| 304 |
try { |
| 305 |
if (typeof (number) === 'number' ? (number > 0) : (number !== '')) { |
| 306 |
var q = { |
| 307 |
type: 'badge', |
| 308 |
options: { |
| 309 |
n: number |
| 310 |
} |
| 311 |
}; |
| 312 |
if ('animation' in opts && animation.types['' + opts.animation]) { |
| 313 |
q.options.animation = '' + opts.animation; |
| 314 |
} |
| 315 |
if ('type' in opts && type['' + opts.type]) { |
| 316 |
q.options.type = '' + opts.type; |
| 317 |
} |
| 318 |
['bgColor', 'textColor'].forEach(function (o) { |
| 319 |
if (o in opts) { |
| 320 |
q.options[o] = hexToRgb(opts[o]); |
| 321 |
} |
| 322 |
}); |
| 323 |
['fontStyle', 'fontFamily'].forEach(function (o) { |
| 324 |
if (o in opts) { |
| 325 |
q.options[o] = opts[o]; |
| 326 |
} |
| 327 |
}); |
| 328 |
_queue.push(q); |
| 329 |
if (_queue.length > 100) { |
| 330 |
throw new Error('Too many badges requests in queue.'); |
| 331 |
} |
| 332 |
icon.start(); |
| 333 |
} else { |
| 334 |
icon.reset(); |
| 335 |
} |
| 336 |
} catch (e) { |
| 337 |
throw new Error('Error setting badge. Message: ' + e.message); |
| 338 |
} |
| 339 |
}; |
| 340 |
if (_ready) { |
| 341 |
_readyCb(); |
| 342 |
} |
| 343 |
}; |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
var image = function (imageElement) { |
| 349 |
_readyCb = function () { |
| 350 |
try { |
| 351 |
var w = imageElement.width; |
| 352 |
var h = imageElement.height; |
| 353 |
var newImg = document.createElement('img'); |
| 354 |
var ratio = (w / _w < h / _h) ? (w / _w) : (h / _h); |
| 355 |
newImg.setAttribute('crossOrigin', 'anonymous'); |
| 356 |
newImg.onload=function(){ |
| 357 |
_context.clearRect(0, 0, _w, _h); |
| 358 |
_context.drawImage(newImg, 0, 0, _w, _h); |
| 359 |
link.setIcon(_canvas); |
| 360 |
}; |
| 361 |
newImg.setAttribute('src', imageElement.getAttribute('src')); |
| 362 |
newImg.height = (h / ratio); |
| 363 |
newImg.width = (w / ratio); |
| 364 |
} catch (e) { |
| 365 |
throw new Error('Error setting image. Message: ' + e.message); |
| 366 |
} |
| 367 |
}; |
| 368 |
if (_ready) { |
| 369 |
_readyCb(); |
| 370 |
} |
| 371 |
}; |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
var video = function (videoElement) { |
| 376 |
_readyCb = function () { |
| 377 |
try { |
| 378 |
if (videoElement === 'stop') { |
| 379 |
_stop = true; |
| 380 |
icon.reset(); |
| 381 |
_stop = false; |
| 382 |
return; |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
videoElement.addEventListener('play', function () { |
| 388 |
drawVideo(this); |
| 389 |
}, false); |
| 390 |
|
| 391 |
} catch (e) { |
| 392 |
throw new Error('Error setting video. Message: ' + e.message); |
| 393 |
} |
| 394 |
}; |
| 395 |
if (_ready) { |
| 396 |
_readyCb(); |
| 397 |
} |
| 398 |
}; |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
var webcam = function (action) { |
| 403 |
|
| 404 |
if (!window.URL || !window.URL.createObjectURL) { |
| 405 |
window.URL = window.URL || {}; |
| 406 |
window.URL.createObjectURL = function (obj) { |
| 407 |
return obj; |
| 408 |
}; |
| 409 |
} |
| 410 |
if (_browser.supported) { |
| 411 |
var newVideo = false; |
| 412 |
navigator.getUserMedia = navigator.getUserMedia || navigator.oGetUserMedia || navigator.msGetUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia; |
| 413 |
_readyCb = function () { |
| 414 |
try { |
| 415 |
if (action === 'stop') { |
| 416 |
_stop = true; |
| 417 |
icon.reset(); |
| 418 |
_stop = false; |
| 419 |
return; |
| 420 |
} |
| 421 |
newVideo = document.createElement('video'); |
| 422 |
newVideo.width = _w; |
| 423 |
newVideo.height = _h; |
| 424 |
navigator.getUserMedia({ |
| 425 |
video: true, |
| 426 |
audio: false |
| 427 |
}, function (stream) { |
| 428 |
newVideo.src = URL.createObjectURL(stream); |
| 429 |
newVideo.play(); |
| 430 |
drawVideo(newVideo); |
| 431 |
}, function () { |
| 432 |
}); |
| 433 |
} catch (e) { |
| 434 |
throw new Error('Error setting webcam. Message: ' + e.message); |
| 435 |
} |
| 436 |
}; |
| 437 |
if (_ready) { |
| 438 |
_readyCb(); |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
}; |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
function drawVideo(video) { |
| 448 |
if (video.paused || video.ended || _stop) { |
| 449 |
return false; |
| 450 |
} |
| 451 |
) |
| 452 |
try { |
| 453 |
_context.clearRect(0, 0, _w, _h); |
| 454 |
_context.drawImage(video, 0, 0, _w, _h); |
| 455 |
} catch (e) { |
| 456 |
|
| 457 |
} |
| 458 |
_drawTimeout = setTimeout(function () { |
| 459 |
drawVideo(video); |
| 460 |
}, animation.duration); |
| 461 |
link.setIcon(_canvas); |
| 462 |
} |
| 463 |
|
| 464 |
var link = {}; |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
link.getIcon = function () { |
| 469 |
var elm = false; |
| 470 |
|
| 471 |
var getLink = function () { |
| 472 |
var link = _doc.getElementsByTagName('head')[0].getElementsByTagName('link'); |
| 473 |
for (var l = link.length, i = (l - 1); i >= 0; i--) { |
| 474 |
if ((/(^|\s)icon(\s|$)/i).test(link[i].getAttribute('rel'))) { |
| 475 |
return link[i]; |
| 476 |
} |
| 477 |
} |
| 478 |
return false; |
| 479 |
}; |
| 480 |
if (_opt.element) { |
| 481 |
elm = _opt.element; |
| 482 |
} else if (_opt.elementId) { |
| 483 |
|
| 484 |
elm = _doc.getElementById(_opt.elementId); |
| 485 |
elm.setAttribute('href', elm.getAttribute('src')); |
| 486 |
} else { |
| 487 |
|
| 488 |
elm = getLink(); |
| 489 |
if (elm === false) { |
| 490 |
elm = _doc.createElement('link'); |
| 491 |
elm.setAttribute('rel', 'icon'); |
| 492 |
_doc.getElementsByTagName('head')[0].appendChild(elm); |
| 493 |
} |
| 494 |
} |
| 495 |
elm.setAttribute('type', 'image/png'); |
| 496 |
return elm; |
| 497 |
}; |
| 498 |
link.setIcon = function (canvas) { |
| 499 |
var url = canvas.toDataURL('image/png'); |
| 500 |
if (_opt.dataUrl) { |
| 501 |
|
| 502 |
_opt.dataUrl(url); |
| 503 |
} |
| 504 |
if (_opt.element) { |
| 505 |
_opt.element.setAttribute('href', url); |
| 506 |
_opt.element.setAttribute('src', url); |
| 507 |
} else if (_opt.elementId) { |
| 508 |
|
| 509 |
var elm = _doc.getElementById(_opt.elementId); |
| 510 |
elm.setAttribute('href', url); |
| 511 |
elm.setAttribute('src', url); |
| 512 |
} else { |
| 513 |
|
| 514 |
if (_browser.ff || _browser.opera) { |
| 515 |
|
| 516 |
|
| 517 |
var old = _orig; |
| 518 |
_orig = _doc.createElement('link'); |
| 519 |
|
| 520 |
if (_browser.opera) { |
| 521 |
_orig.setAttribute('rel', 'icon'); |
| 522 |
} |
| 523 |
_orig.setAttribute('rel', 'icon'); |
| 524 |
_orig.setAttribute('type', 'image/png'); |
| 525 |
_doc.getElementsByTagName('head')[0].appendChild(_orig); |
| 526 |
_orig.setAttribute('href', url); |
| 527 |
if (old.parentNode) { |
| 528 |
old.parentNode.removeChild(old); |
| 529 |
} |
| 530 |
} else { |
| 531 |
_orig.setAttribute('href', url); |
| 532 |
} |
| 533 |
} |
| 534 |
}; |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
function hexToRgb(hex) { |
| 539 |
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; |
| 540 |
hex = hex.replace(shorthandRegex, function (m, r, g, b) { |
| 541 |
return r + r + g + g + b + b; |
| 542 |
}); |
| 543 |
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); |
| 544 |
return result ? { |
| 545 |
r: parseInt(result[1], 16), |
| 546 |
g: parseInt(result[2], 16), |
| 547 |
b: parseInt(result[3], 16) |
| 548 |
} : false; |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
function merge(def, opt) { |
| 555 |
var mergedOpt = {}; |
| 556 |
var attrname; |
| 557 |
for (attrname in def) { |
| 558 |
mergedOpt[attrname] = def[attrname]; |
| 559 |
} |
| 560 |
for (attrname in opt) { |
| 561 |
mergedOpt[attrname] = opt[attrname]; |
| 562 |
} |
| 563 |
return mergedOpt; |
| 564 |
} |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
function isPageHidden() { |
| 571 |
return _doc.hidden || _doc.msHidden || _doc.webkitHidden || _doc.mozHidden; |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
var animation = {}; |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
animation.duration = 40; |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
animation.types = {}; |
| 586 |
animation.types.fade = [{ |
| 587 |
x: 0.4, |
| 588 |
y: 0.4, |
| 589 |
w: 0.6, |
| 590 |
h: 0.6, |
| 591 |
o: 0.0 |
| 592 |
}, { |
| 593 |
x: 0.4, |
| 594 |
y: 0.4, |
| 595 |
w: 0.6, |
| 596 |
h: 0.6, |
| 597 |
o: 0.1 |
| 598 |
}, { |
| 599 |
x: 0.4, |
| 600 |
y: 0.4, |
| 601 |
w: 0.6, |
| 602 |
h: 0.6, |
| 603 |
o: 0.2 |
| 604 |
}, { |
| 605 |
x: 0.4, |
| 606 |
y: 0.4, |
| 607 |
w: 0.6, |
| 608 |
h: 0.6, |
| 609 |
o: 0.3 |
| 610 |
}, { |
| 611 |
x: 0.4, |
| 612 |
y: 0.4, |
| 613 |
w: 0.6, |
| 614 |
h: 0.6, |
| 615 |
o: 0.4 |
| 616 |
}, { |
| 617 |
x: 0.4, |
| 618 |
y: 0.4, |
| 619 |
w: 0.6, |
| 620 |
h: 0.6, |
| 621 |
o: 0.5 |
| 622 |
}, { |
| 623 |
x: 0.4, |
| 624 |
y: 0.4, |
| 625 |
w: 0.6, |
| 626 |
h: 0.6, |
| 627 |
o: 0.6 |
| 628 |
}, { |
| 629 |
x: 0.4, |
| 630 |
y: 0.4, |
| 631 |
w: 0.6, |
| 632 |
h: 0.6, |
| 633 |
o: 0.7 |
| 634 |
}, { |
| 635 |
x: 0.4, |
| 636 |
y: 0.4, |
| 637 |
w: 0.6, |
| 638 |
h: 0.6, |
| 639 |
o: 0.8 |
| 640 |
}, { |
| 641 |
x: 0.4, |
| 642 |
y: 0.4, |
| 643 |
w: 0.6, |
| 644 |
h: 0.6, |
| 645 |
o: 0.9 |
| 646 |
}, { |
| 647 |
x: 0.4, |
| 648 |
y: 0.4, |
| 649 |
w: 0.6, |
| 650 |
h: 0.6, |
| 651 |
o: 1.0 |
| 652 |
}]; |
| 653 |
animation.types.none = [{ |
| 654 |
x: 0.4, |
| 655 |
y: 0.4, |
| 656 |
w: 0.6, |
| 657 |
h: 0.6, |
| 658 |
o: 1 |
| 659 |
}]; |
| 660 |
animation.types.pop = [{ |
| 661 |
x: 1, |
| 662 |
y: 1, |
| 663 |
w: 0, |
| 664 |
h: 0, |
| 665 |
o: 1 |
| 666 |
}, { |
| 667 |
x: 0.9, |
| 668 |
y: 0.9, |
| 669 |
w: 0.1, |
| 670 |
h: 0.1, |
| 671 |
o: 1 |
| 672 |
}, { |
| 673 |
x: 0.8, |
| 674 |
y: 0.8, |
| 675 |
w: 0.2, |
| 676 |
h: 0.2, |
| 677 |
o: 1 |
| 678 |
}, { |
| 679 |
x: 0.7, |
| 680 |
y: 0.7, |
| 681 |
w: 0.3, |
| 682 |
h: 0.3, |
| 683 |
o: 1 |
| 684 |
}, { |
| 685 |
x: 0.6, |
| 686 |
y: 0.6, |
| 687 |
w: 0.4, |
| 688 |
h: 0.4, |
| 689 |
o: 1 |
| 690 |
}, { |
| 691 |
x: 0.5, |
| 692 |
y: 0.5, |
| 693 |
w: 0.5, |
| 694 |
h: 0.5, |
| 695 |
o: 1 |
| 696 |
}, { |
| 697 |
x: 0.4, |
| 698 |
y: 0.4, |
| 699 |
w: 0.6, |
| 700 |
h: 0.6, |
| 701 |
o: 1 |
| 702 |
}]; |
| 703 |
animation.types.popFade = [{ |
| 704 |
x: 0.75, |
| 705 |
y: 0.75, |
| 706 |
w: 0, |
| 707 |
h: 0, |
| 708 |
o: 0 |
| 709 |
}, { |
| 710 |
x: 0.65, |
| 711 |
y: 0.65, |
| 712 |
w: 0.1, |
| 713 |
h: 0.1, |
| 714 |
o: 0.2 |
| 715 |
}, { |
| 716 |
x: 0.6, |
| 717 |
y: 0.6, |
| 718 |
w: 0.2, |
| 719 |
h: 0.2, |
| 720 |
o: 0.4 |
| 721 |
}, { |
| 722 |
x: 0.55, |
| 723 |
y: 0.55, |
| 724 |
w: 0.3, |
| 725 |
h: 0.3, |
| 726 |
o: 0.6 |
| 727 |
}, { |
| 728 |
x: 0.50, |
| 729 |
y: 0.50, |
| 730 |
w: 0.4, |
| 731 |
h: 0.4, |
| 732 |
o: 0.8 |
| 733 |
}, { |
| 734 |
x: 0.45, |
| 735 |
y: 0.45, |
| 736 |
w: 0.5, |
| 737 |
h: 0.5, |
| 738 |
o: 0.9 |
| 739 |
}, { |
| 740 |
x: 0.4, |
| 741 |
y: 0.4, |
| 742 |
w: 0.6, |
| 743 |
h: 0.6, |
| 744 |
o: 1 |
| 745 |
}]; |
| 746 |
animation.types.slide = [{ |
| 747 |
x: 0.4, |
| 748 |
y: 1, |
| 749 |
w: 0.6, |
| 750 |
h: 0.6, |
| 751 |
o: 1 |
| 752 |
}, { |
| 753 |
x: 0.4, |
| 754 |
y: 0.9, |
| 755 |
w: 0.6, |
| 756 |
h: 0.6, |
| 757 |
o: 1 |
| 758 |
}, { |
| 759 |
x: 0.4, |
| 760 |
y: 0.9, |
| 761 |
w: 0.6, |
| 762 |
h: 0.6, |
| 763 |
o: 1 |
| 764 |
}, { |
| 765 |
x: 0.4, |
| 766 |
y: 0.8, |
| 767 |
w: 0.6, |
| 768 |
h: 0.6, |
| 769 |
o: 1 |
| 770 |
}, { |
| 771 |
x: 0.4, |
| 772 |
y: 0.7, |
| 773 |
w: 0.6, |
| 774 |
h: 0.6, |
| 775 |
o: 1 |
| 776 |
}, { |
| 777 |
x: 0.4, |
| 778 |
y: 0.6, |
| 779 |
w: 0.6, |
| 780 |
h: 0.6, |
| 781 |
o: 1 |
| 782 |
}, { |
| 783 |
x: 0.4, |
| 784 |
y: 0.5, |
| 785 |
w: 0.6, |
| 786 |
h: 0.6, |
| 787 |
o: 1 |
| 788 |
}, { |
| 789 |
x: 0.4, |
| 790 |
y: 0.4, |
| 791 |
w: 0.6, |
| 792 |
h: 0.6, |
| 793 |
o: 1 |
| 794 |
}]; |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
animation.run = function (opt, cb, revert, step) { |
| 803 |
var animationType = animation.types[isPageHidden() ? 'none' : _opt.animation]; |
| 804 |
if (revert === true) { |
| 805 |
step = (typeof step !== 'undefined') ? step : animationType.length - 1; |
| 806 |
} else { |
| 807 |
step = (typeof step !== 'undefined') ? step : 0; |
| 808 |
} |
| 809 |
cb = (cb) ? cb : function () { |
| 810 |
}; |
| 811 |
if ((step < animationType.length) && (step >= 0)) { |
| 812 |
type[_opt.type](merge(opt, animationType[step])); |
| 813 |
_animTimeout = setTimeout(function () { |
| 814 |
if (revert) { |
| 815 |
step = step - 1; |
| 816 |
} else { |
| 817 |
step = step + 1; |
| 818 |
} |
| 819 |
animation.run(opt, cb, revert, step); |
| 820 |
}, animation.duration); |
| 821 |
|
| 822 |
link.setIcon(_canvas); |
| 823 |
} else { |
| 824 |
cb(); |
| 825 |
return; |
| 826 |
} |
| 827 |
}; |
| 828 |
|
| 829 |
init(); |
| 830 |
return { |
| 831 |
badge: badge, |
| 832 |
video: video, |
| 833 |
image: image, |
| 834 |
webcam: webcam, |
| 835 |
reset: icon.reset, |
| 836 |
browser: { |
| 837 |
supported: _browser.supported |
| 838 |
} |
| 839 |
}; |
| 840 |
}); |
| 841 |
|
| 842 |
|
| 843 |
if (typeof define !== 'undefined' && define.amd) { |
| 844 |
define([], function () { |
| 845 |
return Favico; |
| 846 |
}); |
| 847 |
} |
| 848 |
|
| 849 |
else if (typeof module !== 'undefined' && module.exports) { |
| 850 |
module.exports = Favico; |
| 851 |
} |
| 852 |
|
| 853 |
else { |
| 854 |
this.Favico = Favico; |
| 855 |
} |
| 856 |
|
| 857 |
})(); |