1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/* Copyright (c) 2011, Canonical Ltd. All rights reserved. */
YUI().add('lp.configutils', function(Y) {
/**
* The configutils module provides objects for managing the config
* or settings of a web page or widget.
*
* Widgets that want to be accessed from a settings/config
* icon should extend BaseConfigUtil and provide a callback that
* will run when the icon is clicked.
*
* @module lp.configutils
*/
// Constants
var CONTENT_BOX = 'contentBox',
EMPTY_FN = function() {};
/**
* BaseConfigUtil is the base object that every FooConfigUtil
* object should extend.
*
* @class BaseConfigUtil
* @extends Widget
* @constructor
*/
function BaseConfigUtil() {
BaseConfigUtil.superclass.constructor.apply(this, arguments);
}
BaseConfigUtil.NAME = 'baseconfigutil';
BaseConfigUtil.ATTRS = {
/**
* A reference to the anchor element created during renderUI.
*
* @attribute anchor
* @type Y.Node
* @default null
*/
anchor: {
value: null
}
};
Y.extend(BaseConfigUtil, Y.Widget, {
/**
* Hook for subclasses to do something when the settings
* icon is clicked.
*/
_handleClick: EMPTY_FN,
/**
* Hook for subclasses to do work after renderUI.
*/
_extraRenderUI: EMPTY_FN,
/**
* Create the anchor element that will display the settings icon.
*
* @method renderUI
*/
renderUI: function() {
var anchor = Y.Node.create(
'<a></a>').addClass('sprite').addClass('config');
anchor.set('title', 'Customise visible bug information');
this.set('anchor', anchor);
var content = this.get(CONTENT_BOX);
content.append(anchor);
this._extraRenderUI();
},
/**
* Wire up the anchor element to _handleClick.
*
* Objects that extend BaseConfigUtil should create their own
* _handleClick method.
*
* @method bindUI
*/
bindUI: function() {
// Do some work here to set up click handlers.
// Add the a element to ATTRS.
var anchor = this.get('anchor');
var that = this;
anchor.on('click', function(e) {
that._handleClick(e);
});
}
});
var configutils = Y.namespace('lp.configutils');
configutils.BaseConfigUtil = BaseConfigUtil;
}, '0.1', {'requires': ['widget']});
|