parent
f7dda94b90
commit
13ae3074cc
@ -0,0 +1,87 @@ |
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
function add_ob_setup( player_id ) |
||||
{ |
||||
// add a new OB setup
|
||||
edit_ob_setup( $("#ob_setup-sortable_"+player_id), null ) ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
function edit_ob_setup( $sortable, $entry ) |
||||
{ |
||||
var $caption, $width ; |
||||
|
||||
// let the user edit the OB setup
|
||||
$("#edit-ob_setup").dialog( { |
||||
dialogClass: "edit-ob_setup", |
||||
modal: true, |
||||
minWidth: 400, |
||||
minHeight: 150, |
||||
open: function() { |
||||
$caption = $(this).children( "textarea" ) ; |
||||
$width = $(this).children( "input[type='text']" ) ; |
||||
if ( $entry ) { |
||||
var data = $entry.data( "sortable-data" ) ; |
||||
$caption.val( data.caption ) ; |
||||
$width.val( data.width ) ; |
||||
} |
||||
else { |
||||
$caption.val( "" ) ; |
||||
$width.val( "" ) ; |
||||
} |
||||
$(this).height( $(this).height() ) ; // fudge: force the textarea to resize
|
||||
}, |
||||
buttons: { |
||||
OK: function() { |
||||
var caption = $caption.val().trim() ; |
||||
var width = $width.val().trim() ; |
||||
if ( $entry ) { |
||||
// update the existing OB setup
|
||||
if ( caption === "" ) |
||||
delete_sortable_entry( $entry ) ; |
||||
else { |
||||
$entry.data("sortable-data").caption = caption ; |
||||
$entry.data("sortable-data").width = width ; |
||||
$entry.empty().append( _make_sortable_entry( caption ) ) ; |
||||
} |
||||
} |
||||
else { |
||||
// create a new OB setup
|
||||
if ( caption !== "" ) { |
||||
data = { caption: caption, width: width } ; |
||||
do_add_ob_setup( $sortable, data ) ; |
||||
} |
||||
} |
||||
$(this).dialog( "close" ) ; |
||||
}, |
||||
Cancel: function() { $(this).dialog( "close" ) ; }, |
||||
}, |
||||
} ) ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
function do_add_ob_setup( $sortable, data ) |
||||
{ |
||||
// add a new sortable entry
|
||||
add_sortable( $sortable, _make_sortable_entry(data.caption), data ) ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
function _make_sortable_entry( caption ) |
||||
{ |
||||
// generate the sortable entry
|
||||
var $content = $( "<div><input type='button' data-id='ob_setup' value='Snippet'>" + caption + "</div>" ) ; |
||||
|
||||
// add a handler for the snippet button
|
||||
$content.children("input[type='button']").click( function() { |
||||
var data = $(this).parent().parent().data( "sortable-data" ) ; |
||||
var extra_params = { OB_SETUP: data.caption, OB_SETUP_WIDTH: data.width } ; |
||||
generate_snippet( $(this), extra_params ) ; |
||||
} ) ; |
||||
|
||||
return $content ; |
||||
} |
@ -0,0 +1,110 @@ |
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
function init_sortable( $sortable, on_add, on_edit ) |
||||
{ |
||||
// initialize the support elements
|
||||
var $add = _find_sortable_helper( $sortable, "add" ) ; |
||||
$add.click( on_add ) ; |
||||
$sortable.data( "on_edit", on_edit ) ; |
||||
|
||||
// handle dragging entries to the trash
|
||||
var $trash = _find_sortable_helper( $sortable, "trash" ) ; |
||||
$sortable.sortable( { connectWith: $trash, cursor: "move" } ) ; |
||||
$trash.sortable( { |
||||
receive: function( evt, ui ) { |
||||
ui.item.remove() ; |
||||
update_sortable_hint($sortable) ; |
||||
} |
||||
} ) ; |
||||
} |
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
function add_sortable( $sortable, $content, sortable_data ) |
||||
{ |
||||
// add a new entry to the sortable
|
||||
var $entry = $( "<li></li>" ) ; |
||||
$entry.append( $content ) ; |
||||
$entry.data( "sortable-data", sortable_data ) ; |
||||
$sortable.append( $entry ) ; |
||||
init_sortable_entry( $entry ) ; |
||||
|
||||
// update the hint
|
||||
update_sortable_hint( $sortable ) ; |
||||
|
||||
return $entry ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
function init_sortable_entry( $entry ) |
||||
{ |
||||
// initialize the sortable entry
|
||||
var $sortable = $entry.parent() ; |
||||
$entry.dblclick( function() { |
||||
$sortable.data("on_edit")( $sortable, $entry ) ; |
||||
} ) ; |
||||
$entry.click( function( evt ) { |
||||
if ( evt.ctrlKey ) |
||||
delete_sortable_entry( $(this) ) ; |
||||
} ) ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
function update_sortable_hint( $sortable ) |
||||
{ |
||||
// show/hide the hint
|
||||
var $hint = _find_sortable_helper( $sortable, "hint" ) ; |
||||
if ( $sortable.children("li").length === 0 ) { |
||||
$sortable.hide() ; |
||||
$hint.show() ; |
||||
} else { |
||||
$sortable.show() ; |
||||
$hint.hide() ; |
||||
} |
||||
} |
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
function delete_sortable_entry( $entry ) |
||||
{ |
||||
// initialize
|
||||
var $sortable = $entry.parent() ; |
||||
|
||||
// ask if it's OK to delete the entry
|
||||
$entry.addClass( "highlighted" ) ; |
||||
var caption = $entry.data("sortable-data").caption ; |
||||
if ( ! caption ) |
||||
caption = $entry.html() ; |
||||
ask( "OK to delete?", escapeHTML(caption), { |
||||
"ok": function() { |
||||
// yup - make it so
|
||||
$entry.remove() ; |
||||
update_sortable_hint( $sortable ) ; |
||||
}, |
||||
"close": function() { $entry.removeClass("highlighted") ; }, |
||||
} ) ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
function delete_all_sortable_entries( $sortable ) |
||||
{ |
||||
// delete all entries from the sortable
|
||||
$sortable.children("li").each( function() { |
||||
$(this).remove() ; |
||||
} ) ; |
||||
update_sortable_hint( $sortable ) ; |
||||
} |
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
function _find_sortable_helper( $sortable, type ) |
||||
{ |
||||
// find a support element for the specified sortable
|
||||
var id = $sortable.prop( "id" ) ; |
||||
var pos = id.indexOf( "sortable" ) ; |
||||
return $( "#" + id.substring(0,pos) + type+ id.substring(pos+8) ) ; |
||||
} |
Loading…
Reference in new issue