cloudcmd/lib/client/view.js
2013-12-16 13:56:40 +00:00

176 lines
6 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,
Info = DOM.CurrentInfo,
Key = CloudCmd.Key,
Images = DOM.Images,
View = this,
Element,
Config = {
beforeShow : function() {
Images.hideLoad();
Key.unsetBind();
},
afterShow : function() {
Element.focus();
},
beforeClose : Key.setBind,
openEffect : 'none',
closeEffect : 'none',
autoSize : false,
height : window.innerHeight,
width : window.innerWidth/0.75,
minWidth : 0,
minHeight : 0,
helpers : {
overlay : {
css : {
'background' : 'rgba(255, 255, 255, 0.1)'
}
}
},
padding : 0
};
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;
Util.loadOnLoad([
lFunc || Util.retExec(View.show, null),
load,
DOM.jqueryLoad
]);
DOM.Events.addKey(listener);
DOM.setButtonKey('f3', view);
}
/**
* function shows FancyBox
*/
this.show = function(pData, pCallBack, pConfig) {
var lPath, lElement, lAfterFunc, lFunc, name,
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;
Util.copyObj(Config, config);
for (name in pConfig)
config[name] = pConfig[name];
$.fancybox(lElement, config);
} else {
lPath = CloudFunc.FS + Info.path;
if (Util.checkExtension(lPath, ['png','jpg', 'gif','ico'])) {
$.fancybox.open({ href : lPath }, Config);
} else
Info.getData(function(pParams) {
var data = document.createTextNode(pParams.data);
$.fancybox(Element.append(data), 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(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(pEvent) {
var lF3 = Key.F3,
lIsBind = Key.isBind(),
lKey = pEvent.keyCode;
/* если клавиши можно обрабатывать */
if (lIsBind && lKey === lF3) {
view();
DOM.preventDefault(pEvent);
}
}
init();
}
})(CloudCmd, Util, DOM, CloudFunc);