2013-10-25 20:16:03 +00:00
|
|
|
/*\
|
2013-11-08 08:47:00 +00:00
|
|
|
title: $:/core/modules/widgets/browse.js
|
2013-10-25 20:16:03 +00:00
|
|
|
type: application/javascript
|
2013-11-08 08:47:00 +00:00
|
|
|
module-type: widget
|
2013-10-25 20:16:03 +00:00
|
|
|
|
|
|
|
Browse widget for browsing for files to import
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2013-11-08 08:47:00 +00:00
|
|
|
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
2013-10-25 20:16:03 +00:00
|
|
|
|
|
|
|
var BrowseWidget = function(parseTreeNode,options) {
|
|
|
|
this.initialise(parseTreeNode,options);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Inherit from the base widget class
|
|
|
|
*/
|
|
|
|
BrowseWidget.prototype = new Widget();
|
|
|
|
|
|
|
|
/*
|
|
|
|
Render this widget into the DOM
|
|
|
|
*/
|
|
|
|
BrowseWidget.prototype.render = function(parent,nextSibling) {
|
|
|
|
var self = this;
|
|
|
|
// Remember parent
|
|
|
|
this.parentDomNode = parent;
|
|
|
|
// Compute attributes and execute state
|
|
|
|
this.computeAttributes();
|
|
|
|
this.execute();
|
|
|
|
// Create element
|
|
|
|
var domNode = this.document.createElement("input");
|
|
|
|
domNode.setAttribute("type","file");
|
2014-09-10 20:54:52 +00:00
|
|
|
if(this.browseMultiple) {
|
|
|
|
domNode.setAttribute("multiple","multiple");
|
|
|
|
}
|
2014-12-02 19:16:38 +00:00
|
|
|
if(this.tooltip) {
|
|
|
|
domNode.setAttribute("title",this.tooltip);
|
|
|
|
}
|
2015-01-11 14:20:34 +00:00
|
|
|
if(this.nwsaveas) {
|
|
|
|
domNode.setAttribute("nwsaveas",this.nwsaveas);
|
|
|
|
}
|
2013-10-25 20:16:03 +00:00
|
|
|
// Add a click event handler
|
|
|
|
domNode.addEventListener("change",function (event) {
|
2014-10-20 15:53:42 +00:00
|
|
|
if(self.message) {
|
2015-01-11 14:20:34 +00:00
|
|
|
self.dispatchEvent({type: self.message, param: self.param, files: event.target.files});
|
2014-10-20 13:57:15 +00:00
|
|
|
} else {
|
2014-10-20 15:53:42 +00:00
|
|
|
self.wiki.readFiles(event.target.files,function(tiddlerFieldsArray) {
|
|
|
|
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)});
|
|
|
|
});
|
2014-10-20 13:57:15 +00:00
|
|
|
}
|
2014-10-20 15:53:42 +00:00
|
|
|
return false;
|
2013-10-25 20:16:03 +00:00
|
|
|
},false);
|
|
|
|
// Insert element
|
|
|
|
parent.insertBefore(domNode,nextSibling);
|
|
|
|
this.renderChildren(domNode,null);
|
|
|
|
this.domNodes.push(domNode);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Compute the internal state of the widget
|
|
|
|
*/
|
|
|
|
BrowseWidget.prototype.execute = function() {
|
2014-09-10 20:54:52 +00:00
|
|
|
this.browseMultiple = this.getAttribute("multiple");
|
2014-10-20 13:57:15 +00:00
|
|
|
this.message = this.getAttribute("message");
|
2015-01-11 14:20:34 +00:00
|
|
|
this.param = this.getAttribute("param");
|
2014-12-02 19:16:38 +00:00
|
|
|
this.tooltip = this.getAttribute("tooltip");
|
2015-01-11 14:20:34 +00:00
|
|
|
this.nwsaveas = this.getAttribute("nwsaveas");
|
2013-10-25 20:16:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
|
|
|
*/
|
|
|
|
BrowseWidget.prototype.refresh = function(changedTiddlers) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.browse = BrowseWidget;
|
|
|
|
|
|
|
|
})();
|