From c0cbf12493448a122bb736aa4388ae9b4ceeb3e6 2014-07-10 20:47:23 From: Jonathan Frederic Date: 2014-07-10 20:47:23 Subject: [PATCH] More review changes --- diff --git a/IPython/html/static/base/js/dialog.js b/IPython/html/static/base/js/dialog.js index 00b8c3b..246f93f 100644 --- a/IPython/html/static/base/js/dialog.js +++ b/IPython/html/static/base/js/dialog.js @@ -90,11 +90,11 @@ define([ return modal.modal(options); }; - var edit_metadata = function (md, callback, name, keyboard_manager, notebook) { - name = name || "Cell"; + var edit_metadata = function (options) { + options.name = options.name || "Cell"; var error_div = $('
').css('color', 'red'); var message = - "Manually edit the JSON below to manipulate the metadata for this " + name + "." + + "Manually edit the JSON below to manipulate the metadata for this " + options.name + "." + " We recommend putting custom metadata attributes in an appropriately named sub-structure," + " so they don't conflict with those of others."; @@ -102,7 +102,7 @@ define([ .attr('rows', '13') .attr('cols', '80') .attr('name', 'metadata') - .text(JSON.stringify(md || {}, null, 2)); + .text(JSON.stringify(options.md || {}, null, 2)); var dialogform = $('
').attr('title', 'Edit the metadata') .append( @@ -125,7 +125,7 @@ define([ mode: 'application/json', }); var modal = modal({ - title: "Edit " + name + " Metadata", + title: "Edit " + options.name + " Metadata", body: dialogform, buttons: { OK: { class : "btn-primary", @@ -139,12 +139,14 @@ define([ error_div.text('WARNING: Could not save invalid JSON.'); return false; } - callback(new_md); + options.callback(new_md); } }, Cancel: {} - } - }, keyboard_manager, notebook); + }, + notebook: options.notebook, + keyboard_manager: options.keyboard_manager, + }); modal.on('shown.bs.modal', function(){ editor.refresh(); }); }; @@ -155,7 +157,7 @@ define([ }; // Backwards compatability. - IPython.Dialog = dialog; + IPython.dialog = dialog; return dialog; }); diff --git a/IPython/html/static/base/js/keyboard.js b/IPython/html/static/base/js/keyboard.js index 222b3a3..211ce2a 100644 --- a/IPython/html/static/base/js/keyboard.js +++ b/IPython/html/static/base/js/keyboard.js @@ -242,7 +242,7 @@ define([ return !( data === undefined || data.handler === undefined ); }; - return { + var keyboard = { keycodes : keycodes, inv_keycodes : inv_keycodes, ShortcutManager : ShortcutManager, @@ -251,4 +251,9 @@ define([ shortcut_to_event : shortcut_to_event, event_to_shortcut : event_to_shortcut }; + + // For backwards compatability. + IPython.keyboard = keyboard; + + return keyboard; }); diff --git a/IPython/html/static/base/js/page.js b/IPython/html/static/base/js/page.js index c52728f..2107aa8 100644 --- a/IPython/html/static/base/js/page.js +++ b/IPython/html/static/base/js/page.js @@ -4,9 +4,6 @@ define([ 'base/js/namespace', 'jquery', - 'components/jquery-ui/ui/minified/jquery-ui.min', - 'components/bootstrap/js/bootstrap.min', - 'auth/js/loginwidget' ], function(IPython, $){ "use strict"; diff --git a/IPython/html/static/base/js/pagemain.js b/IPython/html/static/base/js/pagemain.js index 882d783..3f848a1 100644 --- a/IPython/html/static/base/js/pagemain.js +++ b/IPython/html/static/base/js/pagemain.js @@ -1,10 +1,7 @@ // Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. -var ipython = ipython || {}; require(['base/js/page'], function(page) { var page_instance = new page.Page(); page_instance.show(); - - ipython.page = page_instance; }); diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js index 64e1e73..5923256 100644 --- a/IPython/html/static/base/js/utils.js +++ b/IPython/html/static/base/js/utils.js @@ -551,7 +551,7 @@ define([ }; // Backwards compatability. - IPython.Utils = utils; + IPython.utils = utils; return utils; }); diff --git a/IPython/html/static/dateformat/date.format.js b/IPython/html/static/dateformat/date.format.js index 02d94d0..96c1887 100644 --- a/IPython/html/static/dateformat/date.format.js +++ b/IPython/html/static/dateformat/date.format.js @@ -11,122 +11,115 @@ * The date defaults to the current date/time. * The mask defaults to dateFormat.masks.default. */ -// Copyright (c) IPython Development Team. -// Distributed under the terms of the Modified BSD License. -// Require.js define call added by IPython team. -define([], function() { - var dateFormat = function () { - var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g, - timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g, - timezoneClip = /[^-+\dA-Z]/g, - pad = function (val, len) { - val = String(val); - len = len || 2; - while (val.length < len) val = "0" + val; - return val; - }; - - // Regexes and supporting functions are cached through closure - return function (date, mask, utc) { - var dF = dateFormat; +var dateFormat = function () { + var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g, + timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g, + timezoneClip = /[^-+\dA-Z]/g, + pad = function (val, len) { + val = String(val); + len = len || 2; + while (val.length < len) val = "0" + val; + return val; + }; - // You can't provide utc if you skip other args (use the "UTC:" mask prefix) - if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) { - mask = date; - date = undefined; - } + // Regexes and supporting functions are cached through closure + return function (date, mask, utc) { + var dF = dateFormat; - // Passing date through Date applies Date.parse, if necessary - date = date ? new Date(date) : new Date; - if (isNaN(date)) throw SyntaxError("invalid date"); + // You can't provide utc if you skip other args (use the "UTC:" mask prefix) + if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) { + mask = date; + date = undefined; + } - mask = String(dF.masks[mask] || mask || dF.masks["default"]); + // Passing date through Date applies Date.parse, if necessary + date = date ? new Date(date) : new Date; + if (isNaN(date)) throw SyntaxError("invalid date"); - // Allow setting the utc argument via the mask - if (mask.slice(0, 4) == "UTC:") { - mask = mask.slice(4); - utc = true; - } + mask = String(dF.masks[mask] || mask || dF.masks["default"]); - var _ = utc ? "getUTC" : "get", - d = date[_ + "Date"](), - D = date[_ + "Day"](), - m = date[_ + "Month"](), - y = date[_ + "FullYear"](), - H = date[_ + "Hours"](), - M = date[_ + "Minutes"](), - s = date[_ + "Seconds"](), - L = date[_ + "Milliseconds"](), - o = utc ? 0 : date.getTimezoneOffset(), - flags = { - d: d, - dd: pad(d), - ddd: dF.i18n.dayNames[D], - dddd: dF.i18n.dayNames[D + 7], - m: m + 1, - mm: pad(m + 1), - mmm: dF.i18n.monthNames[m], - mmmm: dF.i18n.monthNames[m + 12], - yy: String(y).slice(2), - yyyy: y, - h: H % 12 || 12, - hh: pad(H % 12 || 12), - H: H, - HH: pad(H), - M: M, - MM: pad(M), - s: s, - ss: pad(s), - l: pad(L, 3), - L: pad(L > 99 ? Math.round(L / 10) : L), - t: H < 12 ? "a" : "p", - tt: H < 12 ? "am" : "pm", - T: H < 12 ? "A" : "P", - TT: H < 12 ? "AM" : "PM", - Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""), - o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), - S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10] - }; + // Allow setting the utc argument via the mask + if (mask.slice(0, 4) == "UTC:") { + mask = mask.slice(4); + utc = true; + } - return mask.replace(token, function ($0) { - return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1); - }); - }; - }(); + var _ = utc ? "getUTC" : "get", + d = date[_ + "Date"](), + D = date[_ + "Day"](), + m = date[_ + "Month"](), + y = date[_ + "FullYear"](), + H = date[_ + "Hours"](), + M = date[_ + "Minutes"](), + s = date[_ + "Seconds"](), + L = date[_ + "Milliseconds"](), + o = utc ? 0 : date.getTimezoneOffset(), + flags = { + d: d, + dd: pad(d), + ddd: dF.i18n.dayNames[D], + dddd: dF.i18n.dayNames[D + 7], + m: m + 1, + mm: pad(m + 1), + mmm: dF.i18n.monthNames[m], + mmmm: dF.i18n.monthNames[m + 12], + yy: String(y).slice(2), + yyyy: y, + h: H % 12 || 12, + hh: pad(H % 12 || 12), + H: H, + HH: pad(H), + M: M, + MM: pad(M), + s: s, + ss: pad(s), + l: pad(L, 3), + L: pad(L > 99 ? Math.round(L / 10) : L), + t: H < 12 ? "a" : "p", + tt: H < 12 ? "am" : "pm", + T: H < 12 ? "A" : "P", + TT: H < 12 ? "AM" : "PM", + Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""), + o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), + S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10] + }; - // Some common format strings - dateFormat.masks = { - "default": "ddd mmm dd yyyy HH:MM:ss", - shortDate: "m/d/yy", - mediumDate: "mmm d, yyyy", - longDate: "mmmm d, yyyy", - fullDate: "dddd, mmmm d, yyyy", - shortTime: "h:MM TT", - mediumTime: "h:MM:ss TT", - longTime: "h:MM:ss TT Z", - isoDate: "yyyy-mm-dd", - isoTime: "HH:MM:ss", - isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", - isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" + return mask.replace(token, function ($0) { + return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1); + }); }; +}(); - // Internationalization strings - dateFormat.i18n = { - dayNames: [ - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", - "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" - ], - monthNames: [ - "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", - "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" - ] - }; +// Some common format strings +dateFormat.masks = { + "default": "ddd mmm dd yyyy HH:MM:ss", + shortDate: "m/d/yy", + mediumDate: "mmm d, yyyy", + longDate: "mmmm d, yyyy", + fullDate: "dddd, mmmm d, yyyy", + shortTime: "h:MM TT", + mediumTime: "h:MM:ss TT", + longTime: "h:MM:ss TT Z", + isoDate: "yyyy-mm-dd", + isoTime: "HH:MM:ss", + isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", + isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" +}; - // For convenience... - Date.prototype.format = function (mask, utc) { - return dateFormat(this, mask, utc); - }; +// Internationalization strings +dateFormat.i18n = { + dayNames: [ + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" + ], + monthNames: [ + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" + ] +}; - return {'dateFormat': dateFormat}; -}); \ No newline at end of file +// For convenience... +Date.prototype.format = function (mask, utc) { + return dateFormat(this, mask, utc); +}; \ No newline at end of file diff --git a/IPython/html/static/notebook/js/celltoolbar.js b/IPython/html/static/notebook/js/celltoolbar.js index a5f4c83..b17bea8 100644 --- a/IPython/html/static/notebook/js/celltoolbar.js +++ b/IPython/html/static/notebook/js/celltoolbar.js @@ -8,16 +8,19 @@ define([ ], function(IPython, $, textcell) { "use strict"; - /** - * @constructor - * @class CellToolbar - * @param {The cell to attach the metadata UI to} cell - */ - var CellToolbar = function (cell, events, notebook) { + var CellToolbar = function (options) { + // Constructor + // + // Parameters: + // options: dictionary + // Dictionary of keyword arguments. + // events: $(Events) instance + // cell: Cell instance + // notebook: Notebook instance CellToolbar._instances.push(this); - this.notebook = notebook; - this.events = events; - this.cell = cell; + this.notebook = options.notebook; + this.events = options.events; + this.cell = options.cell; this.create_element(); this.rebuild(); return this; diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index dd5e917..f1932e7 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -129,7 +129,10 @@ define([ var input = $('
').addClass('input'); var prompt = $('
').addClass('prompt input_prompt'); var inner_cell = $('
').addClass('inner_cell'); - this.celltoolbar = new celltoolbar.CellToolbar(this, this.events, this.notebook); + this.celltoolbar = new celltoolbar.CellToolbar({ + cell: this, + events: this.events, + notebook: this.notebook}); inner_cell.append(this.celltoolbar.element); var input_area = $('
').addClass('input_area'); this.code_mirror = CodeMirror(input_area.get(0), this.cm_config); @@ -159,7 +162,11 @@ define([ var output = $('
'); cell.append(input).append(widget_area).append(output); this.element = cell; - this.output_area = new outputarea.OutputArea(output, true, this.events, this.keyboard_manager); + this.output_area = new outputarea.OutputArea({ + selector: output, + prompt_area: true, + events: this.events, + keyboard_manager: this.keyboard_manager}); this.completer = new completer.Completer(this, this.events); }; diff --git a/IPython/html/static/notebook/js/main.js b/IPython/html/static/notebook/js/main.js index ab0a1cb..cb5d136 100644 --- a/IPython/html/static/notebook/js/main.js +++ b/IPython/html/static/notebook/js/main.js @@ -6,7 +6,6 @@ require([ 'jquery', 'notebook/js/notebook', 'base/js/utils', - 'base/js/keyboard', 'base/js/page', 'notebook/js/layoutmanager', 'base/js/events', @@ -24,7 +23,6 @@ require([ $, notebook, utils, - keyboard, page, layoutmanager, events, @@ -134,5 +132,4 @@ require([ IPython.keyboard_manager = keyboard_manager; IPython.save_widget = save_widget; IPython.config = user_config; - IPython.keyboard = keyboard; }); diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js index 3c7a105..94b28ae 100644 --- a/IPython/html/static/notebook/js/menubar.js +++ b/IPython/html/static/notebook/js/menubar.js @@ -192,7 +192,9 @@ define([ that.notebook.move_cell_down(); }); this.element.find('#edit_nb_metadata').click(function () { - that.notebook.edit_metadata(); + that.notebook.edit_metadata({ + notebook: that.notebook, + keyboard_manager: that.notebook.keyboard_manager}); }); // View diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 95b9a4b..bbdb229 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -13,8 +13,6 @@ define([ 'components/marked/lib/marked', 'notebook/js/mathjaxutils', 'base/js/keyboard', - 'components/jquery-ui/ui/minified/jquery-ui.min', - 'components/bootstrap/js/bootstrap.min', ], function ( IPython, $, @@ -80,11 +78,6 @@ define([ }); } - // Backwards compatability. - IPython.keyboard_manager = this.keyboard_manager; - IPython.save_widget = this.save_widget; - IPython.keyboard = this.keyboard; - this.element = $(selector); this.element.scroll(); this.element.data("notebook", this); @@ -314,9 +307,14 @@ define([ Notebook.prototype.edit_metadata = function () { var that = this; - dialog.edit_metadata(this.metadata, function (md) { - that.metadata = md; - }, 'Notebook'); + dialog.edit_metadata({ + md: this.metadata, + callback: function (md) { + that.metadata = md; + }, + name: 'Notebook', + notebook: this, + keyboard_manager: this.keyboard_manager}); }; // Cell indexing, retrieval, etc. diff --git a/IPython/html/static/notebook/js/notificationwidget.js b/IPython/html/static/notebook/js/notificationwidget.js index 0a1f725..51c40e7 100644 --- a/IPython/html/static/notebook/js/notificationwidget.js +++ b/IPython/html/static/notebook/js/notificationwidget.js @@ -35,12 +35,12 @@ define([ // if timeout <= 0 // click_callback : function called if user click on notification // could return false to prevent the notification to be dismissed - NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, opts) { - opts = opts || {}; + NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, options) { + options = options || {}; var callback = click_callback || function() {return false;}; var that = this; - this.inner.attr('class', opts.icon); - this.inner.attr('title', opts.title); + this.inner.attr('class', options.icon); + this.inner.attr('title', options.title); this.inner.text(msg); this.element.fadeIn(100); if (this.timeout !== null) { diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index 6480873..2a4f208 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -17,20 +17,20 @@ define([ * @constructor */ - var OutputArea = function (selector, prompt_area, events, keyboard_manager) { - this.selector = selector; - this.events = events; - this.keyboard_manager = keyboard_manager; - this.wrapper = $(selector); + var OutputArea = function (options) { + this.selector = options.selector; + this.events = options.events; + this.keyboard_manager = options.keyboard_manager; + this.wrapper = $(options.selector); this.outputs = []; this.collapsed = false; this.scrolled = false; this.trusted = true; this.clear_queued = null; - if (prompt_area === undefined) { + if (options.prompt_area === undefined) { this.prompt_area = true; } else { - this.prompt_area = prompt_area; + this.prompt_area = options.prompt_area; } this.create_elements(); this.style(); diff --git a/IPython/html/static/notebook/js/savewidget.js b/IPython/html/static/notebook/js/savewidget.js index f66941c..b57abd8 100644 --- a/IPython/html/static/notebook/js/savewidget.js +++ b/IPython/html/static/notebook/js/savewidget.js @@ -7,7 +7,7 @@ define([ 'base/js/utils', 'base/js/dialog', 'base/js/keyboard', - 'dateformat/date.format', + 'dateformat', ], function(IPython, $, utils, dialog, keyboard) { "use strict"; diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index 393a9fb..b99455d 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -76,7 +76,10 @@ define([ var prompt = $('
').addClass('prompt input_prompt'); cell.append(prompt); var inner_cell = $('
').addClass('inner_cell'); - this.celltoolbar = new celltoolbar.CellToolbar(this, this.events, this.notebook); + this.celltoolbar = new celltoolbar.CellToolbar({ + cell: this, + events: this.events, + notebook: this.notebook}); inner_cell.append(this.celltoolbar.element); var input_area = $('
').addClass('input_area'); this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config); @@ -451,11 +454,11 @@ define([ IPython.RawCell = RawCell; IPython.HeadingCell = HeadingCell; - var Cells = { + var textcell = { 'TextCell': TextCell, 'MarkdownCell': MarkdownCell, 'RawCell': RawCell, 'HeadingCell': HeadingCell, }; - return Cells; + return textcell; }); diff --git a/IPython/html/templates/page.html b/IPython/html/templates/page.html index a693ac0..49763e7 100644 --- a/IPython/html/templates/page.html +++ b/IPython/html/templates/page.html @@ -24,6 +24,7 @@ backbone : 'components/backbone/backbone-min', jquery: 'components/jquery/jquery.min', bootstraptour: 'components/bootstrap-tour/build/js/bootstrap-tour.min', + dateformat: 'dateformat/date.format', }, shim: { underscore: { @@ -35,6 +36,9 @@ }, bootstraptour: { exports: "Tour" + }, + dateformat: { + exports: "dateFormat" } } });