Skip to content

Commit

Permalink
importing again
Browse files Browse the repository at this point in the history
  • Loading branch information
Jörg Schlötterer committed May 28, 2015
1 parent f27f83f commit 2bade91
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .bowerrc
@@ -0,0 +1,6 @@
{
"directory":"js/lib/",
"scripts": {
"postinstall": "grunt bowerRequirejs"
}
}
31 changes: 31 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,31 @@
/*global module:false*/
module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('package.json'),
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
// Task configuration.
bowerRequirejs: {
target: {
rjsConfig: 'js/common.js',
options: {
baseUrl: './js/lib',
transitive: true
}
}
}
});

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-bower-requirejs');

// Default task.
grunt.registerTask('default', ['bowerRequirejs']);

};
31 changes: 31 additions & 0 deletions bower.json
@@ -0,0 +1,31 @@
{
"name": "eexcess",
"version": "0.0.1",
"authors": [
"eexcess consortium <eexcess@joanneum.at>"
],
"description": "Enhancing Euroupe's eXchange in Cultural, Educational and Scientific reSources",
"moduleType": [
"amd",
"globals"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"lib/",
"test",
"tests"
],
"dependencies": {
"requirejs": "~2.1.17",
"jquery": "~2.1.4",
"c4": "https://github.com/EEXCESS/c4.git"
},
"devDependencies": {
"requirejs": "~2.1.17",
"jquery": "~2.1.4",
"c4": "https://github.com/EEXCESS/c4.git"
}
}
15 changes: 15 additions & 0 deletions html/background.html
@@ -0,0 +1,15 @@
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>TODO write content</div>
<script type="text/javascript" data-main="../js/background" src="../js/lib/requirejs/require.js"></script>
</body>
</html>
40 changes: 40 additions & 0 deletions js/background.js
@@ -0,0 +1,40 @@
require(['./common'], function(common) {
require(['c4/APIconnector'], function(APIconnector) {
var msgAllTabs = function(msg) {
chrome.tabs.query({}, function(tabs) {
for (var i = 0, len = tabs.length; i < len; i++) {
chrome.tabs.sendMessage(tabs[i].id, msg);
}
});
};


chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
if (typeof msg.method !== 'undefined') {
switch (msg.method) {
case 'triggerQuery':
console.log(msg.data);
APIconnector.query(msg.data, function(response) {
if (response.status === 'success') {
msgAllTabs({
method: 'newResults',
data: {profile: msg.data, results: {results: response.data.result}}
});
} else {
msgAllTabs({method: 'error', data: response.data});
}
console.log(response.status);
console.log(response.data);
});
break;
default:
console.log('unknown method: ' + msg.method);
break;
}
} else {
console.log('method not specified');
}
});
});
});

11 changes: 11 additions & 0 deletions js/common.js
@@ -0,0 +1,11 @@
require.config({
shim: {

},
baseUrl: "/js/lib",
paths: {
},
packages: [

]
});
84 changes: 84 additions & 0 deletions js/content.js
@@ -0,0 +1,84 @@
require(['c4/searchBar', 'c4/paragraphDetection', 'c4/namedEntityRecognition', 'c4/iframes'], function(searchBar, paragraphDetection, ner, iframes) {
searchBar.init(function(profile) {
chrome.runtime.sendMessage({method: 'triggerQuery', data: profile});
iframes.sendMsgAll({event: 'eexcess.queryTriggered'});
searchBar.show();
});
window.onmessage = function(e) {
console.log(e.data);
// do something
};

// detect paragraphs
var p = paragraphDetection.getParagraphs();

// enrich paragraphs with entities
ner.entitiesAndCategories(p.map(function(par) {
return {
id: par.id,
headline: par.headline,
content: par.content
};
}), function(result) {
if (result.status && result.status === 'success') {
paragraphDetection.enrichParagraphs(p, result.data.paragraphs);
console.log(p);
}
});

// selection listener
$(document).mouseup(function() {
var selection = paragraphDetection.getSelection(p);
if(selection.selection.length > 0) {
var profile = {
// TODO: split terms
contextKeywords: [{
text:selection.selection,
weight:1.0
}]
};
if(selection.entities) {
profile.contextNamedEntities = selection.entities;
}
// TODO: provide reason
chrome.runtime.sendMessage({method: 'triggerQuery', data: profile});
iframes.sendMsgAll({event: 'eexcess.queryTriggered'});
searchBar.show();
}
console.log(selection);
});

// augment links
$(function() {
paragraphDetection.augmentLinks(
$('.' + paragraphDetection.getSettings().classname),
chrome.extension.getURL('media/icons/19.png'),
function(profile) {
// TODO: provide reason
chrome.runtime.sendMessage({method: 'triggerQuery', data: profile});
iframes.sendMsgAll({event: 'eexcess.queryTriggered'});
searchBar.show();
},
paragraphDetection.getSettings().classname, p
);
});

chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
console.log(msg);
if (msg.method) {
switch (msg.method) {
case 'newResults':
iframes.sendMsgAll({event: 'eexcess.newResults', data: msg.data});
break;
case 'error':
iframes.sendMsgAll({event: 'eexcess.error', data: msg.data});
break;
default:
console.log('unknown method');
break;
}
} else {
console.log('method not specified');
}
});
});
12 changes: 12 additions & 0 deletions js/requireContent.js
@@ -0,0 +1,12 @@
require.load = function(context, moduleName, url) {
var xhr;
xhr = new XMLHttpRequest();
xhr.open('GET', chrome.extension.getURL(url) + '?=' + (new Date()).getTime(), true);
xhr.onreadystatechange = function(e) {
if(xhr.readyState === 4 && xhr.status === 200) {
eval(xhr.responseText);
context.completeLoad(moduleName);
}
};
xhr.send(null);
};
34 changes: 34 additions & 0 deletions manifest.json
@@ -0,0 +1,34 @@
{
"name": "EEXCESS_DEV",
"version": "0.11",
"background": {
"page": "html/background.html"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"run_at":"document_end",
"js": ["js/lib/requirejs/require.js","js/requireContent.js","js/common.js","js/content.js"],
"css": []
}
],

"web_accessible_resources": [
"js/*",
"external/*",
"media/*"
],
"manifest_version": 2,
"permissions": [
"tabs",
"<all_urls>",
"geolocation",
"history",
"background",
"storage"
],
"icons": {"16": "media/icons/16.png",
"48": "media/icons/48.png",
"128": "media/icons/128.png"}
}

Binary file added media/icons/128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/icons/16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/icons/19.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/icons/38.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/icons/48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions package.json
@@ -0,0 +1,10 @@
{
"engines": {
"node": ">= 0.10.0"
},
"devDependencies": {
"bower": "^1.4.1",
"grunt": "^0.4.5",
"grunt-bower-requirejs": "^2.0.0"
}
}

0 comments on commit 2bade91

Please sign in to comment.