TagSpaces is an offline, open source, document manager with tagging support
FF web clipper implementation
Borislav Sapundzhieva5e74a15a588
diff --git a/data/mozilla/main.js b/data/mozilla/main.jsindex 825406222..22e33d8f4 100644--- a/data/mozilla/main.js+++ b/data/mozilla/main.js@@ -20,6 +20,7 @@ var request = require("sdk/request"); // requestvar tabs = require("sdk/tabs");var unload = require('sdk/system/unload');var Panel = require('sdk/panel').Panel;+var selection = require("sdk/selection");//var userstyles = require("userstyles");var {Cc, Ci, Cu@@ -115,21 +116,53 @@ function initToobarButton() {else if (os == "Darwin") {userstyles.load(data.url("mozilla/overlay-darwin.css"));}*/-var tagspacesPanel = new Panel({width: 520,height: 400,- contentURL: data.url('popup.html'),- contentScriptFile:[data.url('libs/jquery/jquery-2.1.1.min.js'), data.url('mozilla/popup.js')],- onHide: null+ contentURL: data.url('popup-mozilla.html'),+ contentScriptFile: [+ data.url('libs/jquery/jquery-2.1.1.min.js'),+ data.url('libs/select2/select2.min.js'),+ //data.url('libs/filesaver.js/FileSaver.js'),+ data.url('libs/dompurify/purify.js'),+ data.url('mozilla/popup.js')+ ],+ //contentScriptWhen: "ready",+ onShow: function() {+ var ttt = tabs.activeTab.title;+ tagspacesPanel.port.emit("show", selection.html, tabs.activeTab.title);+ },+ onHide: function() {+ tagspacesPanel.port.emit("hide");+ }+ });+ //Panel emited messages+ tagspacesPanel.on("message", function(msg){+ console.log("MSG "+ msg);});- tagspacesPanel.port.on("tagspaces.openNewTab", function() {-- openTagSpacesInNewTab();+ tagspacesPanel.port.on('openNewTab', function(content) {+ tagspacesPanel.hide();+ openTagSpacesInNewTab();+ });++ tagspacesPanel.port.on('saveSelectionAsHtml', function(content) {+ tagspacesPanel.hide();+ console.log("saveSelectionAsHtml: " + content);+ });++ tagspacesPanel.port.on('saveAsMHTML', function(content){+ tagspacesPanel.hide();+ console.log("saveAsMHTML: " + content);+ });++ tagspacesPanel.port.on('saveScreenshot', function(content){+ tagspacesPanel.hide();+ console.log("saveScreenshot" + content);});+- var handleChange = function (ctx) {+ var handleChange = function (elem) {tagspacesPanel.show({position: toolbarButton});diff --git a/data/mozilla/popup.js b/data/mozilla/popup.jsindex 239a015b0..f1ff9b623 100644--- a/data/mozilla/popup.js+++ b/data/mozilla/popup.js@@ -2,41 +2,114 @@* Use of this source code is governed by a AGPL3 license that* can be found in the LICENSE file. *//* global saveAs, DOMPurify */-'use strict';(function() {- console.log("Loading Mozilla Popup...");var tags;var title;var html;var htmlTemplate;var tagLibrary;+ var currentSelection;++ function init(selection) {+ console.log("Mozilla Popup init...");- function init() {- console.log("Mozilla Popup init" );+ loadSettingsLocalStorage();$("#startTagSpaces").on("click", function(e) {- self.port.emit('tagspaces.openNewTab', e.toString());+ self.port.emit('openNewTab', e.toString());});$("#saveAsMhtml").on('click', saveAsMHTML);$("#saveSelectionAsHtml").on("click", function() {- console.log("TODO: capture content");++ if(currentSelection) {+ var content = prepareContent(currentSelection);+ self.port.emit('saveSelectionAsHtml', content);+ } else {+ alert("Please select text");+ }});$("#saveScreenshot").on("click", saveScreenshot);}function saveAsMHTML() {- console.log("TODO: saveAsMHTML");+ self.port.emit('saveAsMHTML');+ }++ function saveScreenshot() {+ self.port.emit('saveScreenshot');}- function saveScreenshot() {- console.log("TODO: saveScreenshot");+ function prepareContent(uncleanedHTML) {+ //console.log("uncleaned "+uncleanedHTML);+ var cleanedHTML = DOMPurify.sanitize(uncleanedHTML);++ cleanedHTML = "<body>" + cleanedHTML + "</body>";+ cleanedHTML = htmlTemplate.replace(/\<body[^>]*\>([^]*)\<\/body>/m, cleanedHTML); // jshint ignore:line+ return cleanedHTML;+ }++ function loadSettingsLocalStorage() {+ try {+ var settings = JSON.parse(localStorage.getItem('tagSpacesSettings'));+ //console.log("Settings: "+JSON.stringify(tmpSettings));+ if (settings !== null) {+ htmlTemplate = settings.newHTMLFileContent;+ tagLibrary = settings.tagGroups;+ }+ console.log("Loaded settings from local storage: " + JSON.stringify(tagLibrary));+ } catch (ex) {+ console.log("Loading settings from local storage failed due exception: " + ex);+ }}- $(document).ready(init);+ function extractAllTags() {+ var allTags = [];+ if (tagLibrary === undefined) {+ return allTags;+ }+ for (var i = 0; i < tagLibrary.length; i++) {+ for (var j = 0; j < tagLibrary[i].children.length; j++) {+ if (tagLibrary[i].children[j].type === "plain") {+ allTags.push(tagLibrary[i].children[j].title);+ }+ }+ }+ return allTags;+ }++ //$(document).ready(init);+ init();++ self.port.on("show", function(selection, title) {++ //self.postMessage('show', "ddd1");+ currentSelection = selection;+ var tagList = extractAllTags(tagLibrary);+ console.log("currentSelection: " + currentSelection);++ $('#title').val(title);++ $('#title').focus();++ $('#tags').select2('data', null);+ $("#tags").select2({+ multiple: true,+ tags: tagList,+ tokenSeparators: [",", " "],+ minimumInputLength: 2,+ selectOnBlur: true+ });++ });++ self.port.on("hide", function(){+ console.log("Hide Popup");+ });+ return {};}());diff --git a/data/popup-mozilla.html b/data/popup-mozilla.htmlnew file mode 100644index 000000000..2f4881b6d--- /dev/null+++ b/data/popup-mozilla.html@@ -0,0 +1,57 @@+<!DOCTYPE html>+<html>+<!--+Copyright (c) 2012-2015 The TagSpaces Authors. All rights reserved.+Use of this source code is governed by a AGPL3 license that+can be found in the LICENSE file.+-->+<head lang="en">+ <meta charset="UTF-8">+ <title></title>+ <link rel="stylesheet" type="text/css" href="libs/bootstrap/css/bootstrap.min.css">+ <link rel="stylesheet" type="text/css" href="libs/select2/select2.css">+ <link rel="stylesheet" type="text/css" href="libs/select2/select2-bootstrap.css">+ <link rel="stylesheet" type="text/css" href="libs/font-awesome/css/font-awesome.css">+ <link rel="stylesheet" type="text/css" href="assets/tagspaces.css">+ <!--script type="text/javascript" data-main="loader" src="libs/requirejs/require.js"></script-->+</head>+<body style="width: 520px; height: 400px; padding:0; font-size: 14px; background-color: #f9f9f9;">+<div class="well" style="margin: 0;">+ <div style="white-space: nowrap;" class="text-center">+ <img src="assets/icon128.png" class="pull-left" style="margin-left: 20px; max-height: 32px; max-width: 32px;"/> + <a href="#" class="btn btn-primary" id="startTagSpaces" style="width: 350px;" data-i18n="appLauncher" data-i18n-title="appLauncherTitle">Launch tagspaces</a>+ </div>+ <label style="margin-top: 15px; font-size: 17px;" data-i18n="appLauncherLabel">Capture Web Content</label>+ <div class="form-group">+ <label class="control-label" for="title">1. <span data-i18n="editTitleLabel">Edit Title</span></label>+ <input class="form-control" type="text" name="title" id="title" autocomplete="off"/>+ <p class="help-block"></p>+ </div>+ <form role="form" data-toggle="validator">+ <div class="form-group">+ <label class="control-label" for="tags">2. <span data-i18n="addTagLabel">Add Tags</span></label>+ <input class="form-control" type="text" name="tags" id="tags" autocomplete="off"/>+ <p class="help-block" data-i18n="addTagHelp">Tags should have a minimum length of 2 characters and should not contain special characters such as spaces, #, / ,\ and other.</p>+ </div>+ </form>+ <label>3. <span data-i18n="saveFileLabel">Save as File</span></label>+ <div class="btn-toolbar text-center noWrap">+ <a href="#" class="btn btn-primary" id="saveAsMhtml" data-i18n-title="saveAsMhtmlTitle">+ <i class="fa fa-file fa-lg fa-fw"></i> <span data-i18n="saveAsMhtmlLabel">Save Whole Page</span>+ </a>+ <a href="#" class="btn btn-primary" id="saveSelectionAsHtml" data-i18n-title="saveSelectionAsHtmlTitle">+ <i class="fa fa-file-text fa-lg fa-fw"></i> <span data-i18n="saveAsSelectionLabel">Save Selected</span>+ </a>+ <a href="#" class="btn btn-primary" id="saveScreenshot" data-i18n-title="saveScreenshotTitle">+ <i class="fa fa-camera fa-lg fa-fw"></i> <span data-i18n="saveScreenshotLabel">ScreenShoot</span>+ </a>+ </div>+</div>+<script type="text/javascript" src="libs/jquery/jquery-2.1.1.min.js"></script>+<script type="text/javascript" src="libs/bootstrap/js/bootstrap.min.js"></script>+<script type="text/javascript" src="libs/filesaver.js/FileSaver.js"></script>+<script type="text/javascript" src="libs/i18next/i18next.amd.withJQuery-1.7.2.min.js"></script>+<script type="text/javascript" src="libs/select2/select2.min.js"></script>+<script type="text/javascript" src="libs/dompurify/purify.js"></script>+</body>+</html>\ No newline at end of filediff --git a/data/popup.html b/data/popup.htmlindex ba5b2c229..e146547fe 100644--- a/data/popup.html+++ b/data/popup.html@@ -53,8 +53,6 @@ can be found in the LICENSE file.<script type="text/javascript" src="libs/i18next/i18next.amd.withJQuery-1.7.2.min.js"></script><script type="text/javascript" src="libs/select2/select2.min.js"></script><script type="text/javascript" src="libs/dompurify/purify.js"></script>-<!--<script type="text/javascript" src="chromelight/popup.js"></script>---></body></html>\ No newline at end of file