Revert "now building the project using amd modules. Included requirejs. Adjusted build script."
This reverts commit b86e7755d6
.
This commit is contained in:
parent
9ce335bd0e
commit
c07f62428c
11 changed files with 181 additions and 183 deletions
21
Gulpfile.js
21
Gulpfile.js
|
@ -13,11 +13,12 @@ var tsProject = $.typescript.createProject('tsconfig.json', {
|
|||
});
|
||||
|
||||
gulp.task('scripts', function() {
|
||||
var tsResult = gulp.src('src/**/*.ts')
|
||||
var tsResult = gulp.src('src/*.ts')
|
||||
.pipe($.sourcemaps.init())
|
||||
.pipe($.typescript(tsProject));
|
||||
|
||||
return tsResult.js
|
||||
.pipe($.concat('bundle.js'))
|
||||
.pipe($.ngAnnotate())
|
||||
.pipe($.sourcemaps.write()) // Now the sourcemaps are added to the .js file
|
||||
.pipe(gulp.dest('tmp'));
|
||||
|
@ -65,8 +66,7 @@ gulp.task('dist-node-modules', function () {
|
|||
'node_modules/bootstrap/**/*',
|
||||
'node_modules/angular/**/*',
|
||||
'node_modules/jquery/**/*',
|
||||
'node_modules/lodash/**/*',
|
||||
'node_modules/requirejs/**/*'
|
||||
'node_modules/lodash/**/*'
|
||||
], {base: 'node_modules'})
|
||||
.pipe(gulp.dest('tmp/vendor'));
|
||||
});
|
||||
|
@ -89,20 +89,11 @@ gulp.task('serve', ['tmp'], function () {
|
|||
|
||||
// add browserSync.reload to the tasks array to make
|
||||
// all browsers reload after tasks are complete.
|
||||
gulp.watch("src/**/*.ts", ['serve-reload-scripts']);
|
||||
gulp.watch("src/**/*.ts", ['scripts']);
|
||||
gulp.watch([
|
||||
"src/**/*.html",
|
||||
"src/**/*.css",
|
||||
"src/**/*.js"
|
||||
], ['serve-reload-other']);
|
||||
});
|
||||
|
||||
gulp.task('serve-reload-scripts', ['scripts'], function (done) {
|
||||
browserSync.reload;
|
||||
done();
|
||||
});
|
||||
|
||||
gulp.task('serve-reload-other', ['tmp'], function (done) {
|
||||
browserSync.reload;
|
||||
done();
|
||||
], ['tmp']);
|
||||
gulp.watch("tmp/**/*").on("change", browserSync.reload);
|
||||
});
|
|
@ -23,21 +23,20 @@
|
|||
},
|
||||
"homepage": "https://github.com/nilsnh/tag-youre-it",
|
||||
"dependencies": {
|
||||
"browser-sync": "^2.9.6",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-sourcemaps": "^1.6.0",
|
||||
"angular": "^1.4.7",
|
||||
"bootstrap": "^3.3.5",
|
||||
"browser-sync": "^2.9.6",
|
||||
"del": "^2.0.2",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-concat": "^2.6.0",
|
||||
"gulp-file-include": "^0.13.7",
|
||||
"gulp-flatten": "^0.2.0",
|
||||
"gulp-load-plugins": "^1.0.0",
|
||||
"gulp-ng-annotate": "^1.1.0",
|
||||
"gulp-sourcemaps": "^1.6.0",
|
||||
"gulp-typescript": "^2.9.2",
|
||||
"jquery": "^2.1.4",
|
||||
"lodash": "^3.10.1",
|
||||
"merge2": "^0.3.6",
|
||||
"requirejs": "^2.1.20"
|
||||
"merge2": "^0.3.6"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Code used by both the local web prototype as well as the plugin.
|
||||
|
||||
function injectScripts (tagIt) {
|
||||
function injectScripts () {
|
||||
|
||||
// Save a copy of existing angular js and jquery
|
||||
// Source: http://www.mattburkedev.com/multiple-angular-versions-on-the-same-page/
|
||||
|
@ -14,13 +14,14 @@ function injectScripts (tagIt) {
|
|||
|
||||
function loadAngular () {
|
||||
console.log('loading angular');
|
||||
window.name = 'NG_DEFER_BOOTSTRAP!';
|
||||
loadScript('vendor/angular/angular.js', loadPluginCode);
|
||||
}
|
||||
|
||||
function loadPluginCode () {
|
||||
console.log('loading tagit');
|
||||
tagIt.init(restoreOldAngularAndJquery);
|
||||
loadScript('bundle.js', function () {
|
||||
tagIt.init(restoreOldAngularAndJquery);
|
||||
});
|
||||
}
|
||||
|
||||
function restoreOldAngularAndJquery () {
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
@@include('content_script_include.js')
|
||||
|
||||
requirejs(['index'], function (tagIt) {
|
||||
injectScripts(tagIt); //found in the included file
|
||||
});
|
||||
injectScripts(); //found in the included file
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
document.getElementById('js-show-menu')
|
||||
.addEventListener('click', function () {
|
||||
if (!document.getElementById('tagit-menu')) injectScripts();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
<meta charset="UTF-8">
|
||||
<link href="vendor/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="style.css" rel="stylesheet">
|
||||
<script src="vendor/requirejs/require.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
|
||||
<script src="vendor/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.0/angular.min.js"></script>
|
||||
|
|
|
@ -1,33 +1,36 @@
|
|||
/// <reference path="../typings/tsd.d.ts" />
|
||||
|
||||
export interface ISynset {
|
||||
config: Object,
|
||||
data: {
|
||||
senses: string[]
|
||||
module tagIt {
|
||||
|
||||
export interface ISynset {
|
||||
config: Object,
|
||||
data: {
|
||||
senses: string[]
|
||||
}
|
||||
}
|
||||
|
||||
export interface IVMScope extends angular.IScope {
|
||||
vm : Object;
|
||||
}
|
||||
|
||||
export interface ISense {
|
||||
explanation: string,
|
||||
rank: number,
|
||||
related: string,
|
||||
senseid: string,
|
||||
source: string,
|
||||
word: string
|
||||
}
|
||||
|
||||
/*
|
||||
sentence: represents everything contained by punctuations.
|
||||
context: represents ten chars "in both directions" from the word.
|
||||
*/
|
||||
export interface ISenseTag {
|
||||
userEmail: string,
|
||||
senseid: string,
|
||||
sentence: string,
|
||||
context: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface IVMScope extends angular.IScope {
|
||||
vm : Object;
|
||||
}
|
||||
|
||||
export interface ISense {
|
||||
explanation: string,
|
||||
rank: number,
|
||||
related: string,
|
||||
senseid: string,
|
||||
source: string,
|
||||
word: string
|
||||
}
|
||||
|
||||
/*
|
||||
sentence: represents everything contained by punctuations.
|
||||
context: represents ten chars "in both directions" from the word.
|
||||
*/
|
||||
export interface ISenseTag {
|
||||
userEmail: string,
|
||||
senseid: string,
|
||||
sentence: string,
|
||||
context: string
|
||||
}
|
||||
|
||||
|
|
40
src/index.ts
40
src/index.ts
|
@ -1,36 +1,34 @@
|
|||
/// <reference path="../typings/tsd.d.ts" />
|
||||
|
||||
import { DataService } from './services/data.service';
|
||||
import { SelectedWordService } from './services/selectedWord.service';
|
||||
import { MenuCtrl } from './menu/menu.controller';
|
||||
/// <reference path="menu/menu.controller.ts" />
|
||||
/// <reference path="services/data.service.ts" />
|
||||
/// <reference path="services/selectedWord.service.ts" />
|
||||
|
||||
export function init (callback: () => void) {
|
||||
var $ = jQuery;
|
||||
module tagIt {
|
||||
|
||||
angular.module('tagit', [])
|
||||
.service('DataService', DataService)
|
||||
.service('SelectedWordService', SelectedWordService)
|
||||
.controller('MenuCtrl', MenuCtrl);
|
||||
|
||||
$.get('menu.tpl.html', function (htmlData) {
|
||||
$('body').children().wrapAll('<div id="tagit-body" class="tagit-body" />');
|
||||
$('.tagit-body').before(htmlData);
|
||||
window.name = '';
|
||||
|
||||
angular.element(document).ready(function () {
|
||||
export function init (callback: () => void) {
|
||||
var $ = jQuery;
|
||||
$.get(chromeUrlTranslator('menu.tpl.html'), function (htmlData) {
|
||||
$('body').children().wrapAll('<div id="tagit-body" class="tagit-body" />');
|
||||
$('.tagit-body').before(htmlData);
|
||||
window.name = '';
|
||||
angular.bootstrap(document.getElementById("tagit-menu"), ['tagit']);
|
||||
console.log('TagIt menu loaded');
|
||||
if(callback) callback();
|
||||
});
|
||||
|
||||
if(callback) callback();
|
||||
});
|
||||
|
||||
// function chromeUrlTranslator(relativeUrl : string) {
|
||||
// if(chrome && chrome.extension) {
|
||||
// return chrome.extension.getURL(relativeUrl);
|
||||
// } else {
|
||||
// relativeUrl;
|
||||
// }
|
||||
// }
|
||||
function chromeUrlTranslator(relativeUrl : string) {
|
||||
if(chrome && chrome.extension) {
|
||||
return chrome.extension.getURL(relativeUrl);
|
||||
} else {
|
||||
relativeUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,65 +1,65 @@
|
|||
'use strict';
|
||||
/// <reference path="../index.ts" />
|
||||
|
||||
import { DataService } from '../services/data.service';
|
||||
import { SelectedWordService } from '../services/selectedWord.service';
|
||||
import { ISense, IVMScope, ISynset } from '../index.interfaces';
|
||||
module tagIt {
|
||||
'use strict';
|
||||
|
||||
export class MenuCtrl {
|
||||
export class MenuCtrl {
|
||||
|
||||
selectedWord = "";
|
||||
senses : Object[];
|
||||
dataService : DataService;
|
||||
selectedWordService : SelectedWordService;
|
||||
$log : ng.ILogService;
|
||||
$scope: ng.IScope;
|
||||
selectedWord = "";
|
||||
senses : Object[];
|
||||
dataService : DataService;
|
||||
selectedWordService : SelectedWordService;
|
||||
$log : ng.ILogService;
|
||||
$scope: ng.IScope;
|
||||
|
||||
/* @ngInject */
|
||||
constructor ($scope: IVMScope, $log: angular.ILogService,
|
||||
DataService: DataService,
|
||||
SelectedWordService: SelectedWordService) {
|
||||
$scope.vm = this;
|
||||
this.$log = $log;
|
||||
this.$scope = $scope;
|
||||
this.dataService = DataService;
|
||||
this.selectedWordService = SelectedWordService;
|
||||
/* @ngInject */
|
||||
constructor ($scope: IVMScope, $log: angular.ILogService,
|
||||
DataService: DataService,
|
||||
SelectedWordService: SelectedWordService) {
|
||||
$scope.vm = this;
|
||||
this.$log = $log;
|
||||
this.$scope = $scope;
|
||||
this.dataService = DataService;
|
||||
this.selectedWordService = SelectedWordService;
|
||||
|
||||
// Wire up clicklistener
|
||||
this.selectedWordService.wireUpListener(this.onWordSelected,
|
||||
this.onWordDeSelected);
|
||||
}
|
||||
// Wire up clicklistener
|
||||
this.selectedWordService.wireUpListener(this.onWordSelected,
|
||||
this.onWordDeSelected);
|
||||
}
|
||||
|
||||
onTagSelect (sense: ISense) {
|
||||
this.selectedWordService.addTagToPage(sense);
|
||||
this.dataService.storeTaggingInformation({});
|
||||
}
|
||||
onTagSelect (sense: ISense) {
|
||||
this.selectedWordService.addTagToPage(sense);
|
||||
this.dataService.storeTaggingInformation({});
|
||||
}
|
||||
|
||||
onWordSelected = (newWord : string) => {
|
||||
this.selectedWord = newWord;
|
||||
this.dataService.callServer(newWord)
|
||||
.then((synsets : Object) => {
|
||||
this.$log.debug(synsets);
|
||||
this.senses = this.dataService.processSynsets(<ISynset> synsets);
|
||||
onWordSelected = (newWord : string) => {
|
||||
this.selectedWord = newWord;
|
||||
this.dataService.callServer(newWord)
|
||||
.then((synsets : Object) => {
|
||||
this.$log.debug(synsets);
|
||||
this.senses = this.dataService.processSynsets(<ISynset> synsets);
|
||||
});
|
||||
}
|
||||
|
||||
onWordDeSelected = () => {
|
||||
this.$log.debug("onWordDeSelected");
|
||||
this.selectedWord = "";
|
||||
this.senses = [];
|
||||
this.$scope.$apply();
|
||||
}
|
||||
|
||||
selectWord (sense : ISense) {
|
||||
this.dataService.storeTaggingInformation({
|
||||
mail: "mail@nilsnh.no",
|
||||
sentence: "whole sentence",
|
||||
senseid: sense.senseid,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onWordDeSelected = () => {
|
||||
this.$log.debug("onWordDeSelected");
|
||||
this.selectedWord = "";
|
||||
this.senses = [];
|
||||
this.$scope.$apply();
|
||||
}
|
||||
removeMenu() {
|
||||
$('.tagit-body').children().unwrap();
|
||||
$('.tagit-menu').remove();
|
||||
}
|
||||
|
||||
selectWord (sense : ISense) {
|
||||
this.dataService.storeTaggingInformation({
|
||||
mail: "mail@nilsnh.no",
|
||||
sentence: "whole sentence",
|
||||
senseid: sense.senseid,
|
||||
});
|
||||
}
|
||||
|
||||
removeMenu() {
|
||||
$('.tagit-body').children().unwrap();
|
||||
$('.tagit-menu').remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,29 +1,31 @@
|
|||
/// <reference path="../index.interfaces.ts" />
|
||||
|
||||
'use strict';
|
||||
|
||||
import { ISynset } from '../index.interfaces';
|
||||
module tagIt {
|
||||
|
||||
export class DataService {
|
||||
export class DataService {
|
||||
|
||||
$http : ng.IHttpService;
|
||||
$log : ng.ILogService;
|
||||
private serverUrl = 'http://lexitags.dyndns.org/server/lexitags2/Semtags?data=';
|
||||
$http : ng.IHttpService;
|
||||
$log : ng.ILogService;
|
||||
private serverUrl = 'http://lexitags.dyndns.org/server/lexitags2/Semtags?data=';
|
||||
|
||||
/* @ngInject */
|
||||
constructor($http: ng.IHttpService, $log: ng.ILogService) {
|
||||
this.$http = $http;
|
||||
this.$log = $log;
|
||||
}
|
||||
/* @ngInject */
|
||||
constructor($http: ng.IHttpService, $log: ng.ILogService) {
|
||||
this.$http = $http;
|
||||
this.$log = $log;
|
||||
}
|
||||
|
||||
callServer (word: string) {
|
||||
if (!word) {
|
||||
return;
|
||||
};
|
||||
return this.$http.get(this.serverUrl + this.createQuery(word));
|
||||
}
|
||||
callServer (word: string) {
|
||||
if (!word) {
|
||||
return;
|
||||
};
|
||||
return this.$http.get(this.serverUrl + this.createQuery(word));
|
||||
}
|
||||
|
||||
processSynsets (synsets: ISynset) : string[] {
|
||||
return synsets.data.senses;
|
||||
}
|
||||
processSynsets (synsets: ISynset) : string[] {
|
||||
return synsets.data.senses;
|
||||
}
|
||||
|
||||
// save tagging information
|
||||
// Params: email, tagging, sentence
|
||||
|
@ -34,6 +36,7 @@ export class DataService {
|
|||
|
||||
private createQuery (word: string) {
|
||||
return '{"word":"QUERYTOREPLACE"}'
|
||||
.replace(/QUERYTOREPLACE/, word);
|
||||
.replace(/QUERYTOREPLACE/, word);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +1,43 @@
|
|||
import { ISense } from '../index.interfaces';
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Takes care of figuring out what word
|
||||
* is selected.
|
||||
*/
|
||||
export class SelectedWordService {
|
||||
module tagIt {
|
||||
/**
|
||||
* Takes care of figuring out what word
|
||||
* is selected.
|
||||
*/
|
||||
export class SelectedWordService {
|
||||
|
||||
$log : ng.ILogService;
|
||||
currentSelectionRange : any;
|
||||
$log : ng.ILogService;
|
||||
currentSelectionRange : any;
|
||||
|
||||
/* @ngInject */
|
||||
constructor($log: ng.ILogService) {
|
||||
this.$log = $log;
|
||||
}
|
||||
/* @ngInject */
|
||||
constructor($log: ng.ILogService) {
|
||||
this.$log = $log;
|
||||
}
|
||||
|
||||
wireUpListener (callbackOnSelectFunc : (result : Object) => void,
|
||||
callbackOnDeSelectFunc : () => void) {
|
||||
var that = this;
|
||||
document.getElementById('tagit-body')
|
||||
.addEventListener('click', (evt : any) => {
|
||||
if (!document.hasFocus()) {
|
||||
return true;
|
||||
}
|
||||
var selection = that.findSelection();
|
||||
if(selection) {
|
||||
this.currentSelectionRange = selection.getRangeAt(0).cloneRange();
|
||||
callbackOnSelectFunc(joinLongWords(selection.toString()));
|
||||
wireUpListener (callbackOnSelectFunc : (result : Object) => void,
|
||||
callbackOnDeSelectFunc : () => void) {
|
||||
var that = this;
|
||||
document.getElementById('tagit-body')
|
||||
.addEventListener('click', (evt : any) => {
|
||||
if (!document.hasFocus()) {
|
||||
return true;
|
||||
}
|
||||
var selection = that.findSelection();
|
||||
if(selection) {
|
||||
this.currentSelectionRange = selection.getRangeAt(0).cloneRange();
|
||||
callbackOnSelectFunc(joinLongWords(selection.toString()));
|
||||
} else {
|
||||
callbackOnDeSelectFunc();
|
||||
}
|
||||
// clicks should propagate upwards to other things
|
||||
// evt.stopPropagation();
|
||||
// evt.preventDefault();
|
||||
}, false);
|
||||
function joinLongWords (possiblyLongWord: string) {
|
||||
return possiblyLongWord.replace(" ","_");
|
||||
}, false);
|
||||
function joinLongWords (possiblyLongWord: string) {
|
||||
return possiblyLongWord.replace(" ","_");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// place spans around a tagged word.
|
||||
addTagToPage (sense : ISense) {
|
||||
|
@ -74,8 +73,9 @@ export class SelectedWordService {
|
|||
if (selectedText) {
|
||||
this.$log.debug('text that was selected: ' + selectedText);
|
||||
return currentSelection;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "amd",
|
||||
"noImplicitAny": true,
|
||||
"target": "es5"
|
||||
"out": "output.js"
|
||||
},
|
||||
"files": [
|
||||
"src/index.ts"
|
||||
|
|
Loading…
Reference in a new issue