~cibersheep/unav/systemcolors

« back to all changes in this revision

Viewing changes to nav/toolkit/dialogs.js

  • Committer: costales
  • Date: 2016-03-26 18:53:17 UTC
  • Revision ID: costales.marcos@gmail.com-20160326185317-4iau3yhe8986h5pg
Init team

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
 * Dialogs are modal full-screen popups that prevent other GUI interactions with the application until dismissed.
 
25
 
 
26
Dialogs wrap arbitrary markup.
 
27
 
 
28
Dialogs are declared at the top level inside the <em>content</em> div.
 
29
 * @class Dialog
 
30
 * @constructor
 
31
 * @namespace UbuntuUI
 
32
 * @example
 
33
      <div data-role="content">
 
34
        <div data-role="pagestack">
 
35
          [...]
 
36
        </div>
 
37
        <div data-role="dialog" id="dialogID">
 
38
          [...]
 
39
        </div>
 
40
      </div>
 
41
 
 
42
      JavaScript access:
 
43
      var dialog = UI.dialog("dialogID");
 
44
 
 
45
 */
 
46
var Dialog = function (id) {
 
47
    this.id = id;
 
48
    this.dialog = document.getElementById(id);
 
49
};
 
50
 
 
51
Dialog.prototype = {
 
52
    /**
 
53
     * Display a dialog by adding 'active' CSS class
 
54
     * @method show
 
55
     */
 
56
    show: function () {
 
57
        this.dialog.classList.add('active');
 
58
    },
 
59
    /**
 
60
     * Hide a dialog by removing 'active' class
 
61
     * @method hide
 
62
     */
 
63
    hide: function () {
 
64
        this.dialog.classList.remove('active');
 
65
    },
 
66
    /**
 
67
     * Toggle a dialog, which means removing its 'active' class if it has one, or adding the 'active' class if it does not have one
 
68
     * @method toggle
 
69
     */
 
70
    toggle: function () {
 
71
        this.dialog.classList.toggle('active');
 
72
    },
 
73
    /**
 
74
     * Returns the DOM element associated with the id this widget is bind to.
 
75
     * @method element
 
76
     * @return {DOMElement}
 
77
     * @example
 
78
        var mydialog = UI.dialog("dialogid").element();
 
79
     */
 
80
    element: function () {
 
81
        return document.getElementById(this.id);
 
82
    }
 
83
};