TagSpaces is an offline, open source, document manager with tagging support
code styling
uggrock23872df17eee
diff --git a/data/ext/perspectiveGraph/bilevelPartition.js b/data/ext/perspectiveGraph/bilevelPartition.jsindex 80902d3a6..9df0938b3 100644--- a/data/ext/perspectiveGraph/bilevelPartition.js+++ b/data/ext/perspectiveGraph/bilevelPartition.js@@ -3,159 +3,169 @@* can be found in the LICENSE file. */define(function(require, exports, module) {-"use strict";- console.log("Loading Quantified Self");-- var TSCORE = require("tscore");-- require("d3");-- // Based on http://bl.ocks.org/mbostock/5944371- var drawPartition = function(svg, treeData) {-- var margin = {top: 350, right: 480, bottom: 350, left: 480},- radius = Math.min(margin.top, margin.right, margin.bottom, margin.left);-- var hue = d3.scale.category10();-- var luminance = d3.scale.sqrt()- .domain([0, 1e6])- .clamp(true)- .range([90, 20]);-- svg.append("g")- .attr("transform", "translate(.5,.5)");-- var partition = d3.layout.partition()- .sort(function(a, b) { return d3.ascending(a.name, b.name); })- .size([2 * Math.PI, radius]);-- var arc = d3.svg.arc()- .startAngle(function(d) { return d.x; })- .endAngle(function(d) { return d.x + d.dx; })- .innerRadius(function(d) { return radius / 3 * d.depth; })- .outerRadius(function(d) { return radius / 3 * (d.depth + 1); });--- // Compute the initial layout on the entire tree to sum sizes.- // Also compute the full name and fill color for each node.- partition- .value(function(d) { return d.size; })- .nodes(treeData)- .forEach(function(d) { d.sum = d.value; d.key = key(d); d.fill = fill(d); });-- // Now redefine the value function to use the previously-computed sum.- partition- .children(function(d, depth) { return depth < 2 ? d.children : null; })- .value(function(d) { return d.sum; });-- var center = svg.append("circle")- .attr("r", radius / 3)- .on("click", zoomOut);-- center.append("title")- .text("zoom out");-- var path = svg.selectAll("path")- .data(partition.nodes(treeData).slice(1))- .enter().append("path")- .attr("d", arc)- .style("fill", function(d) { return d.fill; })- .each(function(d) { this._current = updateArc(d); })- .on("click", zoomIn);-- function zoomIn(p) {- if (p.depth > 1) p = p.parent;- if (!p.children) return;- zoom(p, p);- }-- function zoomOut(p) {- if (!p.parent) return;- zoom(p.parent, p);- }-- // Zoom to the specified new root.- function zoom(root, p) {- if (document.documentElement.__transition__) return;-- // Stash the original root dimensions for transitions.- var angle1 = d3.scale.linear()- .domain([0, 2 * Math.PI])- .range([root.x, root.x + root.dx]);-- function insideArc(d) {- return p.key > d.key- ? {depth: d.depth - 1, x: 0, dx: 0} : p.key < d.key- ? {depth: d.depth - 1, x: 2 * Math.PI, dx: 0}- : {depth: 0, x: 0, dx: 2 * Math.PI};- }-- function outsideArc(d) {- return {depth: d.depth + 1, x: angle1(d.x), dx: angle1(d.x + d.dx) - angle1(d.x)};- }-- // When zooming in, arcs enter from the outside and exit to the inside.- // When zooming out, arcs enter from the inside and exit to the outside.- var enterArc = root === p ? outsideArc : insideArc,- exitArc = root === p ? insideArc : outsideArc;-- center.datum(root);-- d3.transition().duration(750).each(function() {- path = path.data(partition.nodes(root).slice(1), function(d) { return d.key; });-- path.transition()- .attrTween("d", function(d) { return arcTween.call(this, updateArc(d)); });-- path.enter().append("path")- .style("fill-opacity", 0)- .style("fill", function(d) { return d.fill; })- .on("click", zoomIn)- .each(function(d) { this._current = enterArc(d); })- .transition()- .style("fill-opacity", 1)- .attrTween("d", function(d) { return arcTween.call(this, updateArc(d)); });-- path.exit().transition()- .style("fill-opacity", 0)- .attrTween("d", function(d) { return arcTween.call(this, exitArc(d)); })- .remove();- });- }-- function key(d) {- var k = [], p = d;- while (p.depth) k.push(p.name), p = p.parent;- return k.reverse().join(".");+ "use strict";++ console.log("Loading Quantified Self");++ var TSCORE = require("tscore");++ require("d3");++ // Based on http://bl.ocks.org/mbostock/5944371+ var drawPartition = function(svg, treeData) {++ var margin = {top: 350, right: 480, bottom: 350, left: 480},+ radius = Math.min(margin.top, margin.right, margin.bottom, margin.left);++ var hue = d3.scale.category10();++ var luminance = d3.scale.sqrt()+ .domain([0, 1e6])+ .clamp(true)+ .range([90, 20]);++ svg.append("g")+ .attr("transform", "translate(.5,.5)");++ var partition = d3.layout.partition()+ .sort(function(a, b) { return d3.ascending(a.name, b.name); })+ .size([2 * Math.PI, radius]);++ var arc = d3.svg.arc()+ .startAngle(function(d) { return d.x; })+ .endAngle(function(d) { return d.x + d.dx; })+ .innerRadius(function(d) { return radius / 3 * d.depth; })+ .outerRadius(function(d) { return radius / 3 * (d.depth + 1); });+++ // Compute the initial layout on the entire tree to sum sizes.+ // Also compute the full name and fill color for each node.+ partition+ .value(function(d) { return d.size; })+ .nodes(treeData)+ .forEach(function(d) { d.sum = d.value; d.key = key(d); d.fill = fill(d); });++ // Now redefine the value function to use the previously-computed sum.+ partition+ .children(function(d, depth) { return depth < 2 ? d.children : null; })+ .value(function(d) { return d.sum; });++ var center = svg.append("circle")+ .attr("r", radius / 3)+ .on("click", zoomOut);++ center.append("title")+ .text("zoom out");++ var path = svg.selectAll("path")+ .data(partition.nodes(treeData).slice(1))+ .enter().append("path")+ .attr("d", arc)+ .style("fill", function(d) { return d.fill; })+ .each(function(d) { this._current = updateArc(d); })+ .on("click", zoomIn);++ function zoomIn(p) {+ if (p.depth > 1) {+ p = p.parent;}-- function fill(d) {- var p = d;- while (p.depth > 1) p = p.parent;- var c = d3.lab(hue(p.name));- c.l = luminance(d.sum);- return c;+ if (!p.children) {+ return;}-- function arcTween(b) {- var i = d3.interpolate(this._current, b);- this._current = i(0);- return function(t) {- return arc(i(t));- };+ zoom(p, p);+ }++ function zoomOut(p) {+ if (!p.parent) {+ return;}-- function updateArc(d) {- return {depth: d.depth, x: d.x, dx: d.dx};+ zoom(p.parent, p);+ }++ // Zoom to the specified new root.+ function zoom(root, p) {+ if (document.documentElement.__transition__) {+ return;}-- d3.select(self.frameElement).style("height", margin.top + margin.bottom + "px");-- }--- // Methods- exports.drawPartition = drawPartition;++ // Stash the original root dimensions for transitions.+ var angle1 = d3.scale.linear()+ .domain([0, 2 * Math.PI])+ .range([root.x, root.x + root.dx]);++ function insideArc(d) {+ return p.key > d.key ? {depth: d.depth - 1, x: 0, dx: 0} : p.key < d.key ? {depth: d.depth - 1, x: 2 * Math.PI, dx: 0} : {depth: 0, x: 0, dx: 2 * Math.PI};+ }++ function outsideArc(d) {+ return {depth: d.depth + 1, x: angle1(d.x), dx: angle1(d.x + d.dx) - angle1(d.x)};+ }++ // When zooming in, arcs enter from the outside and exit to the inside.+ // When zooming out, arcs enter from the inside and exit to the outside.+ var enterArc = root === p ? outsideArc : insideArc,+ exitArc = root === p ? insideArc : outsideArc;++ center.datum(root);++ d3.transition().duration(750).each(function() {+ path = path.data(partition.nodes(root).slice(1), function(d) { return d.key; });++ path.transition()+ .attrTween("d", function(d) { return arcTween.call(this, updateArc(d)); });++ path.enter().append("path")+ .style("fill-opacity", 0)+ .style("fill", function(d) { return d.fill; })+ .on("click", zoomIn)+ .each(function(d) { this._current = enterArc(d); })+ .transition()+ .style("fill-opacity", 1)+ .attrTween("d", function(d) { return arcTween.call(this, updateArc(d)); });++ path.exit().transition()+ .style("fill-opacity", 0)+ .attrTween("d", function(d) { return arcTween.call(this, exitArc(d)); })+ .remove();+ });+ }++ function key(d) {+ var k = [], p = d;+ while (p.depth) {+ k.push(p.name);+ p = p.parent;+ }+ return k.reverse().join(".");+ }++ function fill(d) {+ var p = d;+ while (p.depth > 1) {+ p = p.parent;+ }+ var c = d3.lab(hue(p.name));+ c.l = luminance(d.sum);+ return c;+ }++ function arcTween(b) {+ var i = d3.interpolate(this._current, b);+ this._current = i(0);+ return function(t) {+ return arc(i(t));+ };+ }++ function updateArc(d) {+ return {depth: d.depth, x: d.x, dx: d.dx};+ }++ d3.select(self.frameElement).style("height", margin.top + margin.bottom + "px");++ };++ // Methods+ exports.drawPartition = drawPartition;});\ No newline at end of filediff --git a/data/ext/perspectiveGraph/extension.js b/data/ext/perspectiveGraph/extension.jsindex 631557a5b..32bbfa901 100644--- a/data/ext/perspectiveGraph/extension.js+++ b/data/ext/perspectiveGraph/extension.js@@ -23,7 +23,7 @@ define(function(require, exports, module) {var graphMode = "mindmap";- var treeData = undefined;+ var treeData;exports.init = function init() {console.log("Initializing View "+extensionID);@@ -171,25 +171,25 @@ define(function(require, exports, module) {graphMode = "treeMap";TSCORE.showLoadingAnimation();TSCORE.IO.createDirectoryTree(TSCORE.currentPath);- })+ });$("#" + extensionID + "ActivateTreeMapNaviButton").click(function() {graphMode = "treeMap2";TSCORE.showLoadingAnimation();TSCORE.IO.createDirectoryTree(TSCORE.currentPath);- })+ });$("#" + extensionID + "ActivateTreeButton").click(function() {graphMode = "tree";TSCORE.showLoadingAnimation();TSCORE.IO.createDirectoryTree(TSCORE.currentPath);- })+ });$("#" + extensionID + "ActivateBilevelPartitionButton").click(function() {graphMode = "bilevelPartition";TSCORE.showLoadingAnimation();TSCORE.IO.createDirectoryTree(TSCORE.currentPath);- })+ });};// Varsdiff --git a/data/ext/perspectiveGraph/mindmap.js b/data/ext/perspectiveGraph/mindmap.jsindex b884d3424..c08bff039 100644--- a/data/ext/perspectiveGraph/mindmap.js+++ b/data/ext/perspectiveGraph/mindmap.js@@ -38,7 +38,7 @@ define(function(require, exports, module) {d.children.forEach(toggleAll);toggle(d);}- };+ }// Initialize the display to show a few nodes.root.children.forEach(toggleAll);@@ -133,11 +133,11 @@ define(function(require, exports, module) {d.x0 = d.x;d.y0 = d.y;});- };+ }// Toggle children.function toggle(d) {- if(d.children == undefined || d.children == null) { // || d.children.length < 1+ if(d.children === undefined || d.children === null) { // || d.children.length < 1TSCORE.FileOpener.openFile(d.path);}if (d.children) {@@ -147,7 +147,7 @@ define(function(require, exports, module) {d.children = d._children;d._children = null;}- };+ }};// Methodsdiff --git a/data/ext/perspectiveGraph/treeMap.js b/data/ext/perspectiveGraph/treeMap.jsindex b0409ce9a..0af5699da 100644--- a/data/ext/perspectiveGraph/treeMap.js+++ b/data/ext/perspectiveGraph/treeMap.js@@ -3,7 +3,7 @@* can be found in the LICENSE file. */define(function(require, exports, module) {-"use strict";+ "use strict";console.log("Loading Tree Map");var TSCORE = require("tscore");@@ -88,7 +88,7 @@ define(function(require, exports, module) {t.select("rect").attr("width", function(d) { return kx * d.dx - 1; })- .attr("height", function(d) { return ky * d.dy - 1; })+ .attr("height", function(d) { return ky * d.dy - 1; });t.select("text").attr("x", function(d) { return kx * d.dx / 2; })@@ -98,7 +98,7 @@ define(function(require, exports, module) {node = d;d3.event.stopPropagation();}- }+ };// Based on http://mbostock.github.io/d3/talk/20111018/partition.html// Not working@@ -134,13 +134,14 @@ define(function(require, exports, module) {.attr("transform", transform).attr("dy", ".35em").style("opacity", function(d) { return d.dx * ky > 12 ? 1 : 0; })- .text(function(d) { return d.name; })+ .text(function(d) { return d.name; });- d3.select(window)- .on("click", function() { click(root); })+ d3.select(window).on("click", function() { click(root); });function click(d) {- if (!d.children) return;+ if (!d.children) {+ return;+ }kx = (d.y ? w - 40 : w) / (1 - d.y);ky = h / d.dx;@@ -166,8 +167,7 @@ define(function(require, exports, module) {return "translate(8," + d.dx * ky / 2 + ")";}-- }+ };// Methodsexports.drawTreeMap = drawTreeMap;diff --git a/data/ext/perspectiveGraph/treeViz.js b/data/ext/perspectiveGraph/treeViz.jsindex 8191863f3..a9b9da0d6 100644--- a/data/ext/perspectiveGraph/treeViz.js+++ b/data/ext/perspectiveGraph/treeViz.js@@ -3,7 +3,7 @@* can be found in the LICENSE file. */define(function(require, exports, module) {-"use strict";+ "use strict";console.log("Loading Quantified Self");var TSCORE = require("tscore");@@ -35,7 +35,7 @@ define(function(require, exports, module) {.data(nodes).enter().append("g").attr("class", "node")- .attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })+ .attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; });node.append("circle").attr("r", 4.5);@@ -48,7 +48,7 @@ define(function(require, exports, module) {d3.select(self.frameElement).style("height", diameter - 150 + "px");- }+ };var drawTree = function(svg, treeData) {@@ -75,7 +75,7 @@ define(function(require, exports, module) {.data(nodes).enter().append("g").attr("class", "node")- .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })+ .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; });node.append("circle").attr("r", 4.5);@@ -87,7 +87,7 @@ define(function(require, exports, module) {.text(function(d) { return d.name; });d3.select(self.frameElement).style("height", svg.attr("height") + "px");- }+ };var drawTreeMap2 = function(svg, treeData) {var margin = {top: 40, right: 10, bottom: 10, left: 10},@@ -117,15 +117,13 @@ define(function(require, exports, module) {.text(function(d) { return d.children ? null : d.name; });d3.selectAll("input").on("change", function change() {- var value = this.value === "count"- ? function() { return 1; }- : function(d) { return d.size; };+ var value = this.value === "count" ? function() { return 1; } : function(d) { return d.size; };node- .data(treemap.value(value).nodes)+ .data(treemap.value(value).nodes).transition()- .duration(1500)- .call(position);+ .duration(1500)+ .call(position);});@@ -134,8 +132,8 @@ define(function(require, exports, module) {.style("top", function(d) { return d.y + "px"; }).style("width", function(d) { return Math.max(0, d.dx - 1) + "px"; }).style("height", function(d) { return Math.max(0, d.dy - 1) + "px"; });- }- }+ };+ };var drawTreeMapZoom = function(svg, treeData) {// http://bl.ocks.org/mbostock/raw/1005873/e741416b4271859f1dfb3e0440d2f20bfc989e27/@@ -176,7 +174,7 @@ define(function(require, exports, module) {.attr("height", function(d) { return y(d.y + d.dy) - y(d.y); });}});- }+ };var drawTreeMap = function(svg, treeData) {svg.append("g");@@ -190,24 +188,24 @@ define(function(require, exports, module) {var color = d3.scale.category20();- svg.selectAll(".node")- .data(nodes)- .enter().append("rect")- .attr("class", "node")- .attr("x", function(d) { return d.x; })- .attr("y", function(d) { return d.y; })- .attr("width", function(d) { return d.dx; })- .attr("height", function(d) { return d.dy; })- .style("fill", function(d) { return color((d.children ? d : d.parent).name); });-- svg.selectAll(".label")- .data(nodes.filter(function(d) { return d.dx > 6; }))- .enter().append("text")- .attr("class", "label")- .attr("dy", ".35em")- .attr("transform", function(d) { return "translate(" + (d.x + d.dx / 2) + "," + (d.y + d.dy / 2) + ")rotate(90)"; })- .text(function(d) { return d.name; });- }+ svg.selectAll(".node")+ .data(nodes)+ .enter().append("rect")+ .attr("class", "node")+ .attr("x", function(d) { return d.x; })+ .attr("y", function(d) { return d.y; })+ .attr("width", function(d) { return d.dx; })+ .attr("height", function(d) { return d.dy; })+ .style("fill", function(d) { return color((d.children ? d : d.parent).name); });++ svg.selectAll(".label")+ .data(nodes.filter(function(d) { return d.dx > 6; }))+ .enter().append("text")+ .attr("class", "label")+ .attr("dy", ".35em")+ .attr("transform", function(d) { return "translate(" + (d.x + d.dx / 2) + "," + (d.y + d.dy / 2) + ")rotate(90)"; })+ .text(function(d) { return d.name; });+ };// Methodsexports.drawTreeMap = drawTreeMap;diff --git a/data/ext/perspectiveImageSwiper/extension.js b/data/ext/perspectiveImageSwiper/extension.jsindex 8ab3f0ef6..6c8167cc5 100644--- a/data/ext/perspectiveImageSwiper/extension.js+++ b/data/ext/perspectiveImageSwiper/extension.js@@ -20,7 +20,7 @@ define(function(require, exports, module) {var extensionDirectory = TSCORE.Config.getExtensionPath() + "/" + extensionID;var UI;- var $viewContainer = $("#"+extensionID+"Container");+ var $viewContainer = $("#" + extensionID + "Container");var homeScreen;var template;var UI;@@ -28,14 +28,14 @@ define(function(require, exports, module) {var init = function() {console.log("Initializing perspective " + extensionID);- $viewContainer = $("#"+extensionID+"Container").empty();+ $viewContainer = $("#" + extensionID + "Container").empty();require([- extensionDirectory+"/perspectiveUI.js",- "text!"+extensionDirectory + "/galleryTMPL.html",- "css!"+extensionDirectory + "/gallery.css",- "css!"+extensionDirectory + "/dist/photoswipe.css",- "css!"+extensionDirectory + "/dist/default-skin/default-skin.css"+ extensionDirectory + "/perspectiveUI.js",+ "text!" + extensionDirectory + "/galleryTMPL.html",+ "css!" + extensionDirectory + "/gallery.css",+ "css!" + extensionDirectory + "/dist/photoswipe.css",+ "css!" + extensionDirectory + "/dist/default-skin/default-skin.css"], function(perspectiveUI, tmpl) {UI = perspectiveUI;template = tmpl;@@ -62,13 +62,13 @@ define(function(require, exports, module) {var updateFileUI = function(oldFilePath, newFilePath) {};- var getNextFile = function (filePath) {};+ var getNextFile = function(filePath) {};- var getPrevFile = function (filePath) {};+ var getPrevFile = function(filePath) {};- exports.updateTreeData = function updateIndexData(fsTreeData) {- console.log("Updating tree data not implemented");- };+ exports.updateTreeData = function updateIndexData(fsTreeData) {+ console.log("Updating tree data not implemented");+ };// Varsexports.Title = extensionTitle;diff --git a/data/ext/perspectiveImageSwiper/perspectiveUI.js b/data/ext/perspectiveImageSwiper/perspectiveUI.jsindex 1aae32cc0..3c7033241 100644--- a/data/ext/perspectiveImageSwiper/perspectiveUI.js+++ b/data/ext/perspectiveImageSwiper/perspectiveUI.js@@ -1,222 +1,211 @@define(function(require, exports, module) {"use strict";- var TSCORE = require("tscore");- var extDir;- var supportedFileTypesThumbs = ['jpg','jpeg','png','gif','bmp','svg'];- var defaultThumnailPath;-- function initUI(dir) {- extDir = dir;- defaultThumnailPath = extDir + "/default.png";- }-- function loadThumbnail(fileName) {-- var name = TSCORE.Utils.baseName(fileName);- var res = null;- TSCORE.metaFileList.forEach(function(element) {- if(element.name.indexOf(name) >= 0) {- res = element.path;- }- });-- return res;- }-- function load(container, template, files) {- var data = [];- var compiledTemplate = Handlebars.compile(template);- files.forEach(function(fileInfo) {- var ext = fileInfo[TSCORE.fileListFILEEXT];-- if(supportedFileTypesThumbs.indexOf(ext) !== -1) {- var filePath = fileInfo[TSCORE.fileListFILEPATH];- var doc = {- name: fileInfo[TSCORE.fileListFILENAME],- path: encodeURI("file://" + filePath),- thumbnail: encodeURI(defaultThumnailPath),- title: fileInfo[TSCORE.fileListTITLE]- }-- var metaFilePath = TSCORE.Meta.findMetaFilebyPath(filePath, "png");- if(metaFilePath) {- doc.thumbnail = encodeURI("file://" + metaFilePath);- }- /*var thumb = loadThumbnail(doc.path);- if(thumb) {- doc.thumbnail = encodeURI("file://" + thumb);- }*/- data.push(doc);- }- });-- var html = compiledTemplate({data: data});- container.append(html);- initPhotoSwipeFromDOM('.my-gallery');- }-- exports.initUI = initUI;- exports.load = load;-- var initPhotoSwipeFromDOM = function(gallerySelector) {-- // parse slide data (url, title, size ...) from DOM elements- // (children of gallerySelector)- var parseThumbnailElements = function(el) {- var thumbElements = el.childNodes,- numNodes = thumbElements.length,- items = [],- figureEl,- linkEl,- size,- item;-- for(var i = 0; i < numNodes; i++) {-- figureEl = thumbElements[i]; // <figure> element-- // include only element nodes- if(figureEl.nodeType !== 1) {- continue;- }-- linkEl = figureEl.children[0]; // <a> element-- size = [0,0]; //linkEl.getAttribute('data-size').split('x');-- // create slide object- item = {- src: linkEl.getAttribute('href'),- w: parseInt(size[0], 10),- h: parseInt(size[1], 10)- };-- if(figureEl.children.length > 1) {- // <figcaption> content- item.title = figureEl.children[1].innerHTML;- }-- if(linkEl.children.length > 0) {- // <img> thumbnail element, retrieving thumbnail url- item.msrc = linkEl.children[0].getAttribute('src');- }-- item.el = figureEl; // save link to element for getThumbBoundsFn- items.push(item);- }-- return items;- };-- // find nearest parent element- var closest = function closest(el, fn) {- return el && ( fn(el) ? el : closest(el.parentNode, fn) );+ var TSCORE = require("tscore");+ var extDir;+ var supportedFileTypesThumbs = ['jpg' , 'jpeg' , 'png' , 'gif' , 'bmp' , 'svg'];+ var defaultThumnailPath;++ function initUI(dir) {+ extDir = dir;+ defaultThumnailPath = extDir + "/default.png";+ }++ function loadThumbnail(fileName) {+ var name = TSCORE.Utils.baseName(fileName);+ var res = null;+ TSCORE.metaFileList.forEach(function(element) {+ if (element.name.indexOf(name) >= 0) {+ res = element.path;+ }+ });+ return res;+ }++ function load(container, template, files) {+ var data = [];+ var compiledTemplate = Handlebars.compile(template);+ files.forEach(function(fileInfo) {+ var ext = fileInfo[TSCORE.fileListFILEEXT];++ if (supportedFileTypesThumbs.indexOf(ext) !== -1) {+ var filePath = fileInfo[TSCORE.fileListFILEPATH];+ var doc = {+ name: fileInfo[TSCORE.fileListFILENAME],+ path: encodeURI("file://" + filePath),+ thumbnail: encodeURI(defaultThumnailPath),+ title: fileInfo[TSCORE.fileListTITLE]};- // triggers when user clicks on thumbnail- var onThumbnailsClick = function(e) {- e = e || window.event;- e.preventDefault ? e.preventDefault() : e.returnValue = false;-- var eTarget = e.target || e.srcElement;-- // find root element of slide- var clickedListItem = closest(eTarget, function(el) {- return (el.tagName && el.tagName.toUpperCase() === 'FIGURE');- });-- if(!clickedListItem) {- return;- }-- // find index of clicked item by looping through all child nodes- // alternatively, you may define index via data- attribute- var clickedGallery = clickedListItem.parentNode,- childNodes = clickedListItem.parentNode.childNodes,- numChildNodes = childNodes.length,- nodeIndex = 0,- index;-- for (var i = 0; i < numChildNodes; i++) {- if(childNodes[i].nodeType !== 1) {- continue;- }-- if(childNodes[i] === clickedListItem) {- index = nodeIndex;- break;- }- nodeIndex++;- }-- if(index >= 0) {- // open PhotoSwipe if valid index found- openPhotoSwipe( index, clickedGallery );- }- return false;- };-- var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) {- var pswpElement = document.querySelectorAll('.pswp')[0],- gallery, options;-- var items = parseThumbnailElements(galleryElement);+ var metaFilePath = TSCORE.Meta.findMetaFilebyPath(filePath, "png");+ if (metaFilePath) {+ doc.thumbnail = encodeURI("file://" + metaFilePath);+ }+ data.push(doc);+ }+ });++ var html = compiledTemplate({data: data});+ container.append(html);+ initPhotoSwipeFromDOM('.my-gallery');+ }++ exports.initUI = initUI;+ exports.load = load;++ var initPhotoSwipeFromDOM = function(gallerySelector) {++ // parse slide data (url, title, size ...) from DOM elements+ // (children of gallerySelector)+ var parseThumbnailElements = function(el) {+ var thumbElements = el.childNodes,+ numNodes = thumbElements.length,+ items = [],+ figureEl,+ linkEl,+ size,+ item;++ for (var i = 0; i < numNodes; i++) {+ figureEl = thumbElements[i]; // <figure> element++ // include only element nodes+ if (figureEl.nodeType !== 1) {+ continue;+ }- options = {- // define gallery index (for URL)- galleryUID: galleryElement.getAttribute('data-pswp-uid'),+ linkEl = figureEl.children[0]; // <a> element- getThumbBoundsFn: function(index) {- // See Options -> getThumbBoundsFn section of documentation for more info- var thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnail- pageYScroll = window.pageYOffset || document.documentElement.scrollTop,- rect = thumbnail.getBoundingClientRect();+ size = [0, 0]; //linkEl.getAttribute('data-size').split('x');- return {x:rect.left, y:rect.top + pageYScroll, w:rect.width};- },- shareEl: false- };+ // create slide object+ item = {+ src: linkEl.getAttribute('href'),+ w: parseInt(size[0], 10),+ h: parseInt(size[1], 10)+ };- options.index = parseInt(index, 10);+ if (figureEl.children.length > 1) {+ // <figcaption> content+ item.title = figureEl.children[1].innerHTML;+ }- // exit if index not found- if( isNaN(options.index) ) {- console.log("PhotoSwipe error: index not found");- return;- }+ if (linkEl.children.length > 0) {+ // <img> thumbnail element, retrieving thumbnail url+ item.msrc = linkEl.children[0].getAttribute('src');+ }- if(disableAnimation) {- options.showAnimationDuration = 0;- }+ item.el = figureEl; // save link to element for getThumbBoundsFn+ items.push(item);+ }- require([- extDir + "/dist/photoswipe.js",- extDir + "/dist/photoswipe-ui-default.js",- ], function( PhotoSwipe, PhotoSwipeUI_Default ) {+ return items;+ };- gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);- gallery.init();+ // find nearest parent element+ var closest = function closest(el, fn) {+ return el && (fn(el) ? el : closest(el.parentNode, fn));+ };- gallery.listen('imageLoadComplete', function(index, item) {+ // triggers when user clicks on thumbnail+ var onThumbnailsClick = function(e) {+ e = e || window.event;+ e.preventDefault ? e.preventDefault() : e.returnValue = false;++ var eTarget = e.target || e.srcElement;++ // find root element of slide+ var clickedListItem = closest(eTarget, function(el) {+ return (el.tagName && el.tagName.toUpperCase() === 'FIGURE');+ });++ if (!clickedListItem) {+ return;+ }++ // find index of clicked item by looping through all child nodes+ // alternatively, you may define index via data- attribute+ var clickedGallery = clickedListItem.parentNode,+ childNodes = clickedListItem.parentNode.childNodes,+ numChildNodes = childNodes.length,+ nodeIndex = 0,+ index;++ for (var i = 0; i < numChildNodes; i++) {+ if (childNodes[i].nodeType !== 1) {+ continue;+ }- var img = new Image();- img.src = item.src;- item.w = img.width;- item.h = img.height;- gallery.updateSize(true);- img = undefined;- });+ if (childNodes[i] === clickedListItem) {+ index = nodeIndex;+ break;+ }+ nodeIndex++;+ }++ if (index >= 0) {+ // open PhotoSwipe if valid index found+ openPhotoSwipe(index, clickedGallery);+ }+ return false;+ };- });- };+ var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) {+ var pswpElement = document.querySelectorAll('.pswp')[0],+ gallery, options;++ var items = parseThumbnailElements(galleryElement);++ options = {+ // define gallery index (for URL)+ galleryUID: galleryElement.getAttribute('data-pswp-uid'),++ getThumbBoundsFn: function(index) {+ // See Options -> getThumbBoundsFn section of documentation for more info+ var thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnail+ pageYScroll = window.pageYOffset || document.documentElement.scrollTop,+ rect = thumbnail.getBoundingClientRect();++ return {x:rect.left, y:rect.top + pageYScroll, w:rect.width};+ },+ shareEl: false+ };++ options.index = parseInt(index, 10);++ // exit if index not found+ if (isNaN(options.index)) {+ console.log("PhotoSwipe error: index not found");+ return;+ }++ if (disableAnimation) {+ options.showAnimationDuration = 0;+ }++ require([+ extDir + "/dist/photoswipe.js",+ extDir + "/dist/photoswipe-ui-default.js",+ ], function(PhotoSwipe, PhotoSwipeUI_Default) {+ gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);+ gallery.init();+ gallery.listen('imageLoadComplete', function(index, item) {+ var img = new Image();+ img.src = item.src;+ item.w = img.width;+ item.h = img.height;+ gallery.updateSize(true);+ img = undefined;+ });+ });+ };- // loop through all gallery elements and bind events- var galleryElements = document.querySelectorAll( gallerySelector );+ // loop through all gallery elements and bind events+ var galleryElements = document.querySelectorAll(gallerySelector);- for(var i = 0, l = galleryElements.length; i < l; i++) {- galleryElements[i].setAttribute('data-pswp-uid', i+1);- galleryElements[i].onclick = onThumbnailsClick;- }- };+ for (var i = 0, l = galleryElements.length; i < l; i++) {+ galleryElements[i].setAttribute('data-pswp-uid', i + 1);+ galleryElements[i].onclick = onThumbnailsClick;+ }+ };});\ No newline at end of file