glowingbear-mainbox/js/utils.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-08-28 18:25:40 +02:00
var weechat = angular.module('weechat');
weechat.factory('utils', function() {
// Helper to change style of a class
var changeClassStyle = function(classSelector, attr, value) {
_.each(document.getElementsByClassName(classSelector), function(e) {
e.style[attr] = value;
});
};
// Helper to get style from a class
var getClassStyle = function(classSelector, attr) {
_.each(document.getElementsByClassName(classSelector), function(e) {
return e.style[attr];
});
};
var isMobileUi = function() {
// TODO don't base detection solely on screen width
// You are right. In the meantime I am renaming isMobileDevice to isMobileUi
var mobile_cutoff = 968;
return (document.body.clientWidth < mobile_cutoff);
};
2016-04-03 14:32:17 +02:00
// Inject a javascript (used by KaTeX)
var inject_script = function(script_url) {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = script_url;
var head = document.getElementsByTagName("head")[0];
head.appendChild(script);
};
// Inject a stylesheet (used by KaTeX and theme switching)
var inject_css = function(css_url, id) {
var elem = document.createElement("link");
elem.rel = "stylesheet";
elem.href = css_url;
if (id)
elem.id = id;
var head = document.getElementsByTagName("head")[0];
head.appendChild(elem);
};
2014-08-28 18:25:40 +02:00
return {
changeClassStyle: changeClassStyle,
getClassStyle: getClassStyle,
2016-04-03 14:32:17 +02:00
isMobileUi: isMobileUi,
inject_script: inject_script,
inject_css: inject_css,
2014-08-28 18:25:40 +02:00
};
});