mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
185 lines
5.9 KiB
JavaScript
185 lines
5.9 KiB
JavaScript
var CloudCmd, Util, DOM, CloudFunc, $;
|
|
|
|
(function(CloudCmd, Util, DOM, CloudFunc) {
|
|
'use strict';
|
|
|
|
CloudCmd.View = ViewProto;
|
|
|
|
function ViewProto(CallBack) {
|
|
var Name = 'View',
|
|
Loading = false,
|
|
Events = DOM.Events,
|
|
Info = DOM.CurrentInfo,
|
|
Key = CloudCmd.Key,
|
|
Images = DOM.Images,
|
|
View = function() {
|
|
Util.exec(arguments);
|
|
},
|
|
Element,
|
|
|
|
Config = {
|
|
beforeShow : function() {
|
|
Images.hideLoad();
|
|
Key.unsetBind();
|
|
},
|
|
afterShow : afterShow,
|
|
|
|
beforeClose : Key.setBind,
|
|
|
|
openEffect : 'none',
|
|
closeEffect : 'none',
|
|
autoSize : false,
|
|
height : '100%',
|
|
width : '100%',
|
|
minWidth : 0,
|
|
minHeight : 0,
|
|
|
|
helpers : {
|
|
overlay : {
|
|
css : {
|
|
'background' : 'rgba(255, 255, 255, 0.1)'
|
|
}
|
|
}
|
|
},
|
|
padding : 0
|
|
};
|
|
|
|
View.show = show;
|
|
View.hide = hide;
|
|
|
|
function init() {
|
|
var lFunc, lIsFunc, lIsCallBack;
|
|
|
|
Loading = true;
|
|
|
|
if (CallBack) {
|
|
lIsFunc = Util.isFunction(CallBack);
|
|
lIsCallBack = Util.isFunction(CallBack.callback);
|
|
}
|
|
|
|
if (lIsFunc)
|
|
lFunc = CallBack;
|
|
else if (lIsCallBack)
|
|
lFunc = CallBack.callback;
|
|
else
|
|
lFunc = Util.retExec(View.show, null);
|
|
|
|
Util.loadOnLoad([
|
|
lFunc,
|
|
load,
|
|
DOM.jqueryLoad
|
|
]);
|
|
|
|
Events.addKey(listener);
|
|
}
|
|
|
|
function afterShow() {
|
|
Element.focus();
|
|
}
|
|
|
|
/**
|
|
* function shows FancyBox
|
|
*/
|
|
function show(pData, pCallBack, pConfig) {
|
|
var lPath, lElement, lAfterFunc, lFunc, name, isImage,
|
|
config = {};
|
|
|
|
if (!Loading) {
|
|
Element = $('<div id=view tabindex=0>');
|
|
if (pData) {
|
|
lElement = $(Element).append(pData);
|
|
lFunc = function() {
|
|
afterShow();
|
|
Util.exec(pCallBack);
|
|
};
|
|
|
|
Config.afterShow = lFunc;
|
|
|
|
Util.copyObj(Config, config);
|
|
|
|
for (name in pConfig)
|
|
config[name] = pConfig[name];
|
|
|
|
$.fancybox(lElement, config);
|
|
|
|
} else {
|
|
lPath = CloudFunc.FS + Info.path;
|
|
isImage = $.fancybox.isImage(lPath);
|
|
|
|
if (isImage) {
|
|
$.fancybox.open({ href : lPath }, Config);
|
|
} else
|
|
Info.getData(function(pParams) {
|
|
var data = document.createTextNode(pParams.data);
|
|
/* add margin only for view text documents */
|
|
Element.css('margin', '2%');
|
|
|
|
$.fancybox(Element.append(data), Config);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
function hide() {
|
|
$.fancybox.close();
|
|
}
|
|
|
|
/**
|
|
* function loads css and js of FancyBox
|
|
* @pCallBack - executes, when everything loaded
|
|
*/
|
|
function load(pCallBack) {
|
|
Util.time(Name + ' load');
|
|
var lDir = CloudCmd.LIBDIRCLIENT + 'view/fancyBox/source/',
|
|
lFiles = [ lDir + 'jquery.fancybox.css',
|
|
lDir + 'jquery.fancybox.js' ];
|
|
|
|
DOM.anyLoadOnLoad([lFiles], function() {
|
|
Util.timeEnd(Name + ' load');
|
|
Loading = false;
|
|
Util.exec( pCallBack );
|
|
Images.hideLoad();
|
|
})
|
|
.cssSet({id:'view-css',
|
|
inner : '#view {' +
|
|
'font-size: 16px;' +
|
|
'white-space :pre;' +
|
|
'outline: 0;' +
|
|
'}' +
|
|
'#view::selection {' +
|
|
/*
|
|
'background: #fe57a1;'
|
|
'color: #fff;'
|
|
*/
|
|
'background: #b3d4fc;' +
|
|
'text-shadow: none;' +
|
|
'}' +
|
|
'#fancybox-loading div {' +
|
|
'background: none;' +
|
|
'width: 0;' +
|
|
'height: 0' +
|
|
'}'
|
|
});
|
|
|
|
}
|
|
|
|
function view() {
|
|
Images.showLoad();
|
|
View.show();
|
|
}
|
|
|
|
function listener(event) {
|
|
var keyCode = event.keyCode,
|
|
ESC = Key.ESC;
|
|
|
|
if (keyCode === ESC)
|
|
hide();
|
|
}
|
|
|
|
|
|
init();
|
|
|
|
return View;
|
|
}
|
|
|
|
})(CloudCmd, Util, DOM, CloudFunc);
|