From 6318a941637ab59ad1b5ad2cda92a94abfdf9972 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Mon, 7 Jul 2014 16:42:23 +0200 Subject: [PATCH] Helpers for class styling Implement our own helpers for getting and setting class styles instead of using jquery functions, since we are getting rid of jquery --- js/glowingbear.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index e81fa40..a590bc9 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -14,6 +14,19 @@ weechat.filter('toArray', 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]; + }); +}; + weechat.filter('irclinky', ['$filter', function($filter) { 'use strict'; return function(text, target) { @@ -843,9 +856,9 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // Save setting for playing sound on notification $store.bind($scope, "soundnotification", false); // Save setting for font family - $store.bind($scope, "fontfamily", angular.element('.monospace').css('font-family')); + $store.bind($scope, "fontfamily", getClassStyle('monospace', 'font-family')); // Save setting for font size - $store.bind($scope, "fontsize", angular.element('.monospace').css('font-size')); + $store.bind($scope, "fontsize", getClassStyle('monospace', 'font-size')); // Save setting for displaying embeds in rootScope so it can be used from service $rootScope.visible = $scope.noembed === false; @@ -896,11 +909,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // Update font family when changed $scope.$watch('fontfamily', function() { - angular.element('.monospace').css('font-family', $scope.fontfamily); + changeClassStyle('monospace', 'font-family', $scope.fontfamily); }); // Update font size when changed $scope.$watch('fontsize', function() { - angular.element('.monospace').css('font-size', $scope.fontsize); + changeClassStyle('monospace', 'font-size', $scope.fontsize); }); $scope.setActiveBuffer = function(bufferId, key) {