You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
angularjs-batarang/hintApp.js

53 lines
1.1 KiB
JavaScript

angular.module('ngHintUI', []).
controller('HintController', ['$scope', 'hintService', HintController]).
service('hintService', ['$rootScope', function($rootScope) {
var onHintCallback,
onRefreshCallback;
this.onHint = function(cb) {
onHintCallback = cb;
};
this.onRefresh = function(cb) {
onRefreshCallback = cb;
};
var port = chrome.extension.connect();
port.postMessage(chrome.devtools.inspectedWindow.tabId);
port.onMessage.addListener(function(msg) {
$rootScope.$apply(function () {
if (msg === 'refresh') {
onRefreshCallback();
} else {
var hint = JSON.parse(msg);
onHintCallback(hint);
}
});
});
port.onDisconnect.addListener(function (a) {
console.log(a);
});
}]);
function HintController($scope, hintService) {
resetMessageData();
// TODO: rename this ?
hintService.onRefresh(resetMessageData);
function resetMessageData() {
$scope.hints = [];
}
//Set the hint service to perform this action whenever
//a new hint message is received.
hintService.onHint(function(hint) {
$scope.hints.push(hint);
});
}