Merge pull request #275 from glowing-bear/countWatchers
Better countWatchers, remove jQuery uses
This commit is contained in:
commit
6e88dfe963
1 changed files with 16 additions and 21 deletions
|
@ -491,24 +491,22 @@ function($rootScope,
|
||||||
|
|
||||||
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', function ($rootScope, $scope, $store, $timeout, $log, models, connection) {
|
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', function ($rootScope, $scope, $store, $timeout, $log, models, connection) {
|
||||||
|
|
||||||
|
// From: http://stackoverflow.com/a/18539624 by StackOverflow user "plantian"
|
||||||
$rootScope.countWatchers = function () {
|
$rootScope.countWatchers = function () {
|
||||||
var root = $(document.getElementsByTagName('body'));
|
var q = [$rootScope], watchers = 0, scope;
|
||||||
var watchers = [];
|
while (q.length > 0) {
|
||||||
|
scope = q.pop();
|
||||||
var f = function (element) {
|
if (scope.$$watchers) {
|
||||||
if (element.data().hasOwnProperty('$scope')) {
|
watchers += scope.$$watchers.length;
|
||||||
angular.forEach(element.data().$scope.$$watchers, function (watcher) {
|
|
||||||
watchers.push(watcher);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
if (scope.$$childHead) {
|
||||||
angular.forEach(element.children(), function (childElement) {
|
q.push(scope.$$childHead);
|
||||||
f($(childElement));
|
}
|
||||||
});
|
if (scope.$$nextSibling) {
|
||||||
};
|
q.push(scope.$$nextSibling);
|
||||||
|
}
|
||||||
f(root);
|
}
|
||||||
console.log(watchers.length);
|
console.log(watchers);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -705,7 +703,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
$scope.search = '';
|
$scope.search = '';
|
||||||
|
|
||||||
if (!$rootScope.isMobileUi()) {
|
if (!$rootScope.isMobileUi()) {
|
||||||
$('#sendMessage').focus();
|
document.getElementById('sendMessage').focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1217,10 +1215,7 @@ weechat.directive('inputBar', function() {
|
||||||
* Returns the input element
|
* Returns the input element
|
||||||
*/
|
*/
|
||||||
$scope.getInputNode = function() {
|
$scope.getInputNode = function() {
|
||||||
return $element.find('#'+$scope.inputId)[0];
|
return document.querySelector('textarea#' + $scope.inputId);
|
||||||
};
|
|
||||||
$scope.getForm = function() {
|
|
||||||
return $element.find('form')[0];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.completeNick = function() {
|
$scope.completeNick = function() {
|
||||||
|
|
Loading…
Reference in a new issue