~ubuntu-branches/ubuntu/trusty/qiime/trusty

« back to all changes in this revision

Viewing changes to web/home_static/nih-cloud-apr2012/VariableRegionPositionBoundaries_files/cell.js

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2013-06-17 18:28:26 UTC
  • mfrom: (9.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20130617182826-376az5ad080a0sfe
Tags: 1.7.0+dfsg-1
Upload preparations done for BioLinux to Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//----------------------------------------------------------------------------
2
 
//  Copyright (C) 2008-2011  The IPython Development Team
3
 
//
4
 
//  Distributed under the terms of the BSD License.  The full license is in
5
 
//  the file COPYING, distributed as part of this software.
6
 
//----------------------------------------------------------------------------
7
 
 
8
 
//============================================================================
9
 
// Cell
10
 
//============================================================================
11
 
 
12
 
var IPython = (function (IPython) {
13
 
 
14
 
    var utils = IPython.utils;
15
 
 
16
 
 
17
 
    var Cell = function (notebook) {
18
 
        this.placeholder = this.placeholder || '';
19
 
        this.notebook = notebook;
20
 
        this.read_only = false;
21
 
        if (notebook){
22
 
            this.read_only = notebook.read_only;
23
 
        }
24
 
        this.selected = false;
25
 
        this.element = null;
26
 
        this.create_element();
27
 
        if (this.element !== null) {
28
 
            this.element.data("cell", this);
29
 
            this.bind_events();
30
 
        }
31
 
        this.cell_id = utils.uuid();
32
 
    };
33
 
 
34
 
 
35
 
    // Subclasses must implement create_element.
36
 
    Cell.prototype.create_element = function () {};
37
 
 
38
 
 
39
 
    Cell.prototype.bind_events = function () {
40
 
        var that = this;
41
 
        var nb = that.notebook;
42
 
        that.element.click(function (event) {
43
 
            if (that.selected === false) {
44
 
                nb.select(nb.find_cell_index(that));
45
 
            }
46
 
        });
47
 
        that.element.focusin(function (event) {
48
 
            if (that.selected === false) {
49
 
                nb.select(nb.find_cell_index(that));
50
 
            }
51
 
        });
52
 
    };
53
 
 
54
 
 
55
 
    // typeset with MathJax if MathJax is available
56
 
    Cell.prototype.typeset = function () {
57
 
        if (window.MathJax){
58
 
            MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
59
 
        }
60
 
    };
61
 
 
62
 
 
63
 
    Cell.prototype.select = function () {
64
 
        this.element.addClass('ui-widget-content ui-corner-all');
65
 
        this.selected = true;
66
 
    };
67
 
 
68
 
 
69
 
    Cell.prototype.unselect = function () {
70
 
        this.element.removeClass('ui-widget-content ui-corner-all');
71
 
        this.selected = false;
72
 
    };
73
 
 
74
 
 
75
 
    Cell.prototype.get_text = function () {
76
 
    };
77
 
 
78
 
 
79
 
    Cell.prototype.set_text = function (text) {
80
 
    };
81
 
 
82
 
 
83
 
    Cell.prototype.refresh = function () {
84
 
        this.code_mirror.refresh();
85
 
    };
86
 
 
87
 
 
88
 
    Cell.prototype.edit = function () {
89
 
    };
90
 
 
91
 
 
92
 
    Cell.prototype.render = function () {
93
 
    };
94
 
 
95
 
 
96
 
    Cell.prototype.toJSON = function () {
97
 
    };
98
 
 
99
 
 
100
 
    Cell.prototype.fromJSON = function (data) {
101
 
    };
102
 
 
103
 
 
104
 
    Cell.prototype.is_splittable = function () {
105
 
        return true;
106
 
    };
107
 
 
108
 
 
109
 
    Cell.prototype.get_pre_cursor = function () {
110
 
        var cursor = this.code_mirror.getCursor();
111
 
        var text = this.code_mirror.getRange({line:0,ch:0}, cursor);
112
 
        text = text.replace(/^\n+/, '').replace(/\n+$/, '');
113
 
        return text;
114
 
    }
115
 
 
116
 
 
117
 
    Cell.prototype.get_post_cursor = function () {
118
 
        var cursor = this.code_mirror.getCursor();
119
 
        var last_line_num = this.code_mirror.lineCount()-1;
120
 
        var last_line_len = this.code_mirror.getLine(last_line_num).length;
121
 
        var end = {line:last_line_num, ch:last_line_len}
122
 
        var text = this.code_mirror.getRange(cursor, end);
123
 
        text = text.replace(/^\n+/, '').replace(/\n+$/, '');
124
 
        return text;
125
 
    };
126
 
 
127
 
 
128
 
    Cell.prototype.grow = function(element) {
129
 
        // Grow the cell by hand. This is used upon reloading from JSON, when the
130
 
        // autogrow handler is not called.
131
 
        var dom = element.get(0);
132
 
        var lines_count = 0;
133
 
        // modified split rule from
134
 
        // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
135
 
        var lines = dom.value.split(/\r|\r\n|\n/);
136
 
        lines_count = lines.length;
137
 
        if (lines_count >= 1) {
138
 
            dom.rows = lines_count;
139
 
        } else {
140
 
            dom.rows = 1;
141
 
        }
142
 
    };
143
 
 
144
 
 
145
 
    Cell.prototype.toggle_line_numbers = function () {
146
 
        if (this.code_mirror.getOption('lineNumbers') == false) {
147
 
            this.code_mirror.setOption('lineNumbers', true);
148
 
        } else {
149
 
            this.code_mirror.setOption('lineNumbers', false);
150
 
        }
151
 
        this.code_mirror.refresh();
152
 
    };
153
 
 
154
 
 
155
 
    IPython.Cell = Cell;
156
 
 
157
 
    return IPython;
158
 
 
159
 
}(IPython));
160