* Get file name from path
* @param {String} file path to file
* @return filename
*/
function fileFromPath(file) {
return file.replace(/.*(/|)/, "");
}
/**
* Get file extension lowercase
* @param {String} file name
* @return file extenstion
*/
function getExt(file) {
return (-1 !== file.indexOf('.')) ? file.replace(/.*[.]/, '') : '';
}
function hasClass(el, name) {
var re = new RegExp('b' + name + 'b');
return re.test(el.className);
}
function addClass(el, name) {
if (!hasClass(el, name)) {
el.className += ' ' + name;
}
}
function removeClass(el, name) {
var re = new RegExp('b' + name + 'b');
el.className = el.className.replace(re, '');
}
function removeNode(el) {
el.parentNode.removeChild(el);
}
/**
* Easy styling and uploading
* @constructor
* @param button An element you want convert to
* upload button. Tested dimentions up to 500x500px
* @param {Object} options See defaults below.
*/
window.AjaxUpload = function (button, options) {
this._settings = {
// Location of the server-side upload script
action: 'upload.php',
// File upload name
name: 'userfile',
// Additional data to send
data: {},
// Submit file as soon as it's selected
autoSubmit: true,
// The type of data that you're expecting back from the server.
// html and xml are detected automatically.
// Only useful when you are using json data as a response.
// Set to "json" in that case.
responseType: false,
// Class applied to button when mouse is hovered
hoverClass: 'hover',
// Class applied to button when AU is disabled
disabledClass: 'disabled',
// When user selects a file, useful with autoSubmit disabled
// You can return false to cancel upload
onChange: function (file, extension) {},
// Callback to fire before file is uploaded
// You can return false to cancel upload
onSubmit: function (file, extension) {},
// Fired when file upload is completed
// WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
onComplete: function (file, response) {}
};
// Merge the users options with our defaults
for (var i in options) {
if (options.hasOwnProperty(i)) {
this._settings[i] = options[i];
}
}
// button isn't necessary a dom element
if (button.jquery) {
// jQuery object was passed
button = button[0];
} else if (typeof button == "string") {
if (/^#.*/.test(button)) {
// If jQuery user passes #elementId don't break it
button = button.slice(1);
}
button = document.getElementById(button);
}
if (!button || button.nodeType !== 1) {










