link = cfg.documentAttachmentUrl(link.substr(7));
}
return link;
+ },
+ getLinkForUrl: function(url) {
+ /* globals window */
+ var baseUrl = function(url) {return url.split('/').slice(0,-1).join('/');};
+ if(baseUrl(url) === baseUrl(window.location.origin + this.getUrlForLink('file://test'))) {
+ return 'file://' + _.last(url.split('/'));
+ }
+ return url;
}
});
executeButtonText: gettext('Apply'),
cancelButtonText: gettext('Cancel'),
fields: [
- {label: gettext('Link'), name: 'href', type: 'input'}
+ {label: gettext('Link'), name: 'href', type: 'input',
+ prePasteHandler: function(text) {
+ return params.fragment.document.getLinkForUrl(text);
+ }.bind(this)
+ }
]
}),
action = this;
executeButtonText: gettext('Apply'),
cancelButtonText: gettext('Cancel'),
fields: [
- {label: gettext('Link'), name: 'href', type: 'input', initialValue: el.wlxmlNode.getAttr('href')}
+ {label: gettext('Link'), name: 'href', type: 'input', initialValue: el.wlxmlNode.getAttr('href'),
+ prePasteHandler: function(text) {
+ return this.wlxmlNode.document.getLinkForUrl(text);
+ }.bind(this)
+ }
]
});
e.preventDefault();
'use strict';
- var _ = require('libs/underscore'),
+ var $ = require('libs/jquery'),
+ _ = require('libs/underscore'),
Backbone = require('libs/backbone'),
dialogTemplate = require('libs/text!./dialog.html'),
fieldTemplates = {};
if(!template) {
throw new Error('Field type {type} not recognized.'.replace('{type}', field.type));
}
- body.append(
- _.template(template)(_.extend({description: '', initialValue: ''}, field))
- );
+ var widget = $(_.template(template)(_.extend({description: '', initialValue: ''}, field)));
+
+ body.append(widget);
+
+ if(_.isFunction(field.prePasteHandler) && field.type === 'input') { // TODO: extract this out to widget specific impl.
+ widget.find('input').on('paste', function(e) {
+ var clipboardData = e.originalEvent.clipboardData;
+ if(!clipboardData || !clipboardData.getData) {
+ return;
+ }
+ e.preventDefault();
+ var text = clipboardData.getData('text/plain').replace(/\r?\n|\r/g, ' ');
+ $(e.target).val(field.prePasteHandler(text));
+ });
+ }
});
if(this.options.text) {
-<p>
+<div>
<div style="float: left; width:100px;"><%= label %>:</div>
<input type="checkbox" name="<%= name %>"/>
<span class="description"><%= description %></span>
-</p>
\ No newline at end of file
+</div>
\ No newline at end of file
-<p>
+<div>
<div style="float: left; width:100px;">
<%= label %>:
</div>
<span class="description"><%= description %></span>
</div>
-</p>
\ No newline at end of file
+</div>
\ No newline at end of file
-<p>
+<div>
<div style="float: left; width:100px;"><%= label %>:</div>
<select name="<%= name %>">
<% options.forEach(function(option) { %>
<% }); %>
</select>
<span class="description"><%= description %></span>
-</p>
\ No newline at end of file
+</div>
\ No newline at end of file
-<p>
+<div>
<label><%= label %></label>
<textarea name="<%= name %>" rows="5"><%= initialValue %></textarea>
<span class="description"><%= description %></span>
-</p>
+</div>