~knitzsche/+junk/tabtest

« back to all changes in this revision

Viewing changes to fix-page-tab-issue/0.1/ambiance/js/buttons.js

  • Committer: Kyle Nitzsche
  • Date: 2014-02-28 21:45:04 UTC
  • Revision ID: kyle.nitzsche@canonical.com-20140228214504-nzkax4md3v35r6p2
working test

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Adnane Belmadiaf <daker@ubuntu.com>
 
3
 * License granted by Canonical Limited
 
4
 *
 
5
 * This file is part of ubuntu-html5-ui-toolkit.
 
6
 *
 
7
 * This package is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU Lesser General Public License as
 
9
 * published by the Free Software Foundation; either version 3 of the
 
10
 * License, or
 
11
 * (at your option) any later version.
 
12
 
 
13
 * This package is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 
 
18
 * You should have received a copy of the GNU Lesser General Public
 
19
 * License along with this program. If not, see
 
20
 * <http://www.gnu.org/licenses/>.
 
21
 */
 
22
 
 
23
/**
 
24
 * A Button.
 
25
 
 
26
 Note the Ubuntu CSS style classes: <em>success</em>, <em>warning</em>, and <em>danger</em>
 
27
 
 
28
 * @class Button
 
29
 * @constructor
 
30
 * @namespace UbuntuUI
 
31
 * @example
 
32
      <button data-role="button" id="buttonID">text</button>
 
33
 
 
34
      Javascript access:
 
35
      var button = UI.button("buttonID");
 
36
 */
 
37
var Button = function (id) {
 
38
    this.id =  id;
 
39
};
 
40
 
 
41
Button.prototype = {
 
42
    /**
 
43
     * Associate a function with the button's Click event
 
44
     * @method click
 
45
     * @param {Function} callback - The function to execute on click
 
46
     * @example
 
47
        UI.button("buttonid").click(function(){
 
48
         console.log("clicked");
 
49
        });
 
50
     */
 
51
    click: function (callback) {
 
52
        if ( ! document.getElementById(this.id)) {
 
53
            throw "Invalid button ID: " + String(this.id);
 
54
        }
 
55
        new FastButton(document.getElementById(this.id), callback);
 
56
    },
 
57
    /**
 
58
     * Returns the DOM element associated with the id this widget is bind to.
 
59
     * @method element
 
60
     * @return {DOMElement}
 
61
     * @example
 
62
        var mybutton = UI.button("buttonid").element();
 
63
     */
 
64
    element: function() {
 
65
        return document.getElementById(this.id);
 
66
    }
 
67
};