function init(){ var ubwidget = $("#ubwidget").ubwidget({ width:360, height:240 }); var checkMinimize = false; var text = ""; var winwidth; var minimizedHeight; var winheight; var scroll = false; var defaultFontSize = 35; var currentFontSize = defaultFontSize; var header = $(''); var fontUp = $(''); var fontDown = $(''); var minimize = $(''); var maximize = $(''); var title = $(''); var textField = $('
'); var shadow = $("
 
") .appendTo("body"); var shadowleft = $("") .appendTo($("#sl")); var shadowright = $("") .appendTo($("#sr")); $("#ubwidget") .append(header) .append(textField); fontUp.addClass('menuElement'); fontDown.addClass('menuElement'); minimize.addClass('menuElement'); maximize.addClass('menuElement') .hide(); header.append(maximize) .append(minimize) .append(fontUp) .append(fontDown); var titletext = header.find('textarea'); titletext.click( function(){ titletext.focus(); }); fontDown.click( function(){ var newFontSize = parseInt(currentFontSize) - 3; textField.css({ fontSize : newFontSize }) controlTextField(); if(window.sankore){ window.sankore.setPreference("fontSize", newFontSize); }; if(!checkMinimize) textField.focus(); }); fontUp.click( function(){ var newFontSize = parseInt(currentFontSize) + 3; textField.css({ fontSize : newFontSize }) controlTextField(); if(window.sankore){ window.sankore.setPreference("fontSize", newFontSize); }; if(!checkMinimize) textField.focus(); }); minimize.click( function(){ $('.ubw-container').animate({height:"26px"},500); minimizedHeight = $('.ubw-container').height(); minimize.hide(); maximize.show(); controlTextField(); $('#headtitle').show(); $('#headtitle').focus(); //window.resizeTo($('.ubw-container').width(),0); checkMinimize = true; }); maximize.click( function(){ var lastHeight = String(minimizedHeight)+'px'; $('.ubw-container').animate({height: lastHeight},500); maximize.hide(); minimize.show(); $('#headtitle').hide(); //textField.focus(); //window.resizeTo($('.ubw-container').width()+15,minimizedHeight+20); checkMinimize = false; }); header .append(title); title .addClass('menu'); header .addClass('head'); textField .addClass("textField") .css("fontSize",currentFontSize) .attr('contentEditable','true') .keyup(function(){ if(window.sankore){ window.sankore.setPreference("text", textField.html()); } controlTextField(); //$('#headtitle').hide(); }); if(textField.html().length === 0){ textField.focus(); } titletext .attr('rows','1'); function controlTextField(){ if(textField.text().length < 25) $('#headtitle').val(textField.text()); else $('#headtitle').val(textField.text().substr(0,25) + "..."); textField.css({ height : $('.ubw-container').height()-28, }) if(textField.text().length == 0){ textField.css({ fontSize: defaultFontSize, }); } currentFontSize = textField.css('fontSize').replace('px',''); } textField.bind('paste', function(e) { controlTextField(); }); $('#headtitle').hide(); if(window.sankore){ text = window.sankore.preference('text', text); currentFontSize = window.sankore.preference('fontSize', defaultFontSize); $('.ubw-container').css({ width:window.innerWidth - 2, height:window.innerHeight - 20 }); if(checkMinimize){ minimize.trigger("click"); }; textField.css({ fontSize : parseInt(currentFontSize) }) textField.html(text); } window.onresize = function(){ winwidth = window.innerWidth; winheight = window.innerHeight; if(winwidth <= 290) { window.resizeTo(290,winheight); } if(winheight <= 100) { window.resizeTo(winwidth,100); } if(winheight > 600) { window.resizeTo(winwidth,600); } $('.ubw-container').width(winwidth-2); if(checkMinimize) minimizedHeight = winheight-40; else $('.ubw-container').height(winheight-40); controlTextField(); } }