This repository has been archived by the owner on Oct 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
extension.js
128 lines (109 loc) · 3.95 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* Copyright (c) 2015-2016 The TagSpaces Authors.
* Use of this source code is governed by the MIT license which can be found in the LICENSE.txt file. */
define(function(require, exports, module) {
"use strict";
var extensionTitle = "ImageSwiper"; // should be equal to the name in the bower.json
var extensionID = "perspectiveImageSwiper"; // ID should be equal to the directory name where the ext. is located
var extensionIcon = "fa fa-image"; // icon class from font awesome
console.log("Loading " + extensionID);
var TSCORE = require("tscore");
var extensionDirectory = TSCORE.Config.getExtensionPath() + "/" + extensionID;
var UI;
var $viewContainer = $("#" + extensionID + "Container");
var homeScreen;
var template;
var UI;
var aboutContent;
var extensionLoaded;
function init() {
console.log("Initializing perspective " + extensionID);
$viewContainer = $("#" + extensionID + "Container").empty();
extensionLoaded = new Promise(function(resolve, reject) {
require([
extensionDirectory + "/perspectiveUI.js",
"text!" + extensionDirectory + "/extension.html",
"css!" + extensionDirectory + "/libs/photoswipe/dist/photoswipe.css",
"css!" + extensionDirectory + "/libs/photoswipe/dist/default-skin/default-skin.css",
"css!" + extensionDirectory + "/extension.css",
], function(perspectiveUI, tmpl) {
UI = perspectiveUI;
template = tmpl;
UI.initUI(extensionDirectory);
resolve(true);
}
);
});
}
function load() {
console.log("Loading perspective " + extensionID);
extensionLoaded.then(function() {
UI.load($viewContainer, template);
platformTuning();
$('#' + extensionID + 'Container [data-i18n]').i18n();
TSCORE.hideLoadingAnimation();
try {
require(["marked"], function(marked) {
$('#aboutExtensionModalImageSwiper').on('show.bs.modal', function() {
$.ajax({
url: extensionDirectory + '/README.md',
type: 'GET'
})
.done(function(mdData) {
var modalBody = $("#aboutExtensionModalImageSwiper .modal-body");
TSCORE.Utils.setMarkDownContent(modalBody, mdData);
})
.fail(function(data) {
console.warn("Loading file failed " + data);
});
});
});
} catch (err) {
console.log("Failed translating extension");
}
});
}
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), "*");
});
});
}
function platformTuning() {
// TODO handle tap events cordova, handle key event: left & right arrows switch the image underneeth
// if (isCordova) {
$('#imageSwipperTagButton').hide();
$('#imageSwipperRenameButton').hide();
// }
}
function clearSelectedFiles() {}
function removeFileUI(filePath) {}
function updateFileUI(oldFilePath, newFilePath) {
UI.updateFileUI(oldFilePath, newFilePath);
}
function getNextFile(filePath) {}
function getPrevFile(filePath) {}
function setReadOnly(filePath) {
$('#imageSwipperTagButton').hide();
$("#imageSwipperRenameButton").hide();
$(document).off('drop dragend dragenter dragover dragleave', function(event) {
event.preventDefault();
});
}
// API Vars
exports.Title = extensionTitle;
exports.ID = extensionID;
exports.Icon = extensionIcon;
// API Methods
exports.init = init;
exports.load = load;
exports.clearSelectedFiles = clearSelectedFiles;
exports.getNextFile = getNextFile;
exports.getPrevFile = getPrevFile;
exports.removeFileUI = removeFileUI;
exports.updateFileUI = updateFileUI;
exports.setReadOnly = setReadOnly;
});