triggerSelectionChanged: function() {
this.trigger('selectionChanged', this.getSelection());
+ var s = this.getSelection(),
+ f = s.toDocumentFragment();
+ if(f && f instanceof f.RangeFragment) {
+ var $current = this.wrapper.find('.current-node-element');
+ var current = $current && this.getDocumentElement($current.parent()[0]);
+
+ if($current) {
+ $current.removeClass('current-node-element');
+ }
+ if(current) {
+ current.markAsCurrent(false);
+ }
+ }
},
getSelection: function() {
this.wrapper.find('.current-text-element').removeClass('current-text-element');
element.dom.addClass('current-text-element');
} else {
- this.wrapper.find('.current-node-element').removeClass('current-node-element');
+ var $current = this.wrapper.find('.current-node-element');
+ var current = this.getDocumentElement($current.parent()[0]);
+ $current.removeClass('current-node-element');
+
+ if(current) {
+ current.markAsCurrent(false);
+ }
element._container().addClass('current-node-element');
+ element.markAsCurrent(true);
}
}.bind(this);
this.toggleHighlight(toggle);
},
+ markAsCurrent: function() {},
+
toggleHighlight: function(toggle) {
this._container().toggleClass('highlighted-element', toggle);
},
define(function(require) {
'use strict';
-var $ = require('libs/jquery'),
- genericElement = require('modules/documentCanvas/canvas/genericElement'); // TODO: This should be accessible via plugin infrastructure
+var $ = require('libs/jquery'),
+ genericElement = require('modules/documentCanvas/canvas/genericElement'), // TODO: This should be accessible via plugin infrastructure
+ linkElement = require('./links/linkElement');
var widgets = {
footnoteHandler: function(clickHandler) {
return [
{tag: 'aside', klass: 'comment', prototype: comment},
- {tag: 'aside', klass: 'footnote', prototype: footnote}
+ {tag: 'aside', klass: 'footnote', prototype: footnote},
+ {tag: 'span', klass: 'link', prototype: linkElement}
];
font-size: 10px;
color: lighten(@black, 10%);
z-index:1000;
-}
\ No newline at end of file
+}
-@import 'canvasElements.less';
\ No newline at end of file
+@import 'canvasElements.less';
+@import 'links/links.less';
--- /dev/null
+<div contenteditable="false" link-box style="white-space: nowrap">
+ <a link target="blank" href="<%= href %>"><%= href %></a> --
+ <span>
+ <a class="change" href="#"><%= gettext('change') %></a> |
+ <a class="delete" href="#"><%= gettext('remove') %></a>
+ </span>
+</div>
\ No newline at end of file
--- /dev/null
+define(function(require) {
+
+'use strict';
+/* globals gettext */
+
+
+var $ = require('libs/jquery'),
+ _ = require('libs/underscore'),
+ genericElement = require('modules/documentCanvas/canvas/genericElement'),
+ Dialog = require('views/dialog/dialog'),
+ boxTemplate = require('libs/text!./box.html'),
+ linkElement = Object.create(genericElement);
+
+
+_.extend(linkElement, {
+ init: function() {
+ genericElement.init.call(this);
+ _.bindAll(this, 'changeLink', 'deleteLink');
+
+ this.box = $(_.template(boxTemplate)({href: this.wlxmlNode.getAttr('href')}));
+ this.box.find('.change').on('click', this.changeLink);
+ this.box.find('.delete').on('click', this.deleteLink);
+ this.box.hide();
+ this.addWidget(this.box);
+ },
+ markAsCurrent: function(toggle) {
+ this.box.toggle(toggle);
+ },
+ onNodeAttrChange: function(event) {
+ if(event.meta.attr === 'href') {
+ var link = this.box.find('[link]');
+ link.text(event.meta.newVal);
+ link.attr('href', event.meta.newVal);
+ }
+ },
+
+ changeLink: function(e) {
+ var el = this,
+ dialog = Dialog.create({
+ title: gettext('Edit link'),
+ executeButtonText: gettext('Apply'),
+ cancelButtonText: gettext('Cancel'),
+ fields: [
+ {label: gettext('Link'), name: 'href', type: 'input', initialValue: el.wlxmlNode.getAttr('href')}
+ ]
+ });
+ e.preventDefault();
+ e.stopPropagation();
+
+ dialog.on('execute', function(event) {
+ el.wlxmlNode.document.transaction(function() {
+ el.wlxmlNode.setAttr('href', event.formData.href);
+ event.success();
+ }, {
+ metadata: {
+ description: gettext('Edit link')
+ }
+ });
+ });
+ dialog.show();
+ },
+
+ deleteLink: function() {
+ var el = this;
+ el.wlxmlNode.document.transaction(function() {
+ el.wlxmlNode.unwrapContent();
+ }, {
+ metadata: {
+ description: gettext('Remove link')
+ }
+ });
+ }
+});
+
+return linkElement;
+
+});
--- /dev/null
+[link-box] {
+ border: 1px solid #ddd;
+ position: absolute;
+ color: black;
+ left:0;
+ font-size: 12px;
+ line-height: 10px;
+ bottom: -42px;
+ padding: 10px 15px;
+ background-color: rgba(255,255,255,1);
+ box-shadow:0 10px 5px #888888;
+ z-index:9999;
+ font-style: normal;
+}
\ No newline at end of file