PageRenderTime 427ms CodeModel.GetById 180ms app.highlight 5ms RepoModel.GetById 181ms app.codeStats 60ms

/wwwroot/lib/ucewidget.js

http://github.com/AF83/ucengine
JavaScript | 76 lines | 58 code | 6 blank | 12 comment | 9 complexity | d19f623e814278395501703ee0c92c0b MD5 | raw file
 1/**
 2 * U.C.Engine UI Widget
 3 * http://ucengine.org/
 4 * (c) 2010 af83
 5 */
 6(function($) {
 7    $.uce = {};
 8    $.uce.widget = function (name, base, prototype) {
 9        var constructor = base._create;
10        var ucewidget = {
11            _create: function() {
12                if (constructor) {
13                    constructor.apply(this, []);
14                }
15                if (this.options.ucemeeting != null) {
16                    for (var ucevent in this.meetingsEvents) {
17                        var method = this.meetingsEvents[ucevent];
18                        if (method) {
19                            method = $.proxy(this[method], this);
20                            this.options.ucemeeting.on(ucevent, method);
21                        }
22                    }
23                }
24            },
25            /**
26             * Trigger ucengine event for testing purpose
27             * Handle only events in meetingsEvents hash
28             */
29            triggerUceEvent: function(event) {
30                var methodName = this.meetingsEvents[event.type];
31                this[methodName](event);
32            }
33        }
34        $.widget("uce." + name, $.extend(true, base, ucewidget, $.uce.header), prototype);
35    };
36    /**
37     * Special headers for U.C.Engine
38     */
39    $.uce.header = {
40        addHeader: function() {
41            this._addHeader(this.options.title, this.options.buttons)
42        },
43
44        _addHeader: function(title, buttons) {
45            var header = $('<div>')
46                .attr('class', 'ui-widget-header ui-corner-all ui-helper-clearfix');
47
48            if (buttons && buttons.left) {
49                var left = $('<span>').attr('class', 'ui-widget-header-left');
50                left.appendTo(header);
51                $.each(buttons.left, function(index, elem) {
52                    elem.appendTo(left);
53                });
54            }
55
56            $('<span>')
57                .addClass('ui-widget-header-title')
58                .text(title)
59                .appendTo(header);
60
61            if (buttons && buttons.right) {
62                var right = $('<span>').attr('class', 'ui-widget-header-right');
63                right.appendTo(header);
64                $.each(buttons.right, function(index, elem) {
65                    elem.appendTo(right);
66                });
67            }
68            header.prependTo(this.element);
69        },
70
71        _setTitle: function(title) {
72            this.element.find('.ui-widget-header-title').text(title);
73        }
74    };
75
76})(jQuery);