-
Notifications
You must be signed in to change notification settings - Fork 1
/
browse-wrap.js
110 lines (90 loc) · 3 KB
/
browse-wrap.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
/*\
title: $:/plugins/FSpark/file-uploads-Aliyun-OSS/browse-wrap.js
type: application/javascript
module-type: widget
Browse wrapper widget
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget;
var BrowseWrapWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};
/*
Inherit from the base widget class
*/
BrowseWrapWidget.prototype = new Widget();
/*
Render this widget into the DOM
*/
BrowseWrapWidget.prototype.render = function(parent,nextSibling) {
var self = this,
readFileCallback = function(tiddlerFieldsArray) {
self.readFileCallback(tiddlerFieldsArray);
};
this.addEventListener( "tm-browse-wrap", function(event){
this.wiki.readFiles(event.files,{
callback: readFileCallback,
deserializer: this.dropzoneDeserializer
});
}
);
this.parentDomNode = parent;
this.computeAttributes();
this.execute();
var domNode = this.document.createElement("div");
domNode.setAttribute("class","tc-file-input-wrapper");
parent.parentNode.insertBefore(domNode,parent.nextElementSibling);
domNode.appendChild(parent);
domNode = this.document.createElement("div");
parent.insertBefore(domNode,nextSibling);
this.renderChildren(domNode,null);
this.domNodes.push(domNode);
};
/*
Compute the internal state of the widget
*/
BrowseWrapWidget.prototype.execute = function() {
this.importTitle = this.getAttribute("importTitle");
this.contentTypesFilter = this.getAttribute("contentTypesFilter");
this.autoOpenOnImport = this.getAttribute("autoOpenOnImport");
this.actions = this.getAttribute("actions");
this.dropzoneDeserializer = this.getAttribute("deserializer");
this.makeChildWidgets();
};
/*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/
BrowseWrapWidget.prototype.refresh = function(changedTiddlers) {
return this.refreshChildren(changedTiddlers);
};
BrowseWrapWidget.prototype.filterByContentTypes = function(tiddlerFieldsArray) {
var filteredTypes,
filtered = [],
types = [];
$tw.utils.each(tiddlerFieldsArray,function(tiddlerFields) {
types.push(tiddlerFields.type || "");
});
filteredTypes = this.wiki.filterTiddlers(this.contentTypesFilter,this,this.wiki.makeTiddlerIterator(types));
$tw.utils.each(tiddlerFieldsArray,function(tiddlerFields) {
if(filteredTypes.indexOf(tiddlerFields.type) !== -1) {
filtered.push(tiddlerFields);
}
});
return filtered;
};
BrowseWrapWidget.prototype.readFileCallback = function(tiddlerFieldsArray) {
if(this.contentTypesFilter) {
tiddlerFieldsArray = this.filterByContentTypes(tiddlerFieldsArray);
}
if(tiddlerFieldsArray.length) {
this.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray), autoOpenOnImport: this.autoOpenOnImport, importTitle: this.importTitle});
if(this.actions) {
this.invokeActionString(this.actions,this,event,{importTitle: this.importTitle});
}
}
};
exports.bwrap = BrowseWrapWidget;
})();