now building the project using amd modules. Included requirejs. Adjusted build script.

This commit is contained in:
Nils Norman Haukås 2015-11-07 23:47:50 +01:00
parent 7377c38efb
commit b86e7755d6
11 changed files with 188 additions and 186 deletions

View file

@ -13,12 +13,11 @@ 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'));
@ -66,7 +65,8 @@ gulp.task('dist-node-modules', function () {
'node_modules/bootstrap/**/*',
'node_modules/angular/**/*',
'node_modules/jquery/**/*',
'node_modules/lodash/**/*'
'node_modules/lodash/**/*',
'node_modules/requirejs/**/*'
], {base: 'node_modules'})
.pipe(gulp.dest('tmp/vendor'));
});
@ -89,11 +89,20 @@ 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", ['scripts']);
gulp.watch("src/**/*.ts", ['serve-reload-scripts']);
gulp.watch([
"src/**/*.html",
"src/**/*.css",
"src/**/*.js"
], ['tmp']);
gulp.watch("tmp/**/*").on("change", browserSync.reload);
], ['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();
});

View file

@ -23,20 +23,21 @@
},
"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"
"merge2": "^0.3.6",
"requirejs": "^2.1.20"
}
}

View file

@ -1,6 +1,6 @@
// Code used by both the local web prototype as well as the plugin.
function injectScripts () {
function injectScripts (tagIt) {
// Save a copy of existing angular js and jquery
// Source: http://www.mattburkedev.com/multiple-angular-versions-on-the-same-page/
@ -14,14 +14,13 @@ function injectScripts () {
function loadAngular () {
console.log('loading angular');
window.name = 'NG_DEFER_BOOTSTRAP!';
loadScript('vendor/angular/angular.js', loadPluginCode);
}
function loadPluginCode () {
console.log('loading tagit');
loadScript('bundle.js', function () {
tagIt.init(restoreOldAngularAndJquery);
});
tagIt.init(restoreOldAngularAndJquery);
}
function restoreOldAngularAndJquery () {

View file

@ -2,11 +2,6 @@
@@include('content_script_include.js')
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();
});
});
requirejs(['index'], function (tagIt) {
injectScripts(tagIt); //found in the included file
});

View file

@ -5,6 +5,7 @@
<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>

View file

@ -1,36 +1,33 @@
/// <reference path="../typings/tsd.d.ts" />
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 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
}

View file

@ -1,34 +1,36 @@
/// <reference path="../typings/tsd.d.ts" />
/// <reference path="menu/menu.controller.ts" />
/// <reference path="services/data.service.ts" />
/// <reference path="services/selectedWord.service.ts" />
import { DataService } from './services/data.service';
import { SelectedWordService } from './services/selectedWord.service';
import { MenuCtrl } from './menu/menu.controller';
module tagIt {
export function init (callback: () => void) {
var $ = jQuery;
angular.module('tagit', [])
.service('DataService', DataService)
.service('SelectedWordService', SelectedWordService)
.controller('MenuCtrl', MenuCtrl);
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 = '';
$.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 () {
angular.bootstrap(document.getElementById("tagit-menu"), ['tagit']);
console.log('TagIt menu loaded');
if(callback) callback();
});
function chromeUrlTranslator(relativeUrl : string) {
if(chrome && chrome.extension) {
return chrome.extension.getURL(relativeUrl);
} else {
relativeUrl;
}
}
}
if(callback) callback();
});
// function chromeUrlTranslator(relativeUrl : string) {
// if(chrome && chrome.extension) {
// return chrome.extension.getURL(relativeUrl);
// } else {
// relativeUrl;
// }
// }
}

View file

@ -1,65 +1,65 @@
/// <reference path="../index.ts" />
'use strict';
module tagIt {
'use strict';
import { DataService } from '../services/data.service';
import { SelectedWordService } from '../services/selectedWord.service';
import { ISense, IVMScope, ISynset } from '../index.interfaces';
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;
// Wire up clicklistener
this.selectedWordService.wireUpListener(this.onWordSelected,
this.onWordDeSelected);
}
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);
});
}
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,
});
}
removeMenu() {
$('.tagit-body').children().unwrap();
$('.tagit-menu').remove();
}
/* @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);
}
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);
});
}
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,
});
}
removeMenu() {
$('.tagit-body').children().unwrap();
$('.tagit-menu').remove();
}
}

View file

@ -1,31 +1,29 @@
/// <reference path="../index.interfaces.ts" />
'use strict';
module tagIt {
import { ISynset } from '../index.interfaces';
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
@ -36,7 +34,6 @@ module tagIt {
private createQuery (word: string) {
return '{"word":"QUERYTOREPLACE"}'
.replace(/QUERYTOREPLACE/, word);
.replace(/QUERYTOREPLACE/, word);
}
}
}

View file

@ -1,43 +1,44 @@
import { ISense } from '../index.interfaces';
'use strict';
module tagIt {
/**
* Takes care of figuring out what word
* is selected.
*/
export class SelectedWordService {
/**
* 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) {
@ -73,9 +74,8 @@ module tagIt {
if (selectedText) {
this.$log.debug('text that was selected: ' + selectedText);
return currentSelection;
} else {
return;
} else {
return;
}
}
}
}
}

View file

@ -1,7 +1,8 @@
{
"compilerOptions": {
"module": "amd",
"noImplicitAny": true,
"out": "output.js"
"target": "es5"
},
"files": [
"src/index.ts"