Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b80b3bc

Browse files
committed
Merge pull request #5980 from jdfreder/requirejs
use require.js
2 parents 4f25cd4 + e30ae83 commit b80b3bc

70 files changed

Lines changed: 2740 additions & 2797 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ before_install:
1515
- time sudo apt-get update
1616
- time sudo apt-get install pandoc casperjs nodejs libzmq3-dev
1717
- time pip install -f https://nipy.bic.berkeley.edu/wheelhouse/travis jinja2 sphinx pygments tornado requests mock pyzmq jsonschema jsonpointer
18+
- time npm install -g requirejs jquery
1819
install:
1920
- time python setup.py install -q
2021
script:
Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
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-
//----------------------------------------------------------------------------
1+
// Copyright (c) IPython Development Team.
2+
// Distributed under the terms of the Modified BSD License.
73

8-
//============================================================================
9-
// On document ready
10-
//============================================================================
11-
12-
13-
$(document).ready(function () {
14-
15-
IPython.page = new IPython.Page();
4+
var ipython = ipython || {};
5+
require(['base/js/page'], function(page) {
6+
var page_instance = new page.Page();
167
$('button#login_submit').addClass("btn btn-default");
17-
IPython.page.show();
8+
page_instance.show();
189
$('input#password_input').focus();
19-
10+
11+
ipython.page = page_instance;
2012
});
21-
Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
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-
// Login button
10-
//============================================================================
11-
12-
var IPython = (function (IPython) {
1+
// Copyright (c) IPython Development Team.
2+
// Distributed under the terms of the Modified BSD License.
3+
4+
define([
5+
'base/js/namespace',
6+
'base/js/utils',
7+
'jquery',
8+
], function(IPython, utils, $){
139
"use strict";
1410

1511
var LoginWidget = function (selector, options) {
1612
options = options || {};
17-
this.base_url = options.base_url || IPython.utils.get_body_data("baseUrl");
13+
this.base_url = options.base_url || utils.get_body_data("baseUrl");
1814
this.selector = selector;
1915
if (this.selector !== undefined) {
2016
this.element = $(selector);
@@ -31,13 +27,13 @@ var IPython = (function (IPython) {
3127
LoginWidget.prototype.bind_events = function () {
3228
var that = this;
3329
this.element.find("button#logout").click(function () {
34-
window.location = IPython.utils.url_join_encode(
30+
window.location = utils.url_join_encode(
3531
that.base_url,
3632
"logout"
3733
);
3834
});
3935
this.element.find("button#login").click(function () {
40-
window.location = IPython.utils.url_join_encode(
36+
window.location = utils.url_join_encode(
4137
that.base_url,
4238
"login"
4339
);
@@ -47,6 +43,5 @@ var IPython = (function (IPython) {
4743
// Set module variables
4844
IPython.LoginWidget = LoginWidget;
4945

50-
return IPython;
51-
52-
}(IPython));
46+
return {'LoginWidget': LoginWidget};
47+
});
Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
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-
//----------------------------------------------------------------------------
1+
// Copyright (c) IPython Development Team.
2+
// Distributed under the terms of the Modified BSD License.
73

8-
//============================================================================
9-
// On document ready
10-
//============================================================================
11-
12-
13-
$(document).ready(function () {
14-
15-
IPython.page = new IPython.Page();
4+
var ipython = ipython || {};
5+
require(['base/js/page'], function(page) {
6+
var page_instance = new page.Page();
167
$('#ipython-main-app').addClass('border-box-sizing');
17-
IPython.page.show();
8+
page_instance.show();
189

10+
ipython.page = page_instance;
1911
});
20-

IPython/html/static/base/js/dialog.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
//----------------------------------------------------------------------------
2-
// Copyright (C) 2013 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-
//----------------------------------------------------------------------------
1+
// Copyright (c) IPython Development Team.
2+
// Distributed under the terms of the Modified BSD License.
73

8-
//============================================================================
9-
// Utility for modal dialogs with bootstrap
10-
//============================================================================
11-
12-
IPython.namespace('IPython.dialog');
13-
14-
IPython.dialog = (function (IPython) {
4+
define([
5+
'base/js/namespace',
6+
'jquery',
7+
], function(IPython, $) {
158
"use strict";
169

1710
var modal = function (options) {
11+
1812
var modal = $("<div/>")
1913
.addClass("modal")
2014
.addClass("fade")
@@ -79,34 +73,36 @@ IPython.dialog = (function (IPython) {
7973
});
8074
}
8175
modal.on("hidden.bs.modal", function () {
82-
if (IPython.notebook) {
83-
var cell = IPython.notebook.get_selected_cell();
76+
if (options.notebook) {
77+
var cell = options.notebook.get_selected_cell();
8478
if (cell) cell.select();
85-
IPython.keyboard_manager.enable();
86-
IPython.keyboard_manager.command_mode();
79+
}
80+
if (options.keyboard_manager) {
81+
options.keyboard_manager.enable();
82+
options.keyboard_manager.command_mode();
8783
}
8884
});
8985

90-
if (IPython.keyboard_manager) {
91-
IPython.keyboard_manager.disable();
86+
if (options.keyboard_manager) {
87+
options.keyboard_manager.disable();
9288
}
9389

9490
return modal.modal(options);
9591
};
9692

97-
var edit_metadata = function (md, callback, name) {
98-
name = name || "Cell";
93+
var edit_metadata = function (options) {
94+
options.name = options.name || "Cell";
9995
var error_div = $('<div/>').css('color', 'red');
10096
var message =
101-
"Manually edit the JSON below to manipulate the metadata for this " + name + "." +
97+
"Manually edit the JSON below to manipulate the metadata for this " + options.name + "." +
10298
" We recommend putting custom metadata attributes in an appropriately named sub-structure," +
10399
" so they don't conflict with those of others.";
104100

105101
var textarea = $('<textarea/>')
106102
.attr('rows', '13')
107103
.attr('cols', '80')
108104
.attr('name', 'metadata')
109-
.text(JSON.stringify(md || {}, null, 2));
105+
.text(JSON.stringify(options.md || {}, null, 2));
110106

111107
var dialogform = $('<div/>').attr('title', 'Edit the metadata')
112108
.append(
@@ -128,8 +124,8 @@ IPython.dialog = (function (IPython) {
128124
autoIndent: true,
129125
mode: 'application/json',
130126
});
131-
var modal = IPython.dialog.modal({
132-
title: "Edit " + name + " Metadata",
127+
var modal = modal({
128+
title: "Edit " + options.name + " Metadata",
133129
body: dialogform,
134130
buttons: {
135131
OK: { class : "btn-primary",
@@ -143,19 +139,25 @@ IPython.dialog = (function (IPython) {
143139
error_div.text('WARNING: Could not save invalid JSON.');
144140
return false;
145141
}
146-
callback(new_md);
142+
options.callback(new_md);
147143
}
148144
},
149145
Cancel: {}
150-
}
146+
},
147+
notebook: options.notebook,
148+
keyboard_manager: options.keyboard_manager,
151149
});
152150

153151
modal.on('shown.bs.modal', function(){ editor.refresh(); });
154152
};
155153

156-
return {
154+
var dialog = {
157155
modal : modal,
158156
edit_metadata : edit_metadata,
159157
};
160158

161-
}(IPython));
159+
// Backwards compatability.
160+
IPython.dialog = dialog;
161+
162+
return dialog;
163+
});
Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,19 @@
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-
// Events
10-
//============================================================================
1+
// Copyright (c) IPython Development Team.
2+
// Distributed under the terms of the Modified BSD License.
113

124
// Give us an object to bind all events to. This object should be created
135
// before all other objects so it exists when others register event handlers.
146
// To trigger an event handler:
157
// $([IPython.events]).trigger('event.Namespace');
168
// To handle it:
179
// $([IPython.events]).on('event.Namespace',function () {});
18-
19-
var IPython = (function (IPython) {
10+
define(['base/js/namespace'], function(IPython) {
2011
"use strict";
2112

22-
var utils = IPython.utils;
23-
2413
var Events = function () {};
25-
14+
15+
// Backwards compatability.
2616
IPython.Events = Events;
27-
IPython.events = new Events();
28-
29-
return IPython;
30-
31-
}(IPython));
32-
17+
18+
return {'Events': Events};
19+
});

0 commit comments

Comments
 (0)