2 'libs/jquery-1.9.1.min',
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().find('.canvas-widgets').append(widget);
17 this.clearWidgets = function() {
18 documentElement.dom().find('.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.bound() ? 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')
54 var GenericManager = function(wlxmlElement) {
55 this.el = wlxmlElement;
58 $.extend(GenericManager.prototype, {
60 this.el.setDisplayStyle(getDisplayStyle(this.el.tag(), this.el.klass()));
62 this.el.clearWidgets();
63 this.el.addWidget(widgets.labelWidget(this.el.tag(), this.el.klass()));
66 toggle: function(toggle) {
67 this.el.toggle(toggle);
74 set: function(tag, klass, manager) {
77 this._m[tag][klass] = manager;
79 get: function(tag,klass) {
80 if(this._m[tag] && this._m[tag][klass])
81 return this._m[tag][klass];
82 return GenericManager;
86 var FootnoteManager = function(wlxmlElement) {
87 this.el = wlxmlElement;
89 $.extend(FootnoteManager.prototype, {
91 this.el.clearWidgets();
93 var clickHandler = function() {
96 this.footnoteHandler = widgets.footnoteHandler(clickHandler);
97 this.el.addWidget(this.footnoteHandler);
99 var closeHandler = function() {
103 this.hideButton = widgets.hideButton(closeHandler);
104 this.el.addWidget(this.hideButton);
106 this.toggle(false, {silent: true});
108 toggle: function(toggle, options) {
109 options = options || {};
110 this.hideButton.toggle(toggle);
111 this.footnoteHandler.toggle(!toggle);
113 this.el.setDisplayStyle(toggle ? 'block' : 'inline');
114 this.el.toggle(toggle);
116 this.el.trigger('elementToggled', toggle, this.el.documentElement);
119 managers.set('aside', 'footnote', FootnoteManager);
123 getFor: function(documentElement) {
124 var wlxmlElement = new DocumentElementWrapper(documentElement);
125 return new (managers.get(wlxmlElement.tag(), wlxmlElement.klass()))(wlxmlElement);