3 'modules/documentCanvas/canvas/widgets'
4 ], function($, widgets) {
9 var DocumentElementWrapper = function(documentElement) {
11 this.documentElement = documentElement;
13 this.addWidget = function(widget) {
14 documentElement.dom().children('.canvas-widgets').append(widget.DOM ? widget.DOM : widget);
17 this.clearWidgets = function() {
18 documentElement.dom().children('.canvas-widgets').empty();
21 this.setDisplayStyle = function(displayStyle) {
22 documentElement.dom().css('display', displayStyle || '');
23 documentElement._container().css('display', displayStyle || '');
26 this.tag = function() {
27 return documentElement.getWlxmlTag();
30 this.klass = function() {
31 return documentElement.getWlxmlClass();
34 this.toggle = function(toggle) {
35 documentElement._container().toggle(toggle);
38 var eventBus = documentElement.canvas ? documentElement.canvas.eventBus :
39 {trigger: function() {}};
40 this.trigger = function() {
41 eventBus.trigger.apply(eventBus, arguments);
44 this.node = documentElement.data('wlxmlNode');
48 var getDisplayStyle = function(tag, klass) {
49 if(tag === 'metadata') {
55 if(klass && klass.substr(0, 4) === 'item') {
64 var GenericManager = function(wlxmlElement) {
65 this.el = wlxmlElement;
68 $.extend(GenericManager.prototype, {
70 this.el.setDisplayStyle(getDisplayStyle(this.el.tag(), this.el.klass()));
72 this.el.clearWidgets();
73 this.el.addWidget(widgets.labelWidget(this.el.tag(), this.el.klass()));
76 toggle: function(toggle) {
77 this.el.toggle(toggle);
84 set: function(tag, klass, manager) {
88 this._m[tag][klass] = manager;
90 get: function(tag,klass) {
91 if(this._m[tag] && this._m[tag][klass]) {
92 return this._m[tag][klass];
94 return GenericManager;
98 var FootnoteManager = function(wlxmlElement) {
99 this.el = wlxmlElement;
101 $.extend(FootnoteManager.prototype, {
103 this.el.clearWidgets();
105 var clickHandler = function() {
108 this.footnoteHandler = widgets.footnoteHandler(clickHandler);
109 this.el.addWidget(this.footnoteHandler);
111 var closeHandler = function() {
115 this.hideButton = widgets.hideButton(closeHandler);
116 this.el.addWidget(this.hideButton);
118 this.toggle(false, {silent: true});
120 toggle: function(toggle, options) {
121 options = options || {};
122 this.hideButton.toggle(toggle);
123 this.footnoteHandler.toggle(!toggle);
125 this.el.setDisplayStyle(toggle ? 'block' : 'inline');
126 this.el.toggle(toggle);
127 if(!options.silent) {
128 this.el.trigger('elementToggled', toggle, this.el.documentElement);
132 managers.set('aside', 'footnote', FootnoteManager);
135 var ListItemManager = function(wlxmlElement) {
136 this.el = wlxmlElement;
138 $.extend(ListItemManager.prototype, {
140 this.el.clearWidgets();
141 this.el.addWidget(widgets.labelWidget(this.el.tag(), this.el.klass()));
142 this.el.documentElement._container().css({display: 'list-item'});
144 toggleBullet: function(toggle) {
145 this.el.documentElement._container().css({display : toggle ? 'list-item' : 'block'});
148 managers.set('div', 'item', ListItemManager);
151 var CommentManager = function(wlxmlElement) {
152 this.el = wlxmlElement;
155 $.extend(CommentManager.prototype, {
157 this.el.clearWidgets();
158 this.el.addWidget(widgets.labelWidget(this.el.tag(), this.el.klass()));
160 this.widget = widgets.commentAdnotation(this.el.node);
161 this.el.addWidget(this.widget);
162 this.widget.DOM.show();
164 updateMetadata: function() {
166 // this.el.node.getMetadata().forEach(function(row) {
167 // parts.push(row.getValue());
169 // this.widget.text(parts.join(', '));
170 this.widget.update(this.el.node);
173 managers.set('aside', 'comment', CommentManager);
176 getFor: function(documentElement) {
177 var wlxmlElement = new DocumentElementWrapper(documentElement);
178 return new (managers.get(wlxmlElement.tag(), wlxmlElement.klass()))(wlxmlElement);