chore(polyfill) add " "

This commit is contained in:
coderaiser 2014-01-21 03:03:21 -05:00
parent b3c8cc8b33
commit 48970afb2c

View file

@ -1,20 +1,20 @@
var Util, DOM, jQuery;
(function(Util, DOM, $){
(function(Util, DOM, $) {
'use strict';
if(!window.XMLHttpRequest || !document.head)
if (!window.XMLHttpRequest || !document.head)
DOM.ajax = $.ajax;
/* setting head ie6 - ie8 */
if(!document.head){
if (!document.head) {
document.head = $('head')[0];
/*
{name: '', src: ' ',func: '', style: '', id: '', parent: '',
async: false, inner: 'id{color:red, }, class:'', not_append: false}
*/
DOM.cssSet = function(pParams_o){
DOM.cssSet = function(pParams_o) {
var lElement = '<style ';
if (pParams_o.id) lElement += 'id=' + pParams_o.id + ' ';
@ -51,10 +51,10 @@ var Util, DOM, jQuery;
* @param pType
* @param pListener
*/
DOM.addListener = function(pType, pListener, pCapture, pElement){
DOM.addListener = function(pType, pListener, pCapture, pElement) {
var lRet;
if(!pElement)
if (!pElement)
pElement = window;
lRet = $(pElement).bind(pType, null, pListener);
@ -62,11 +62,11 @@ var Util, DOM, jQuery;
return lRet;
};
if(!document.removeEventListener){
DOM.removeListener = function(pType, pListener, pCapture, pElement){
if (!document.removeEventListener) {
DOM.removeListener = function(pType, pListener, pCapture, pElement) {
var lRet;
if(!pElement)
if (!pElement)
pElement = window;
$(pElement).unbind(pType, pListener);
@ -89,102 +89,102 @@ var Util, DOM, jQuery;
};
}
DOM.scrollByPages = Util.retFalse;
/* function polyfill webkit standart function */
DOM.scrollIntoViewIfNeeded = function(pElement, centerIfNeeded){
if(!window.getComputedStyle)
return;
/*
https://gist.github.com/2581101
*/
centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;
var parent = pElement.parentNode,
parentComputedStyle = window.getComputedStyle(parent, null),
parentBorderTopWidth =
parseInt(parentComputedStyle.getPropertyValue('border-top-width'), 10),
parentBorderLeftWidth =
parseInt(parentComputedStyle.getPropertyValue('border-left-width'), 10),
overTop = pElement.offsetTop - parent.offsetTop < parent.scrollTop,
overBottom =
(pElement.offsetTop -
parent.offsetTop +
pElement.clientHeight -
parentBorderTopWidth) >
(parent.scrollTop + parent.clientHeight),
overLeft = pElement.offsetLeft -
parent.offsetLeft < parent.scrollLeft,
overRight =
(pElement.offsetLeft -
parent.offsetLeft +
pElement.clientWidth -
parentBorderLeftWidth) >
(parent.scrollLeft + parent.clientWidth),
alignWithTop = overTop && !overBottom;
if ((overTop || overBottom) && centerIfNeeded)
parent.scrollTop =
pElement.offsetTop -
parent.offsetTop -
parent.clientHeight / 2 -
parentBorderTopWidth +
pElement.clientHeight / 2;
if ((overLeft || overRight) && centerIfNeeded)
parent.scrollLeft =
pElement.offsetLeft -
parent.offsetLeft -
parent.clientWidth / 2 -
parentBorderLeftWidth +
pElement.clientWidth / 2;
if ( (overTop || overBottom || overLeft || overRight) &&
!centerIfNeeded)
pElement.scrollIntoView(alignWithTop);
};
if(!document.body.classList){
DOM.scrollByPages = Util.retFalse;
/* function polyfill webkit standart function */
DOM.scrollIntoViewIfNeeded = function(pElement, centerIfNeeded) {
if (!window.getComputedStyle)
return;
/*
https://gist.github.com/2581101
*/
centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;
DOM.isContainClass = function(pElement, pClass){
var parent = pElement.parentNode,
parentComputedStyle = window.getComputedStyle(parent, null),
parentBorderTopWidth =
parseInt(parentComputedStyle.getPropertyValue('border-top-width'), 10),
parentBorderLeftWidth =
parseInt(parentComputedStyle.getPropertyValue('border-left-width'), 10),
overTop = pElement.offsetTop - parent.offsetTop < parent.scrollTop,
overBottom =
(pElement.offsetTop -
parent.offsetTop +
pElement.clientHeight -
parentBorderTopWidth) >
(parent.scrollTop + parent.clientHeight),
overLeft = pElement.offsetLeft -
parent.offsetLeft < parent.scrollLeft,
overRight =
(pElement.offsetLeft -
parent.offsetLeft +
pElement.clientWidth -
parentBorderLeftWidth) >
(parent.scrollLeft + parent.clientWidth),
alignWithTop = overTop && !overBottom;
if ((overTop || overBottom) && centerIfNeeded)
parent.scrollTop =
pElement.offsetTop -
parent.offsetTop -
parent.clientHeight / 2 -
parentBorderTopWidth +
pElement.clientHeight / 2;
if ((overLeft || overRight) && centerIfNeeded)
parent.scrollLeft =
pElement.offsetLeft -
parent.offsetLeft -
parent.clientWidth / 2 -
parentBorderLeftWidth +
pElement.clientWidth / 2;
if ( (overTop || overBottom || overLeft || overRight) &&
!centerIfNeeded)
pElement.scrollIntoView(alignWithTop);
};
if (!document.body.classList) {
DOM.isContainClass = function(pElement, pClass) {
var lRet,
lClassName = pElement && pElement.className;
if(lClassName)
if (lClassName)
lRet = lClassName.indexOf(pClass) > 0;
return lRet;
};
DOM.addClass = function(pElement, pClass){
DOM.addClass = function(pElement, pClass) {
var lRet,
lClassName = pElement && pElement.className,
lSpaceChar = lClassName ? ' ' : '';
lRet = !DOM.isContainClass(pElement, pClass);
if( lRet )
if ( lRet )
pElement.className += lSpaceChar + pClass;
return lRet;
};
DOM.removeClass = function(pElement, pClass){
DOM.removeClass = function(pElement, pClass) {
var lClassName = pElement.className;
if(lClassName.length > pClass.length)
if (lClassName.length > pClass.length)
pElement.className = lClassName.replace(pClass, '');
};
}
if(!window.JSON){
if (!window.JSON) {
Util.parseJSON = $.parseJSON;
/* https://gist.github.com/754454 */
Util.stringifyJSON = function(pObj){
Util.stringifyJSON = function(pObj) {
var lRet;
if (!Util.isObject(pObj) || pObj === null) {
@ -214,26 +214,26 @@ var Util, DOM, jQuery;
};
}
if(!window.localStorage){
var Storage = function(){
if (!window.localStorage) {
var Storage = function() {
/* приватный переключатель возможности работы с кэшем */
var StorageAllowed,
Data = {};
/* функция проверяет возможно ли работать с кэшем каким-либо образом */
this.isAllowed = function(){
this.isAllowed = function() {
return StorageAllowed;
};
this.setAllowed = function(pAllowed){
this.setAllowed = function(pAllowed) {
StorageAllowed = pAllowed;
return pAllowed;
};
/** remove element */
this.remove = function(pItem){
this.remove = function(pItem) {
var lRet = this;
if(StorageAllowed)
if (StorageAllowed)
delete Data[pItem];
return lRet;
@ -243,40 +243,40 @@ var Util, DOM, jQuery;
* в нём есть нужная нам директория -
* записываем данные в него
*/
this.set = function(pName, pData){
this.set = function(pName, pData) {
var lRet = this;
if(StorageAllowed && pName && pData)
if (StorageAllowed && pName && pData)
Data[pName] = pData;
return lRet;
},
/** Если доступен Storage принимаем из него данные*/
this.get = function(pName){
this.get = function(pName) {
var lRet = false;
if(StorageAllowed)
if (StorageAllowed)
lRet = Data[pName];
return lRet;
},
/* get all Storage from local storage */
this.getAll = function(){
this.getAll = function() {
var lRet = null;
if(StorageAllowed)
if (StorageAllowed)
lRet = Data;
return lRet;
};
/** функция чистит весь кэш для всех каталогов*/
this.clear = function(){
this.clear = function() {
var lRet = this;
if(StorageAllowed)
if (StorageAllowed)
Data = {};
return lRet;