##// END OF EJS Templates
various unicode fixes...
various unicode fixes - remove notebookPath, notebookName, and baseProjectUrl methods everywhere - use base_project_url *attributes* instead - we should never use escaped URLs except when making an actual request Should fix issues with double-escaping

File last commit:

r11033:fa36e98f
r15234:1dd0f22d
Show More
example.js
154 lines | 5.7 KiB | application/javascript | JavascriptLexer
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 //----------------------------------------------------------------------------
// Copyright (C) 2012 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
//============================================================================
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 // CellToolbar Example
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 //============================================================================
/**
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 * Example Use for the CellToolbar library
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 * add the following to your custom.js to load
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 * Celltoolbar UI for slideshow
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 *
* ```
Matthias BUSSONNIER
fix example.js
r9083 * $.getScript('/static/js/celltoolbarpresets/example.js');
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 * ```
*/
// IIFE without asignement, we don't modifiy the IPython namespace
(function (IPython) {
"use strict";
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 var CellToolbar = IPython.CellToolbar;
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057
Matthias BUSSONNIER
fix example.js
r9083 var example_preset = [];
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 var simple_button = function(div, cell) {
var button_container = $(div);
var button = $('<div/>').button({icons:{primary:'ui-icon-locked'}});
var fun = function(value){
try{
if(value){
cell.code_mirror.setOption('readOnly','nocursor')
button.button('option','icons',{primary:'ui-icon-locked'})
} else {
Matthias BUSSONNIER
fix lock cell button...
r9075 cell.code_mirror.setOption('readOnly',false)
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 button.button('option','icons',{primary:'ui-icon-unlocked'})
}
} catch(e){}
}
fun(cell.metadata.ro)
button.click(function(){
var v = cell.metadata.ro;
var locked = !v;
cell.metadata.ro = locked;
fun(locked)
})
.css('height','16px')
.css('width','35px');
button_container.append(button);
}
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 CellToolbar.register_callback('example.lock',simple_button);
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 example_preset.push('example.lock');
var toggle_test = function(div, cell) {
var button_container = $(div)
Matthias BUSSONNIER
fix css size
r9070 var button = $('<div/>')
.button({label:String(cell.metadata.foo)}).
css('width','65px');
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 button.click(function(){
var v = cell.metadata.foo;
cell.metadata.foo = !v;
button.button("option","label",String(!v));
})
button_container.append(button);
}
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 CellToolbar.register_callback('example.toggle',toggle_test);
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 example_preset.push('example.toggle');
Matthias BUSSONNIER
slightly generalize utils generator
r9072 var checkbox_test = CellToolbar.utils.checkbox_ui_generator('Yes/No',
// setter
function(cell, value){
// we check that the slideshow namespace exist and create it if needed
if (cell.metadata.yn_test == undefined){cell.metadata.yn_test = {}}
// set the value
cell.metadata.yn_test.value = value
},
//geter
function(cell){ var ns = cell.metadata.yn_test;
// if the slideshow namespace does not exist return `undefined`
// (will be interpreted as `false` by checkbox) otherwise
// return the value
return (ns == undefined)? undefined: ns.value
}
);
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 CellToolbar.register_callback('example.checkbox',checkbox_test);
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 example_preset.push('example.checkbox');
Matthias BUSSONNIER
slightly generalize utils generator
r9072 var select_test = CellToolbar.utils.select_ui_generator([
["-" ,undefined ],
["Header Slide" ,"header_slide" ],
["Slide" ,"slide" ],
["Fragment" ,"fragment" ],
["Skip" ,"skip" ],
],
// setter
function(cell,value){
// we check that the slideshow namespace exist and create it if needed
if (cell.metadata.test == undefined){cell.metadata.test = {}}
// set the value
cell.metadata.test.slide_type = value
},
//geter
function(cell){ var ns = cell.metadata.test;
// if the slideshow namespace does not exist return `undefined`
// (will be interpreted as `false` by checkbox) otherwise
// return the value
return (ns == undefined)? undefined: ns.slide_type
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 });
Matthias BUSSONNIER
rename metaui -> celltoolbar
r9064 CellToolbar.register_callback('example.select',select_test);
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057 example_preset.push('example.select');
Matthias BUSSONNIER
remove most of the duplicate example
r9067 var simple_dialog = function(title,text){
var dlg = $('<div/>').attr('title',title)
.append($('<p/>').text(text))
$(dlg).dialog({
autoOpen: true,
height: 300,
width: 650,
modal: true,
close: function() {
//cleanup on close
$(this).remove();
}
});
}
var add_simple_dialog_button = function(div, cell) {
var help_text = ["This is the Metadata editting UI.",
"It heavily rely on plugin to work ",
"and is still under developpement. You shouldn't wait too long before",
" seeing some customisable buttons in those toolbar."
].join('\n')
var button_container = $(div)
var button = $('<div/>').button({label:'?'})
.click(function(){simple_dialog('help',help_text); return false;})
button_container.append(button);
}
CellToolbar.register_callback('example.help',add_simple_dialog_button)
example_preset.push('example.help')
Matthias BUSSONNIER
Capitalize
r9082 CellToolbar.register_preset('Example',example_preset);
Brian E. Granger
Removing call to $.browser which went away in jQuery 1.9....
r9227 console.log('Example extension for metadata editing loaded.');
Matthias BUSSONNIER
Split metadataui into multiple file...
r9057
}(IPython));