jquery插件ajaxupload实现文件上传操作

2020-05-29 07:11:33易采站长站整理

var zoom = 1;
if (body.getBoundingClientRect) {
var bound = body.getBoundingClientRect();
zoom = (bound.right - bound.left) / body.clientWidth;
}

if (zoom > 1) {
clientTop = 0;
clientLeft = 0;
}

var top = box.top / zoom + (window.pageYOffset || docElem && docElem.scrollTop / zoom || body.scrollTop / zoom) - clientTop,
left = box.left / zoom + (window.pageXOffset || docElem && docElem.scrollLeft / zoom || body.scrollLeft / zoom) - clientLeft;

return {
top: top,
left: left
};
};
} else {
// Get offset adding all offsets
var getOffset = function (el) {
var top = 0,
left = 0;
do {
top += el.offsetTop || 0;
left += el.offsetLeft || 0;
el = el.offsetParent;
} while (el);

return {
left: left,
top: top
};
};
}

/**
* Returns left, top, right and bottom properties describing the border-box,
* in pixels, with the top-left relative to the body
* @param {Element} el
* @return {Object} Contains left, top, right,bottom
*/

function getBox(el) {
var left, right, top, bottom;
var offset = getOffset(el);
left = offset.left;
top = offset.top;

right = left + el.offsetWidth;
bottom = top + el.offsetHeight;

return {
left: left,
right: right,
top: top,
bottom: bottom
};
}

/**
* Helper that takes object literal
* and add all properties to element.style
* @param {Element} el
* @param {Object} styles
*/

function addStyles(el, styles) {
for (var name in styles) {
if (styles.hasOwnProperty(name)) {
el.style[name] = styles[name];
}
}
}

/**
* Function places an absolutely positioned
* element on top of the specified element
* copying position and dimentions.
* @param {Element} from
* @param {Element} to
*/

function copyLayout(from, to) {
var box = getBox(from);

addStyles(to, {
position: 'absolute',
left: box.left + 'px',
top: box.top + 'px',
width: from.offsetWidth + 'px',
height: from.offsetHeight + 'px'
});
}

/**
* Creates and returns element from html chunk
* Uses innerHTML to create an element
*/
var toElement = (function () {
var div = document.createElement('div');
return function (html) {
div.innerHTML = html;
var el = div.firstChild;
return div.removeChild(el);
};
})();

/**
* Function generates unique id
* @return unique id
*/
var getUID = (function () {
var id = 0;
return function () {
return 'ValumsAjaxUpload' + id++;
};
})();

/**