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

50 lines
1.0 KiB
JavaScript

'use strict';
angular.module('ngHintUI', []).
controller('HintController', ['$scope', 'hintService', HintController]).
service('hintService', ['$rootScope', hintService]);
function HintController($scope, hintService) {
resetMessageData();
hintService.onRefresh(resetMessageData);
function resetMessageData() {
$scope.hints = [];
}
hintService.onHint(function(hint) {
$scope.hints.push(hint);
});
}
function hintService($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);
});
}