feature(view,edit,console,menu) add Loading check

This commit is contained in:
coderaiser 2013-09-13 11:41:19 +00:00
parent acfc827555
commit 8f294504e1
4 changed files with 144 additions and 123 deletions

View file

@ -6,6 +6,7 @@ var CloudCmd, Util, DOM, $;
function ConsoleProto(CloudCmd, Util, DOM){
var Name = 'Console',
Loading,
jqconsole,
Element,
MouseBinded,
@ -16,6 +17,8 @@ var CloudCmd, Util, DOM, $;
this.init = function(pCallBack) {
var lFunc, lIsFunc = Util.isFunction(CloudCmd.View);
Loading = true;
if (lIsFunc)
lFunc = CloudCmd.View;
else
@ -36,65 +39,67 @@ var CloudCmd, Util, DOM, $;
};
this.show = function() {
Images.showLoad({top:true});
if (!Element) {
Element = DOM.anyload({
name : 'div',
className : 'console'
});
if (!Loading) {
Images.showLoad({top:true});
jqconsole = $(Element).jqconsole('', '> ');
// Abort prompt on Ctrl+Z.
jqconsole.RegisterShortcut('Z', function() {
jqconsole.AbortPrompt();
handler();
});
// Handle a command.
var handler = function(command) {
var lSocket = CloudCmd.Socket;
if (command) {
Images.showLoad({ top:true });
if(lSocket)
lSocket.send(command);
}
jqconsole.Prompt(true, handler);
};
// Initiate the first prompt.
handler();
}
CloudCmd.View.show(Element, function(){
var l$Console = jqconsole.$console,
l$Input = jqconsole.$input_source,
lFocus = function(){
var x = window.scrollX,
y = window.scrollY;
l$Input.focus();
window.scrollTo(x,y);
};
lFocus();
if (!MouseBinded) {
MouseBinded = true;
$(l$Console).unbind('mouseup');
$(l$Console).mouseup(function() {
if( !window.getSelection().toString() ) {
var lTop = l$Console.scrollTop();
lFocus();
l$Console.scrollTop(lTop);
}
if (!Element) {
Element = DOM.anyload({
name : 'div',
className : 'console'
});
jqconsole = $(Element).jqconsole('', '> ');
// Abort prompt on Ctrl+Z.
jqconsole.RegisterShortcut('Z', function() {
jqconsole.AbortPrompt();
handler();
});
// Handle a command.
var handler = function(command) {
var lSocket = CloudCmd.Socket;
if (command) {
Images.showLoad({ top:true });
if(lSocket)
lSocket.send(command);
}
jqconsole.Prompt(true, handler);
};
// Initiate the first prompt.
handler();
}
});
CloudCmd.View.show(Element, function(){
var l$Console = jqconsole.$console,
l$Input = jqconsole.$input_source,
lFocus = function(){
var x = window.scrollX,
y = window.scrollY;
l$Input.focus();
window.scrollTo(x,y);
};
lFocus();
if (!MouseBinded) {
MouseBinded = true;
$(l$Console).unbind('mouseup');
$(l$Console).mouseup(function() {
if( !window.getSelection().toString() ) {
var lTop = l$Console.scrollTop();
lFocus();
l$Console.scrollTop(lTop);
}
});
}
});
}
};
this.hide = function(){
@ -134,6 +139,7 @@ var CloudCmd, Util, DOM, $;
DOM.anyLoadInParallel(lFiles, function(){
Util.timeEnd(Name + ' load');
Loading = false;
Util.exec(pCallBack);
});

View file

@ -6,6 +6,7 @@ var CloudCmd, Util, DOM, JsDiff, ace;
function EditProto(CloudCmd, Util, DOM){
var Name = 'Edit',
Loading = false,
DIR = CloudCmd.LIBDIRCLIENT + 'edit/',
Value,
Edit = this,
@ -18,6 +19,7 @@ var CloudCmd, Util, DOM, JsDiff, ace;
this.init = function(pCallBack) {
var lFunc, lIsFunc = Util.isFunction(CloudCmd.View);
Loading = true;
if (lIsFunc)
lFunc = CloudCmd.View;
else
@ -40,43 +42,45 @@ var CloudCmd, Util, DOM, JsDiff, ace;
lExt = Util.getExtension(lName),
lUseWorker = Util.strCmp(lExt, ['.js', '.json']);
Images.showLoad();
if (!Element) {
Element = DOM.anyload({
name : 'div',
className : 'edit',
style :
'width : 100%;' +
'height : 100%;' +
'font : 16px "Droid Sans Mono";' +
'position: absolute;',
not_append : true
});
initAce();
}
Ace.session.setOption('useWorker', lUseWorker);
if ( Util.isString(pValue) ) {
Ace.setValue(pValue);
CloudCmd.View.show(Element, focus);
Key.unsetBind();
}
else {
DOM.getCurrentData({
success : function(pData){
var lValue = '';
if (pData)
lValue = pData.data;
Value = lValue;
Ace.setValue(lValue);
CloudCmd.View.show(Element, focus);
}
});
if (!Loading) {
Images.showLoad();
if (!Element) {
Element = DOM.anyload({
name : 'div',
className : 'edit',
style :
'width : 100%;' +
'height : 100%;' +
'font : 16px "Droid Sans Mono";' +
'position: absolute;',
not_append : true
});
initAce();
}
Ace.session.setOption('useWorker', lUseWorker);
if ( Util.isString(pValue) ) {
Ace.setValue(pValue);
CloudCmd.View.show(Element, focus);
Key.unsetBind();
}
else {
DOM.getCurrentData({
success : function(pData){
var lValue = '';
if (pData)
lValue = pData.data;
Value = lValue;
Ace.setValue(lValue);
CloudCmd.View.show(Element, focus);
}
});
}
}
};
@ -132,7 +136,7 @@ var CloudCmd, Util, DOM, JsDiff, ace;
DOM.anyLoadOnLoad(lFiles, function(){
Util.timeEnd(Name + ' load');
Loading = false;
Util.exec(pCallBack);
});
}

View file

@ -10,6 +10,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
function MenuProto(CloudCmd, Util, DOM, CloudFunc) {
var Name = 'Menu',
Loading = false,
Key = CloudCmd.Key,
Events = DOM.Events,
MenuSeted = false,
@ -20,6 +21,8 @@ var CloudCmd, Util, DOM, CloudFunc, $;
this.ENABLED = false;
this.init = function(pPosition){
Loading = true;
Position = pPosition;
Util.loadOnLoad([
@ -41,13 +44,15 @@ var CloudCmd, Util, DOM, CloudFunc, $;
};
this.show = function() {
set();
DOM.Images.hideLoad();
if(Position && !Position.x )
Position = undefined;
$('li').contextMenu(Position);
if (!Loading) {
set();
DOM.Images.hideLoad();
if(Position && !Position.x )
Position = undefined;
$('li').contextMenu(Position);
}
};
/* function read data from modules.json
@ -239,6 +244,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
DOM.anyLoadInParallel(lFiles, function(){
Util.timeEnd(Name + ' load');
Loading = false;
Util.exec(pCallBack);
});
}

View file

@ -7,6 +7,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
function ViewProto(CloudCmd, Util, DOM, CloudFunc){
var Name = 'View',
Loading = false,
Key = CloudCmd.Key,
Images = DOM.Images,
View = this,
@ -44,6 +45,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
this.init = function(pCallBack){
var lFunc, lIsFunc, lIsCallBack;
Loading = true;
if (pCallBack){
lIsFunc = Util.isFunction(pCallBack);
lIsCallBack = Util.isFunction(pCallBack.callback);
@ -73,29 +75,31 @@ var CloudCmd, Util, DOM, CloudFunc, $;
var lPath, lElement,
lAfterFunc, lFunc;
Element = $('<div id=view tabindex=0>');
if (pData) {
lElement = $(Element).append(pData);
lAfterFunc = Config.afterShow,
lFunc = function(){
Util.exec(lAfterFunc);
Util.exec(pCallBack);
};
Config.afterShow = lFunc;
$.fancybox(lElement, Config);
} else {
lPath = CloudFunc.FS + DOM.getCurrentPath();
if( Util.checkExtension(lPath, ['png','jpg', 'gif','ico']) ) {
$.fancybox.open({ href : lPath }, Config);
if (!Loading) {
Element = $('<div id=view tabindex=0>');
if (pData) {
lElement = $(Element).append(pData);
lAfterFunc = Config.afterShow,
lFunc = function(){
Util.exec(lAfterFunc);
Util.exec(pCallBack);
};
Config.afterShow = lFunc;
$.fancybox(lElement, Config);
} else {
lPath = CloudFunc.FS + DOM.getCurrentPath();
if( Util.checkExtension(lPath, ['png','jpg', 'gif','ico']) ) {
$.fancybox.open({ href : lPath }, Config);
}
else
DOM.getCurrentData(function(pParams){
var data = document.createTextNode(pParams.data);
$.fancybox( Element.append(data), Config );
});
}
else
DOM.getCurrentData(function(pParams){
var data = document.createTextNode(pParams.data);
$.fancybox( Element.append(data), Config );
});
}
};
@ -116,6 +120,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
DOM.anyLoadOnLoad([lFiles], function(){
Util.timeEnd(Name + ' load');
Loading = false;
Util.exec( pCallBack );
Images.hideLoad();
})