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);
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);
46 var getDisplayStyle = function(tag, klass) {
47 if(tag === 'metadata') {
53 if(klass === 'item') {
59 var GenericManager = function(wlxmlElement) {
60 this.el = wlxmlElement;
63 $.extend(GenericManager.prototype, {
65 this.el.setDisplayStyle(getDisplayStyle(this.el.tag(), this.el.klass()));
67 this.el.clearWidgets();
68 this.el.addWidget(widgets.labelWidget(this.el.tag(), this.el.klass()));
71 toggle: function(toggle) {
72 this.el.toggle(toggle);
79 set: function(tag, klass, manager) {
83 this._m[tag][klass] = manager;
85 get: function(tag,klass) {
86 if(this._m[tag] && this._m[tag][klass]) {
87 return this._m[tag][klass];
89 return GenericManager;
93 var FootnoteManager = function(wlxmlElement) {
94 this.el = wlxmlElement;
96 $.extend(FootnoteManager.prototype, {
98 this.el.clearWidgets();
100 var clickHandler = function() {
103 this.footnoteHandler = widgets.footnoteHandler(clickHandler);
104 this.el.addWidget(this.footnoteHandler);
106 var closeHandler = function() {
110 this.hideButton = widgets.hideButton(closeHandler);
111 this.el.addWidget(this.hideButton);
113 this.toggle(false, {silent: true});
115 toggle: function(toggle, options) {
116 options = options || {};
117 this.hideButton.toggle(toggle);
118 this.footnoteHandler.toggle(!toggle);
120 this.el.setDisplayStyle(toggle ? 'block' : 'inline');
121 this.el.toggle(toggle);
122 if(!options.silent) {
123 this.el.trigger('elementToggled', toggle, this.el.documentElement);
127 managers.set('aside', 'footnote', FootnoteManager);
130 var ListItemManager = function(wlxmlElement) {
131 this.el = wlxmlElement;
133 $.extend(ListItemManager.prototype, {
135 this.el.clearWidgets();
136 this.el.addWidget(widgets.labelWidget(this.el.tag(), this.el.klass()));
137 this.el.documentElement._container().css({display: 'list-item'});
139 toggleBullet: function(toggle) {
140 this.el.documentElement._container().css({display : toggle ? 'list-item' : 'block'});
143 managers.set('div', 'item', ListItemManager);
146 getFor: function(documentElement) {
147 var wlxmlElement = new DocumentElementWrapper(documentElement);
148 return new (managers.get(wlxmlElement.tag(), wlxmlElement.klass()))(wlxmlElement);