TagSpaces is an offline, open source, document manager with tagging support
adding extCommon library
uggrock401700b6a9c8
diff --git a/data/libs/extCommon/LICENSE.txt b/data/libs/extCommon/LICENSE.txtnew file mode 100644index 000000000..f754b3f0a--- /dev/null+++ b/data/libs/extCommon/LICENSE.txt@@ -0,0 +1,8 @@+The MIT License (MIT)+Copyright (c) 2016 Ilian Sapundshiev++Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.diff --git a/data/libs/extCommon/README.md b/data/libs/extCommon/README.mdnew file mode 100644index 000000000..7c55af0b4--- /dev/null+++ b/data/libs/extCommon/README.md@@ -0,0 +1,7 @@+## TagSpaces Extension Commons++A library containing common code needed in some of the TagSpaces extensions++## License++[MIT](https://github.com/tagspaces/viewerHTML/blob/master/LICENSE.txt)diff --git a/data/libs/extCommon/common.css b/data/libs/extCommon/common.cssnew file mode 100644index 000000000..b202a1afb--- /dev/null+++ b/data/libs/extCommon/common.css@@ -0,0 +1,50 @@+#aboutExtensionModal img {+ max-width: 100%;+}++#aboutExtensionModal h1 {+ font-size: 22px;+}++#aboutExtensionModal h2 {+ font-size: 20px;+}++#aboutExtensionModal h3 {+ font-size: 18px;+}++#aboutExtensionModal .modal-body {+ max-height: 500px;+ overflow: auto;+}++#searchText span{+ background-color:#FF9;+ color:#555;+}++#searchToolbar {+ border-radius: 0px;+ margin-left: 0px;+ min-width:99.99%;+ box-shadow: 1px 1px 3px #BBBBBB;+ border-bottom: 3px solid #F2F2F2;+ border-top: 0px;+ border-left: 0px;+ border-right: 0px;+}++.highlight {+ background-color: #FFFF88;+}++#searchExtButton {+ padding-left: 20px;+ padding-right: 20px;+}++#clearSearchExtButton {+ padding-left: 20px;+ padding-right: 20px;+}\ No newline at end of filediff --git a/data/libs/extCommon/common.js b/data/libs/extCommon/common.jsnew file mode 100644index 000000000..580cfdd9c--- /dev/null+++ b/data/libs/extCommon/common.js@@ -0,0 +1,156 @@+/* Copyright (c) 2013-2016 The TagSpaces Authors.+ * Use of this source code is governed by the MIT license which can be found in the LICENSE.txt file. */++"use strict";+/* globals Mousetrap */++var isCordova;+var isWin;+var isWeb;++$(document).ready(function() {+ isCordova = parent.isCordova;+ isWin = parent.isWin;+ isWeb = parent.isWeb;++// Disable drag events in extensions+ $(document).on('drop dragend dragenter dragover', function(event) {+ event.preventDefault();+ });++// Hide all menus in TS on click in extension+ $(document).on('click' , function(event) {+ fireHideAllMenusEvent();+ });++ function fireHideAllMenusEvent() {+ var msg = {command: "hideAllMenus"};+ window.parent.postMessage(JSON.stringify(msg), "*");+ }++// Init about box functionality+ $('#aboutExtensionModal').on('show.bs.modal', function() {+ $.ajax({+ url: 'README.md',+ type: 'GET'+ }).done(function(mdData) {+ //console.log("DATA: " + mdData);+ if (marked) {+ var modalBody = $("#aboutExtensionModal .modal-body");+ modalBody.html(marked(mdData, {sanitize: true}));+ handleLinks(modalBody);+ } else {+ console.log("markdown to html transformer not found");+ }+ }).fail(function(data) {+ console.warn("Loading file failed " + data);+ });+ });++ function handleLinks($element) {+ $element.find("a[href]").each(function() {+ var currentSrc = $(this).attr("href");+ $(this).bind('click', function(e) {+ e.preventDefault();+ var msg = {command: "openLinkExternally", link: currentSrc};+ window.parent.postMessage(JSON.stringify(msg), "*");+ });+ });+ }++ $("#aboutButton").on("click", function(e) {+ $("#aboutExtensionModal").modal({show: true});+ });++// Activating the print functionality+ $("#printButton").on("click", function(e) {+ window.print();+ });++ if (isCordova) {+ $("#printButton").hide();+ }++ initSearch();+});++function getParameterByName(name) {+ name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");+ var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search);++ return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));+}++function showSearchPanel(e) {+ //$('#searchToolbar').slideDown(500);+ $('#searchToolbar').show();+ $('#searchBox').val('');+ $('#searchBox').focus();+}++function cancelSearch() {+ //$('#searchToolbar').slideUp(500);+ $('#htmlContent').unhighlight();+ $('#searchToolbar').hide();+ //$('#searchBox').hide();+}++function initSearch() {+ $("#findInFile").on('click', function() {+ showSearchPanel();+ });++ $("#searchExtButton").on('click', function() {+ doSearch();+ });++ $('#clearSearchExtButton').on('click', function(e) {+ cancelSearch();+ });++ $('#searchBox').keyup(function(e) {+ if (e.keyCode === 13) { // Start the search on ENTER+ doSearch();+ } else if (e.keyCode == 27) { // Hide search on ESC+ cancelSearch();+ }+ });++ Mousetrap.bind(['command+f', 'ctrl+f'], function(e) {+ showSearchPanel();+ return false;+ });+}++function doSearch() {+ $('#htmlContent').unhighlight();+ $('#searchBox').attr('placeholder', 'Search');+ var givenString = document.getElementById("searchBox").value;++ var selector = $('#htmlContent') || 'body';+ var caseSensitiveString = $('#htmlContent').highlight(givenString, {wordsOnly: false});+ var found, getSelection;++ if (window.find) { // Firefox, Google Chrome, Safari+ found = window.find(givenString);+ $('#htmlContent').highlight(givenString, {wordsOnly: false});++ var searchTermRegEx = new RegExp(found, "ig");+ var matches = $(selector).text().match(searchTermRegEx);+ if (matches) {+ if ($('.highlight:first').length) {//if match found, scroll to where the first one appears+ //$(window).animate({scrollTo:($("*:contains('"+ givenString +"')").offset().top)},"fast");+ //$(selector).animate({scrollTop: $('#htmlContent .highlight::selection').offset().top}, "fast");+ //window.find(givenString);+ //$(window).animate({scrollTop: window.find(givenString)}, "fast");+ }+ }+ if (!found || (!found && !caseSensitiveString) || !caseSensitiveString) {+ var topOfContent = $(selector).animate({scrollTop: $('#htmlContent').offset().top}, "fast");+ $('#htmlContent').unhighlight();+ $('#searchBox').val('');+ $('#searchBox').attr('placeholder', 'Search text not found. Try again.');+ return topOfContent;+ }+ }+}