mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 04:24:45 -04:00
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
|
|
modulejs.define('ext/qrcode', ['_', '$', 'modernizr', 'core/settings', 'core/event'], function (_, $, modernizr, allsettings, event) {
|
|
|
|
var settings = _.extend({
|
|
enabled: false,
|
|
size: 150
|
|
}, allsettings.qrcode),
|
|
|
|
template = '<div id="qrcode"/>',
|
|
|
|
$qrcode, hideTimeoutId,
|
|
|
|
update = function (item) {
|
|
|
|
$qrcode.empty().qrcode({
|
|
render: modernizr.canvas ? 'canvas' : 'div',
|
|
width: settings.size,
|
|
height: settings.size,
|
|
color: '#333',
|
|
bgColor: '#fff',
|
|
text: window.location.protocol + '//' + window.location.host + item.absHref
|
|
});
|
|
},
|
|
|
|
onMouseenter = function (item) {
|
|
|
|
if (!item.isFolder()) {
|
|
update(item);
|
|
clearTimeout(hideTimeoutId);
|
|
$qrcode.stop(true, true).fadeIn(400);
|
|
}
|
|
},
|
|
|
|
onMouseleave = function (item) {
|
|
|
|
hideTimeoutId = setTimeout(function () {
|
|
|
|
$qrcode.stop(true, true).fadeOut(400);
|
|
}, 200);
|
|
},
|
|
|
|
init = function () {
|
|
|
|
if (!settings.enabled) {
|
|
return;
|
|
}
|
|
|
|
$qrcode = $(template).appendTo('body');
|
|
|
|
event.sub('item.mouseenter', onMouseenter);
|
|
event.sub('item.mouseleave', onMouseleave);
|
|
};
|
|
|
|
init();
|
|
});
|