2009-06-11 17:43:45 +00:00
/ *
2011-07-30 05:22:57 -03:00
* Copyright [ 2011 ] [ wisemapping ]
*
* Licensed under WiseMapping Public License , Version 1.0 ( the "License" ) .
* It is basically the Apache License , Version 2.0 ( the "License" ) plus the
* "powered by wisemapping" text requirement on every single page ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the license at
*
* http : //www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
2009-06-11 17:43:45 +00:00
* /
2011-08-25 22:08:39 -03:00
Asset . javascript ( '../js/mindplot-min.js' , {
2011-07-30 05:22:57 -03:00
id : 'MindplotSVGLib' ,
onLoad : function ( ) {
afterMindpotLibraryLoading ( ) ;
}
} ) ;
2009-06-07 18:59:43 +00:00
var designer = null ;
/* JavaScript tabs changer */
// CSS helper functions
CSS = {
// Adds a class to an element.
AddClass : function ( e , c ) {
if ( ! e . className . match ( new RegExp ( "\\b" + c + "\\b" , "i" ) ) )
e . className += ( e . className ? " " : "" ) + c ;
} ,
// Removes a class from an element.
RemoveClass : function ( e , c ) {
e . className = e . className . replace ( new RegExp ( " \\b" + c + "\\b|\\b" + c + "\\b ?" , "gi" ) , "" ) ;
}
} ;
// Functions for handling tabs.
Tabs = {
// Changes to the tab with the specified ID.
GoTo : function ( contentId , skipReplace ) {
// This variable will be true if a tab for the specified
// content ID was found.
var foundTab = false ;
// Get the TOC element.
var toc = $ ( "toc" ) ;
if ( toc ) {
var lis = toc . getElementsByTagName ( "li" ) ;
for ( var j = 0 ; j < lis . length ; j ++ ) {
var li = lis [ j ] ;
// Give the current tab link the class "current" and
// remove the class from any other TOC links.
var anchors = li . getElementsByTagName ( "a" ) ;
var anchors = li . getElementsByTagName ( "a" ) ;
for ( var k = 0 ; k < anchors . length ; k ++ ) {
if ( anchors [ k ] . hash == "#" + contentId ) {
CSS . AddClass ( li , "current" ) ;
foundTab = true ;
break ;
} else {
CSS . RemoveClass ( li , "current" ) ;
}
}
}
}
// Show the content with the specified ID.
var divsToHide = [ ] ;
var divs = document . getElementsByTagName ( "div" ) ;
for ( var i = 0 ; i < divs . length ; i ++ ) {
var div = divs [ i ] ;
if ( div . className . match ( /\btabContent\b/i ) ) {
if ( div . id == "_" + contentId )
div . style . display = "block" ;
2011-07-30 05:22:57 -03:00
else {
2009-06-07 18:59:43 +00:00
divsToHide . push ( div ) ;
}
}
}
// Hide the other content boxes.
for ( var i = 0 ; i < divsToHide . length ; i ++ )
divsToHide [ i ] . style . display = "none" ;
// Change the address bar.
if ( ! skipReplace ) window . location . replace ( "#" + contentId ) ;
} ,
OnClickHandler : function ( e ) {
// Stop the event (to stop it from scrolling or
// making an entry in the history).
if ( ! e ) e = window . event ;
if ( e . preventDefault ) e . preventDefault ( ) ; else e . returnValue = false ;
// Get the name of the anchor of the link that was clicked.
Tabs . GoTo ( this . hash . substring ( 1 ) ) ;
} ,
Init : function ( ) {
2011-07-30 05:22:57 -03:00
if ( ! document . getElementsByTagName ) {
2009-06-07 18:59:43 +00:00
return ;
}
// Attach an onclick event to all the anchor links on the page.
var anchors = document . getElementsByTagName ( "a" ) ;
for ( var i = 0 ; i < anchors . length ; i ++ ) {
var a = anchors [ i ] ;
if ( a . hash ) {
a . onclick = Tabs . OnClickHandler ;
}
}
var contentId ;
if ( window . location . hash )
contentId = window . location . hash . substring ( 1 ) ;
var divs = document . getElementsByTagName ( "div" ) ;
for ( var i = 0 ; i < divs . length ; i ++ ) {
var div = divs [ i ] ;
if ( div . className . match ( /\btabContent\b/i ) ) {
if ( ! contentId ) contentId = div . id ;
div . id = "_" + div . id ;
}
}
if ( contentId )
Tabs . GoTo ( contentId , true ) ;
}
} ;
if ( document . createStyleSheet ) {
var style = document . createStyleSheet ( ) ;
style . addRule ( "div.tabContent" , "display: none;" ) ;
style . addRule ( "div" + contentId , "display: block;" ) ;
} else {
var head = document . getElementsByTagName ( "head" ) [ 0 ] ;
if ( head ) {
var style = document . createElement ( "style" ) ;
style . setAttribute ( "type" , "text/css" ) ;
style . appendChild ( document . createTextNode ( "div.tabContent { display: none; }" ) ) ;
style . appendChild ( document . createTextNode ( "div" + contentId + " { display: block; }" ) ) ;
head . appendChild ( style ) ;
}
}
// Hook up the OnLoad event to the tab initialization function.
Tabs . Init ( ) ;
// Hide the content while waiting for the onload event to trigger.
var contentId = window . location . hash || "#Introduction" ;
2011-07-30 05:22:57 -03:00
function afterMindpotLibraryLoading ( ) {
2009-06-07 18:59:43 +00:00
buildMindmapDesigner ( ) ;
2011-07-30 05:22:57 -03:00
if ( $ ( 'helpButton' ) != null ) {
2009-06-07 18:59:43 +00:00
var helpPanel = new Panel ( { panelButton : $ ( 'helpButton' ) , backgroundColor : 'black' } ) ;
helpPanel . setContent ( Help . buildHelp ( helpPanel ) ) ;
}
2011-07-30 05:22:57 -03:00
if ( $ ( 'helpButtonFirstSteps' ) != null ) {
2009-06-07 18:59:43 +00:00
var firstStepsPanel = $ ( 'helpButtonFirstSteps' )
firstStepsPanel . addEvent ( 'click' , function ( event ) {
var firstStepWindow = window . open ( "firststeps.htm" , "WiseMapping" , "width=100px, height=100px" ) ;
firstStepWindow . focus ( ) ;
firstStepWindow . moveTo ( 0 , 0 ) ;
firstStepWindow . resizeTo ( screen . availWidth , screen . availHeight ) ;
} ) ;
2011-03-28 01:33:16 -03:00
}
2009-06-07 18:59:43 +00:00
2011-07-30 05:22:57 -03:00
if ( $ ( 'helpButtonKeyboard' ) != null ) {
2009-06-07 18:59:43 +00:00
var keyboardPanel = $ ( 'helpButtonKeyboard' )
keyboardPanel . addEvent ( 'click' , function ( event ) {
MOOdalBox . open ( 'keyboard.htm' , 'KeyBoard Shortcuts' , '500px 400px' , false )
} ) ;
}
// Save event handler ....
var saveButton = $ ( 'saveButton' ) ;
saveButton . addEvent ( 'click' , function ( event ) {
2011-07-30 05:22:57 -03:00
if ( ! isTryMode ) {
2009-06-07 18:59:43 +00:00
saveButton . setStyle ( 'cursor' , 'wait' ) ;
2011-07-30 05:22:57 -03:00
var saveFunc = function ( ) {
designer . save ( function ( ) {
2009-06-07 18:59:43 +00:00
var monitor = core . Monitor . getInstance ( ) ;
monitor . logMessage ( 'Save completed successfully' ) ;
saveButton . setStyle ( 'cursor' , 'pointer' ) ;
} , true ) ;
}
saveFunc . delay ( 1 ) ;
2011-07-30 05:22:57 -03:00
} else {
2011-04-06 11:20:15 +01:00
new Windoo . Confirm ( 'This option is not enabled in try mode. You must by signed in order to execute this action.<br/> to create an account click <a href="userRegistration.htm">here</a>' ,
2011-07-30 05:22:57 -03:00
{
'window' : { theme : Windoo . Themes . wise ,
title : ''
}
} ) ;
2009-06-07 18:59:43 +00:00
}
} ) ;
var discardButton = $ ( 'discardButton' ) ;
discardButton . addEvent ( 'click' , function ( event ) {
2011-07-30 05:22:57 -03:00
if ( ! isTryMode ) {
2009-06-07 18:59:43 +00:00
displayLoading ( ) ;
window . document . location = "mymaps.htm" ;
2011-07-30 05:22:57 -03:00
} else {
2011-04-06 11:20:15 +01:00
displayLoading ( ) ;
window . document . location = "home.htm" ;
2011-07-30 05:22:57 -03:00
}
} ) ;
2009-06-07 18:59:43 +00:00
2011-07-30 05:22:57 -03:00
if ( isTryMode ) {
$ ( 'tagIt' ) . addEvent ( 'click' , function ( event ) {
2009-06-07 18:59:43 +00:00
new Windoo . Confirm ( 'This option is not enabled in try mode. You must by signed in order to execute this action.' ,
2011-07-30 05:22:57 -03:00
{
'window' : { theme : Windoo . Themes . wise ,
title : ''
}
} ) ;
2009-06-07 18:59:43 +00:00
} ) ;
2011-07-30 05:22:57 -03:00
$ ( 'shareIt' ) . addEvent ( 'click' , function ( event ) {
2009-06-07 18:59:43 +00:00
new Windoo . Confirm ( 'This option is not enabled in try mode. You must by signed in order to execute this action.' ,
2011-07-30 05:22:57 -03:00
{
'window' : { theme : Windoo . Themes . wise ,
title : ''
}
} ) ;
2009-06-07 18:59:43 +00:00
} ) ;
2011-07-30 05:22:57 -03:00
$ ( 'publishIt' ) . addEvent ( 'click' , function ( event ) {
2009-06-07 18:59:43 +00:00
new Windoo . Confirm ( 'This option is not enabled in try mode. You must by signed in order to execute this action.' ,
2011-07-30 05:22:57 -03:00
{
'window' : { theme : Windoo . Themes . wise ,
title : ''
}
} ) ;
2009-06-07 18:59:43 +00:00
} ) ;
2011-07-30 05:22:57 -03:00
$ ( 'history' ) . addEvent ( 'click' , function ( event ) {
2009-06-07 18:59:43 +00:00
new Windoo . Confirm ( 'This option is not enabled in try mode. You must by signed in order to execute this action.' ,
2011-07-30 05:22:57 -03:00
{
'window' : { theme : Windoo . Themes . wise ,
title : ''
}
} ) ;
2009-06-07 18:59:43 +00:00
} ) ;
}
// Autosave ...
2011-07-30 05:22:57 -03:00
if ( ! isTryMode ) {
2011-08-19 13:38:37 -03:00
( function ( ) {
2009-06-07 18:59:43 +00:00
2011-07-30 05:22:57 -03:00
if ( designer . needsSave ( ) ) {
designer . save ( function ( ) {
2009-06-07 18:59:43 +00:00
var monitor = core . Monitor . getInstance ( ) ;
} , false ) ;
}
2011-08-19 13:38:37 -03:00
} ) . periodical ( 30000 ) ;
2009-06-07 18:59:43 +00:00
// To prevent the user from leaving the page with changes ...
2011-08-05 01:06:56 -03:00
window . onbeforeunload = function ( ) {
2011-07-30 05:22:57 -03:00
if ( designer . needsSave ( ) ) {
2009-06-07 18:59:43 +00:00
designer . save ( null , false )
}
}
}
2011-08-08 09:20:32 -03:00
var menu = new mindplot . widget . Menu ( designer ) ;
// If a node has focus, focus can be move to another node using the keys.
2011-08-19 13:38:37 -03:00
designer . _cleanScreen = function ( ) {
menu . clear ( )
} ;
2009-06-07 18:59:43 +00:00
2009-06-11 17:43:45 +00:00
// If not problem has occured, I close the dialod ...
2011-07-30 05:22:57 -03:00
var closeDialog = function ( ) {
2009-06-11 17:43:45 +00:00
2011-07-30 05:22:57 -03:00
if ( ! window . hasUnexpectedErrors ) {
2009-06-11 17:43:45 +00:00
waitDialog . deactivate ( ) ;
}
} . delay ( 500 ) ;
2009-06-07 18:59:43 +00:00
}
2011-07-30 05:22:57 -03:00
function buildMindmapDesigner ( ) {
2009-06-07 18:59:43 +00:00
// Initialize message logger ...
var monitor = new core . Monitor ( $ ( 'msgLoggerContainer' ) , $ ( 'msgLogger' ) ) ;
core . Monitor . setInstance ( monitor ) ;
// Initialize Editor ...
2011-08-26 19:41:50 -03:00
var container = $ ( 'mindplot' ) ;
// container.setStyles({
// height: screen.height - 151,
// width: screen.width
// });
container . setStyles ( {
height : window . getHeight ( ) - 151 ,
width : window . getWidth ( )
} ) ;
2009-06-07 18:59:43 +00:00
2010-12-13 11:07:20 -03:00
designer = new mindplot . MindmapDesigner ( editorProperties , container ) ;
2009-06-07 18:59:43 +00:00
designer . loadFromXML ( mapId , mapXml ) ;
// Save map on load ....
2011-07-30 05:22:57 -03:00
if ( editorProperties . saveOnLoad ) {
2009-06-07 18:59:43 +00:00
var saveOnLoad = function ( ) {
designer . save ( function ( ) {
} , false ) ;
} . delay ( 1000 )
}
2011-08-19 13:38:37 -03:00
}
;
2009-06-07 18:59:43 +00:00