cloudcmd/lib/client/view.js
2013-06-12 10:46:25 -04:00

162 lines
5.4 KiB
JavaScript

var CloudCmd, Util, DOM, CloudFunc, $;
(function(CloudCmd, Util, DOM, CloudFunc){
'use strict';
CloudCmd.View = new ViewProto(CloudCmd, Util, DOM, CloudFunc);
function ViewProto(CloudCmd, Util, DOM, CloudFunc){
var Key = CloudCmd.Key,
Images = DOM.Images,
View = this,
Config = {
beforeShow : Key.unsetBind,
afterShow : function(){
var lEditor = DOM.getById('View');
if(lEditor)
lEditor.focus();
},
beforeClose : Key.setBind,
openEffect : 'none',
closeEffect : 'none',
autoSize : false,
height : window.innerHeight,
helpers : {
overlay : {
css : {
'background' : 'rgba(255, 255, 255, 0.1)'
}
}
},
padding : 0
};
this.init = function(pCallBack){
debugger;
Util.loadOnLoad([
pCallBack || View.show,
load,
DOM.jqueryLoad
]);
DOM.Events.addKey(listener);
DOM.setButtonKey('f3', view);
delete View.init;
};
this.showHelp = function(){
Images.showLoad();
DOM.ajax({
url: '/README.md',
success: function (pData){
var lData = {text: pData};
DOM.ajax({
method : 'post',
url : 'https://api.github.com/markdown',
data : Util.stringifyJSON(lData),
success:function(pResult){
Images.hideLoad();
$.fancybox(pResult, Config);
},
error: Images.showError
});
},
error:Images.showError
});
};
/**
* function shows FancyBox
*/
this.show = function(pData){
var lPath;
if(pData)
$.fancybox('<div id=view tabindex=0>' + pData + '</div>', Config);
else {
lPath = CloudFunc.FS + DOM.getCurrentPath();
if( Util.checkExtension(lPath, ['png','jpg', 'gif','ico']) ) {
Images.hideLoad();
$.fancybox.open({ href : lPath }, Config);
}
else
DOM.getCurrentData(function(pParams){
Images.hideLoad();
$.fancybox('<div id=view tabindex=0>' +
pParams.data + '</div>', Config);
});
}
};
this.hide = function(){
$.fancybox.close();
};
/**
* function loads css and js of FancyBox
* @pParent - this
* @pCallBack - executes, when everything loaded
*/
function load(pCallBack){
Util.time('fancybox load');
var lDir = CloudCmd.LIBDIRCLIENT + 'view/fancyBox/source/',
lFiles = [ lDir + 'jquery.fancybox.css',
lDir + 'jquery.fancybox.js' ];
DOM.anyLoadOnLoad([lFiles], function(){
Util.timeEnd('fancybox load');
Util.exec( pCallBack );
Images.hideLoad();
})
.cssSet({id:'view-css',
inner : '#view{' +
'font-size: 16px;' +
'white-space :pre' +
'}' +
'#view::selection{' +
/*
'background: #fe57a1;'
'color: #fff;'
*/
'background: #b3d4fc;' +
'text-shadow: none;' +
'}'
});
}
function view(){
Images.showLoad();
View.show();
}
function listener(pEvent){
var lF3 = Key.F3,
lF1 = Key.F1,
lIsBind = Key.isBind(),
lKey = pEvent.keyCode;
/* если клавиши можно обрабатывать */
if (lIsBind) {
switch(lKey){
case lF3:
view();
DOM.preventDefault(pEvent);
break;
case lF1:
View.showHelp();
break;
}
}
}
}
})(CloudCmd, Util, DOM, CloudFunc);