function openWikiBlockEditor( htmlElement, entityDefinition, blockId, handler ) { ping( "/clientUI/openSession.aspx", function( text ) { var host = document.getElementById( "editorHost" ); host.Initialize( "http://lagotek.com/clientUI/cuservice.aspx", text ); setTimeout( function() { host.ShowEditor( entityDefinition.EditorClass, blockId ); startPolling( handler ); }, 10 ); } ); } function editWikiBlock( htmlElement, entityDefinition, blockId, callback ) { openWikiBlockEditor( htmlElement, entityDefinition, blockId, function( modalResult, returnValue ) { ping( getEntityTextPath( entityDefinition, blockId ), function( text ) { if ( callback ) callback(); htmlElement.innerHTML = text; } ); } ); } function createWikiBlock( htmlElement, entityDefinition, menuFunction, callback ) { openWikiBlockEditor( htmlElement, entityDefinition, "", function( modalResult, id ) { if ( !htmlElement ) { if ( callback ) callback(); return; } if ( !id ) { return; } ping( getEntityTextPath( entityDefinition, id ), function( text ) { if ( callback ) callback(); var parent = htmlElement.parentElement; var span = document.createElement( "span" ); span.onmouseover = function() { menuFunction( span, id ) }; span.innerHTML = text; parent.insertBefore( span, htmlElement ); } ); } ); } function getEntityTextPath( entityDefinition, blockId ) { var entityName = entityDefinition.EntityName; var controlPath = entityDefinition.ControlPath; if ( controlPath != '' ) { controlPath = "&control=" + controlPath; } if ( entityDefinition.HasSeparator ) { controlPath += "&includeSeparator=1"; } return "/clientUI/getEntityText.aspx?entity=" + entityName + "&id=" + blockId + controlPath; } function deleteWikiBlock( htmlElement, entityDefinition, blockId, callback ) { ping( '/clientui/deleteEntity.aspx?entity=' + entityDefinition.EntityName + '&id=' + blockId, function( text ) { if ( callback ) callback(); var parent = htmlElement.parentElement; parent.removeChild( htmlElement ); } ); } function startPolling( cb ) { var host = document.getElementById( "editorHost" ); setTimeout( function() { if ( host.EditorVisible ) { startPolling( cb ); } else { cb( host.ModalResult, host.ReturnValue ); } }, 500 ); }