2013-10-15 13:32:27 +00:00
|
|
|
/*\
|
2013-11-08 08:47:00 +00:00
|
|
|
title: $:/core/modules/widgets/edit.js
|
2013-10-15 13:32:27 +00:00
|
|
|
type: application/javascript
|
2013-11-08 08:47:00 +00:00
|
|
|
module-type: widget
|
2013-10-15 13:32:27 +00:00
|
|
|
|
|
|
|
Edit widget is a meta-widget chooses the appropriate actual editting widget
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(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-15 13:32:27 +00:00
|
|
|
|
|
|
|
var EditWidget = function(parseTreeNode,options) {
|
|
|
|
this.initialise(parseTreeNode,options);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Inherit from the base widget class
|
|
|
|
*/
|
|
|
|
EditWidget.prototype = new Widget();
|
|
|
|
|
|
|
|
/*
|
|
|
|
Render this widget into the DOM
|
|
|
|
*/
|
|
|
|
EditWidget.prototype.render = function(parent,nextSibling) {
|
|
|
|
this.parentDomNode = parent;
|
|
|
|
this.computeAttributes();
|
|
|
|
this.execute();
|
|
|
|
this.renderChildren(parent,nextSibling);
|
|
|
|
};
|
|
|
|
|
2014-01-24 20:22:23 +00:00
|
|
|
// Mappings from content type to editor type are stored in tiddlers with this prefix
|
|
|
|
var EDITOR_MAPPING_PREFIX = "$:/config/EditorTypeMappings/";
|
2013-10-15 13:32:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Compute the internal state of the widget
|
|
|
|
*/
|
|
|
|
EditWidget.prototype.execute = function() {
|
|
|
|
// Get our parameters
|
2013-10-30 13:36:44 +00:00
|
|
|
this.editTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
|
2013-10-15 13:32:27 +00:00
|
|
|
this.editField = this.getAttribute("field","text");
|
|
|
|
this.editIndex = this.getAttribute("index");
|
|
|
|
this.editClass = this.getAttribute("class");
|
2013-12-20 17:06:57 +00:00
|
|
|
this.editPlaceholder = this.getAttribute("placeholder");
|
2019-02-08 16:11:39 +00:00
|
|
|
this.editTabIndex = this.getAttribute("tabindex");
|
2019-10-12 11:04:10 +00:00
|
|
|
this.editFocus = this.getAttribute("focus","");
|
2020-06-11 10:41:35 +00:00
|
|
|
this.editCancelPopups = this.getAttribute("cancelPopups","");
|
2020-07-13 16:42:55 +00:00
|
|
|
this.editInputActions = this.getAttribute("inputActions");
|
|
|
|
this.editRefreshTitle = this.getAttribute("refreshTitle");
|
2020-11-30 18:48:04 +00:00
|
|
|
this.editAutoComplete = this.getAttribute("autocomplete");
|
2014-08-16 14:01:04 +00:00
|
|
|
// Choose the appropriate edit widget
|
|
|
|
this.editorType = this.getEditorType();
|
|
|
|
// Make the child widgets
|
|
|
|
this.makeChildWidgets([{
|
|
|
|
type: "edit-" + this.editorType,
|
2020-06-27 11:33:14 +00:00
|
|
|
attributes: this.parseTreeNode.attributes,
|
2016-04-22 07:36:29 +00:00
|
|
|
children: this.parseTreeNode.children
|
2014-08-16 14:01:04 +00:00
|
|
|
}]);
|
|
|
|
};
|
|
|
|
|
|
|
|
EditWidget.prototype.getEditorType = function() {
|
2013-10-15 13:32:27 +00:00
|
|
|
// Get the content type of the thing we're editing
|
|
|
|
var type;
|
|
|
|
if(this.editField === "text") {
|
|
|
|
var tiddler = this.wiki.getTiddler(this.editTitle);
|
|
|
|
if(tiddler) {
|
|
|
|
type = tiddler.fields.type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
type = type || "text/vnd.tiddlywiki";
|
2014-05-02 08:43:39 +00:00
|
|
|
var editorType = this.wiki.getTiddlerText(EDITOR_MAPPING_PREFIX + type);
|
|
|
|
if(!editorType) {
|
|
|
|
var typeInfo = $tw.config.contentTypeInfo[type];
|
|
|
|
if(typeInfo && typeInfo.encoding === "base64") {
|
|
|
|
editorType = "binary";
|
|
|
|
} else {
|
|
|
|
editorType = "text";
|
|
|
|
}
|
|
|
|
}
|
2014-08-16 14:01:04 +00:00
|
|
|
return editorType;
|
2013-10-15 13:32:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
|
|
|
*/
|
|
|
|
EditWidget.prototype.refresh = function(changedTiddlers) {
|
|
|
|
var changedAttributes = this.computeAttributes();
|
2014-08-16 14:01:04 +00:00
|
|
|
// Refresh if an attribute has changed, or the type associated with the target tiddler has changed
|
2024-01-24 11:37:15 +00:00
|
|
|
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.tabindex || changedAttributes.cancelPopups || changedAttributes.inputActions || changedAttributes.refreshTitle || changedAttributes.autocomplete || (this.getEditorType() !== this.editorType)) {
|
2013-10-15 13:32:27 +00:00
|
|
|
this.refreshSelf();
|
|
|
|
return true;
|
|
|
|
} else {
|
2019-02-08 16:11:39 +00:00
|
|
|
return this.refreshChildren(changedTiddlers);
|
2013-10-15 13:32:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.edit = EditWidget;
|
|
|
|
|
|
|
|
})();
|