~abreu-alexandre/ubuntu-html5-theme/add-button-class-ubuntu

« back to all changes in this revision

Viewing changes to 0.1/ambiance/js/shape.js

  • Committer: Tarmac
  • Author(s): Kyle Nitzsche
  • Date: 2013-11-01 20:38:57 UTC
  • mfrom: (90.1.4 trunk)
  • Revision ID: tarmac-20131101203857-o50mfgnebkogb950
This MR does three main things:
1) Implements yuidoc comments in all js files to support API doc generation, and provides yuidoc assets (theme dir and json file) needed to build the API docs. Bug LP: #1241029
3) Provides JS classes for shape and page with corresponding UbuntuUI prototype constructor functions. Bug LP: #1243248
4) Adds a getEl(UbuntuUIObject) to return the element for any Ubuntu class. Also LP: #1243248.

Approved by PS Jenkins bot, David Barth.

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-theme.
 
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
 * An Ubuntu Shape contains and decorates (with CSS styles) some markup, often an <em>img</em>.
 
25
 * @class Shape
 
26
 * @constructor
 
27
 * @namespace UbuntuUI
 
28
 * @example
 
29
      <div data-role="shape" id="shapeID">
 
30
        <img src="URI"/>
 
31
      </div>
 
32
 
 
33
      JavaScript access:
 
34
      var shape = UI.shape("shapeID");
 
35
 
 
36
 */
 
37
var Shape = function (id) {
 
38
    this.id =  id;
 
39
};
 
40
 
 
41
Shape.prototype = {
 
42
    /**
 
43
     * Associate a function with the Click event
 
44
     * @method click
 
45
     * @param {Function} - The function to execute on click
 
46
     * @example
 
47
        UI.shape("id").click(function(){
 
48
         console.log("Clicked");
 
49
        });
 
50
     */
 
51
    click: function (callback) {
 
52
      if ( ! document.getElementById(this.id)) {
 
53
        throw "Error. id attribute: " + String(this.id) + " is not present in DOM";
 
54
      } else {
 
55
        var el = document.getElementById(this.id);
 
56
        el.addEventListener('click', callback);
 
57
      }
 
58
    },
 
59
};