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.wlxmlNode;
47 var getDisplayStyle = function(tag, klass) {
48 if(tag === 'metadata') {
54 if(klass && klass.substr(0, 4) === 'item') {
63 var GenericManager = function(wlxmlElement) {
64 this.el = wlxmlElement;
67 $.extend(GenericManager.prototype, {
69 this.el.setDisplayStyle(getDisplayStyle(this.el.tag(), this.el.klass()));
71 this.el.clearWidgets();
72 this.el.addWidget(widgets.labelWidget(this.el.tag(), this.el.klass()));
75 toggle: function(toggle) {
76 this.el.toggle(toggle);
83 set: function(tag, klass, manager) {
87 this._m[tag][klass] = manager;
89 get: function(tag,klass) {
90 if(this._m[tag] && this._m[tag][klass]) {
91 return this._m[tag][klass];
93 return GenericManager;
97 var FootnoteManager = function(wlxmlElement) {
98 this.el = wlxmlElement;
100 $.extend(FootnoteManager.prototype, {
102 this.el.clearWidgets();
104 var clickHandler = function() {
107 this.footnoteHandler = widgets.footnoteHandler(clickHandler);
108 this.el.addWidget(this.footnoteHandler);
110 var closeHandler = function() {
114 this.hideButton = widgets.hideButton(closeHandler);
115 this.el.addWidget(this.hideButton);
117 this.toggle(false, {silent: true});
119 toggle: function(toggle, options) {
120 options = options || {};
121 this.hideButton.toggle(toggle);
122 this.footnoteHandler.toggle(!toggle);
124 this.el.setDisplayStyle(toggle ? 'block' : 'inline');
125 this.el.toggle(toggle);
126 if(!options.silent) {
127 this.el.trigger('elementToggled', toggle, this.el.documentElement);
131 managers.set('aside', 'footnote', FootnoteManager);
134 var ListItemManager = function(wlxmlElement) {
135 this.el = wlxmlElement;
137 $.extend(ListItemManager.prototype, {
139 this.el.clearWidgets();
140 this.el.addWidget(widgets.labelWidget(this.el.tag(), this.el.klass()));
141 this.el.documentElement._container().css({display: 'list-item'});
143 toggleBullet: function(toggle) {
144 this.el.documentElement._container().css({display : toggle ? 'list-item' : 'block'});
147 managers.set('div', 'item', ListItemManager);
150 var CommentManager = function(wlxmlElement) {
151 this.el = wlxmlElement;
154 $.extend(CommentManager.prototype, {
156 this.el.clearWidgets();
157 this.el.addWidget(widgets.labelWidget(this.el.tag(), this.el.klass()));
159 this.widget = widgets.commentAdnotation(this.el.node);
160 this.el.addWidget(this.widget);
161 this.widget.DOM.show();
163 updateMetadata: function() {
165 // this.el.node.getMetadata().forEach(function(row) {
166 // parts.push(row.getValue());
168 // this.widget.text(parts.join(', '));
169 this.widget.update(this.el.node);
172 managers.set('aside', 'comment', CommentManager);
175 getFor: function(documentElement) {
176 var wlxmlElement = new DocumentElementWrapper(documentElement);
177 return new (managers.get(wlxmlElement.tag(), wlxmlElement.klass()))(wlxmlElement);