big update

This commit is contained in:
2018-09-07 10:54:01 +02:00
parent 8fb74fdf95
commit fdd2f67cc6
243 changed files with 18538 additions and 2087 deletions

View File

@@ -0,0 +1,857 @@
(function($) {
//Global container.
window.imce = {tree: {}, findex: [], fids: {}, selected: {}, selcount: 0, ops: {}, cache: {}, urlId: {},
vars: {previewImages: 1, cache: 1},
hooks: {load: [], list: [], navigate: [], cache: []},
//initiate imce.
initiate: function() {
imce.conf = Drupal.settings.imce || {};
if (imce.conf.error != false) return;
imce.ie = (navigator.userAgent.match(/msie (\d+)/i) || ['', 0])[1] * 1;
imce.FLW = imce.el('file-list-wrapper'), imce.SBW = imce.el('sub-browse-wrapper');
imce.NW = imce.el('navigation-wrapper'), imce.BW = imce.el('browse-wrapper');
imce.PW = imce.el('preview-wrapper'), imce.FW = imce.el('forms-wrapper');
imce.updateUI();
imce.prepareMsgs();//process initial status messages
imce.initiateTree();//build directory tree
imce.hooks.list.unshift(imce.processRow);//set the default list-hook.
imce.initiateList();//process file list
imce.initiateOps();//prepare operation tabs
imce.refreshOps();
// Bind global error handler
$(document).ajaxError(imce.ajaxError);
imce.invoke('load', window);//run functions set by external applications.
},
//process navigation tree
initiateTree: function() {
$('#navigation-tree li').each(function(i) {
var a = this.firstChild, txt = a.firstChild;
txt && (txt.data = imce.decode(txt.data));
var branch = imce.tree[a.title] = {'a': a, li: this, ul: this.lastChild.tagName == 'UL' ? this.lastChild : null};
if (a.href) imce.dirClickable(branch);
imce.dirCollapsible(branch);
});
},
//Add a dir to the tree under parent
dirAdd: function(dir, parent, clickable) {
if (imce.tree[dir]) return clickable ? imce.dirClickable(imce.tree[dir]) : imce.tree[dir];
var parent = parent || imce.tree['.'];
parent.ul = parent.ul ? parent.ul : parent.li.appendChild(imce.newEl('ul'));
var branch = imce.dirCreate(dir, imce.decode(dir.substr(dir.lastIndexOf('/')+1)), clickable);
parent.ul.appendChild(branch.li);
return branch;
},
//create list item for navigation tree
dirCreate: function(dir, text, clickable) {
if (imce.tree[dir]) return imce.tree[dir];
var branch = imce.tree[dir] = {li: imce.newEl('li'), a: imce.newEl('a')};
$(branch.a).addClass('folder').text(text).attr('title', dir).appendTo(branch.li);
imce.dirCollapsible(branch);
return clickable ? imce.dirClickable(branch) : branch;
},
//change currently active directory
dirActivate: function(dir) {
if (dir != imce.conf.dir) {
if (imce.tree[imce.conf.dir]){
$(imce.tree[imce.conf.dir].a).removeClass('active');
}
$(imce.tree[dir].a).addClass('active');
imce.conf.dir = dir;
}
return imce.tree[imce.conf.dir];
},
//make a dir accessible
dirClickable: function(branch) {
if (branch.clkbl) return branch;
$(branch.a).attr('href', '#').removeClass('disabled').click(function() {imce.navigate(this.title); return false;});
branch.clkbl = true;
return branch;
},
//sub-directories expand-collapse ability
dirCollapsible: function (branch) {
if (branch.clpsbl) return branch;
$(imce.newEl('span')).addClass('expander').html(' ').click(function() {
if (branch.ul) {
$(branch.ul).toggle();
$(branch.li).toggleClass('expanded');
imce.ie && $('#navigation-header').css('top', imce.NW.scrollTop);
}
else if (branch.clkbl){
$(branch.a).click();
}
}).prependTo(branch.li);
branch.clpsbl = true;
return branch;
},
//update navigation tree after getting subdirectories.
dirSubdirs: function(dir, subdirs) {
var branch = imce.tree[dir];
if (subdirs && subdirs.length) {
var prefix = dir == '.' ? '' : dir +'/';
for (var i in subdirs) {//add subdirectories
imce.dirAdd(prefix + subdirs[i], branch, true);
}
$(branch.li).removeClass('leaf').addClass('expanded');
$(branch.ul).show();
}
else if (!branch.ul){//no subdirs->leaf
$(branch.li).removeClass('expanded').addClass('leaf');
}
},
//process file list
initiateList: function(cached) {
var L = imce.hooks.list, dir = imce.conf.dir, token = {'%dir': dir == '.' ? $(imce.tree['.'].a).text() : imce.decode(dir)}
imce.findex = [], imce.fids = {}, imce.selected = {}, imce.selcount = 0, imce.vars.lastfid = null;
imce.tbody = imce.el('file-list').tBodies[0];
if (imce.tbody.rows.length) {
for (var row, i = 0; row = imce.tbody.rows[i]; i++) {
var fid = row.id;
imce.findex[i] = imce.fids[fid] = row;
if (cached) {
if (imce.hasC(row, 'selected')) {
imce.selected[imce.vars.lastfid = fid] = row;
imce.selcount++;
}
}
else {
for (var func, j = 0; func = L[j]; j++) func(row);//invoke list-hook
}
}
}
if (!imce.conf.perm.browse) {
imce.setMessage(Drupal.t('File browsing is disabled in directory %dir.', token), 'error');
}
},
//add a file to the list. (having properties name,size,formatted size,width,height,date,formatted date)
fileAdd: function(file) {
var row, fid = file.name, i = imce.findex.length, attr = ['name', 'size', 'width', 'height', 'date'];
if (!(row = imce.fids[fid])) {
row = imce.findex[i] = imce.fids[fid] = imce.tbody.insertRow(i);
for (var i in attr) row.insertCell(i).className = attr[i];
}
row.cells[0].innerHTML = row.id = fid;
row.cells[1].innerHTML = file.fsize; row.cells[1].id = file.size;
row.cells[2].innerHTML = file.width;
row.cells[3].innerHTML = file.height;
row.cells[4].innerHTML = file.fdate; row.cells[4].id = file.date;
imce.invoke('list', row);
if (imce.vars.prvfid == fid) imce.setPreview(fid);
if (file.id) imce.urlId[imce.getURL(fid)] = file.id;
},
//remove a file from the list
fileRemove: function(fid) {
if (!(row = imce.fids[fid])) return;
imce.fileDeSelect(fid);
imce.findex.splice(row.rowIndex, 1);
$(row).remove();
delete imce.fids[fid];
if (imce.vars.prvfid == fid) imce.setPreview();
},
//return a file object containing all properties.
fileGet: function (fid) {
var file = imce.fileProps(fid);
if (file) {
file.name = imce.decode(fid);
file.url = imce.getURL(fid);
file.relpath = imce.getRelpath(fid);
file.id = imce.urlId[file.url] || 0; //file id for newly uploaded files
}
return file;
},
//return file properties embedded in html.
fileProps: function (fid) {
var row = imce.fids[fid];
return row ? {
size: row.cells[1].innerHTML,
bytes: row.cells[1].id * 1,
width: row.cells[2].innerHTML * 1,
height: row.cells[3].innerHTML * 1,
date: row.cells[4].innerHTML,
time: row.cells[4].id * 1
} : null;
},
//simulate row click. selection-highlighting
fileClick: function(row, ctrl, shft) {
if (!row) return;
var fid = typeof(row) == 'string' ? row : row.id;
if (ctrl || fid == imce.vars.prvfid) {
imce.fileToggleSelect(fid);
}
else if (shft) {
var last = imce.lastFid();
var start = last ? imce.fids[last].rowIndex : -1;
var end = imce.fids[fid].rowIndex;
var step = start > end ? -1 : 1;
while (start != end) {
start += step;
imce.fileSelect(imce.findex[start].id);
}
}
else {
for (var fname in imce.selected) {
imce.fileDeSelect(fname);
}
imce.fileSelect(fid);
}
//set preview
imce.setPreview(imce.selcount == 1 ? imce.lastFid() : null);
},
//file select/deselect functions
fileSelect: function (fid) {
if (imce.selected[fid] || !imce.fids[fid]) return;
imce.selected[fid] = imce.fids[imce.vars.lastfid=fid];
$(imce.selected[fid]).addClass('selected');
imce.selcount++;
},
fileDeSelect: function (fid) {
if (!imce.selected[fid] || !imce.fids[fid]) return;
if (imce.vars.lastfid == fid) imce.vars.lastfid = null;
$(imce.selected[fid]).removeClass('selected');
delete imce.selected[fid];
imce.selcount--;
},
fileToggleSelect: function (fid) {
imce['file'+ (imce.selected[fid] ? 'De' : '') +'Select'](fid);
},
//process file operation form and create operation tabs.
initiateOps: function() {
imce.setHtmlOps();
imce.setUploadOp();//upload
imce.setFileOps();//thumb, delete, resize
},
//process existing html ops.
setHtmlOps: function () {
$(imce.el('ops-list')).children('li').each(function() {
if (!this.firstChild) return $(this).remove();
var name = this.id.substr(8);
var Op = imce.ops[name] = {div: imce.el('op-content-'+ name), li: imce.el('op-item-'+ name)};
Op.a = Op.li.firstChild;
Op.title = Op.a.innerHTML;
$(Op.a).click(function() {imce.opClick(name); return false;});
});
},
//convert upload form to an op.
setUploadOp: function () {
var el, form = imce.el('imce-upload-form');
if (!form) return;
$(form).ajaxForm(imce.uploadSettings()).find('fieldset').each(function() {//clean up fieldsets
this.removeChild(this.firstChild);
$(this).after(this.childNodes);
}).remove();
// Set html response flag
el = form.elements['files[imce]'];
if (el && el.files && window.FormData) {
if (el = form.elements.html_response) {
el.value = 0;
}
}
imce.opAdd({name: 'upload', title: Drupal.t('Upload'), content: form});//add op
},
//convert fileop form submit buttons to ops.
setFileOps: function () {
var form = imce.el('imce-fileop-form');
if (!form) return;
$(form.elements.filenames).parent().remove();
$(form).find('fieldset').each(function() {//remove fieldsets
var $sbmt = $('input:submit', this);
if (!$sbmt.length) return;
var Op = {name: $sbmt.attr('id').substr(5)};
var func = function() {imce.fopSubmit(Op.name); return false;};
$sbmt.click(func);
Op.title = $(this).children('legend').remove().text() || $sbmt.val();
Op.name == 'delete' ? (Op.func = func) : (Op.content = this.childNodes);
imce.opAdd(Op);
}).remove();
imce.vars.opform = $(form).serialize();//serialize remaining parts.
},
//refresh ops states. enable/disable
refreshOps: function() {
for (var p in imce.conf.perm) {
if (imce.conf.perm[p]) imce.opEnable(p);
else imce.opDisable(p);
}
},
//add a new file operation
opAdd: function (op) {
var oplist = imce.el('ops-list'), opcons = imce.el('op-contents');
var name = op.name || ('op-'+ $(oplist).children('li').length);
var title = op.title || 'Untitled';
var Op = imce.ops[name] = {title: title};
if (op.content) {
Op.div = imce.newEl('div');
$(Op.div).attr({id: 'op-content-'+ name, 'class': 'op-content'}).appendTo(opcons).append(op.content);
}
Op.a = imce.newEl('a');
Op.li = imce.newEl('li');
$(Op.a).attr({href: '#', name: name, title: title}).html('<span>' + title +'</span>').click(imce.opClickEvent);
$(Op.li).attr('id', 'op-item-'+ name).append(Op.a).appendTo(oplist);
Op.func = op.func || imce.opVoid;
return Op;
},
//click event for file operations
opClickEvent: function(e) {
imce.opClick(this.name);
return false;
},
//void operation function
opVoid: function() {},
//perform op click
opClick: function(name) {
var Op = imce.ops[name], oldop = imce.vars.op;
if (!Op || Op.disabled) {
return imce.setMessage(Drupal.t('You can not perform this operation.'), 'error');
}
if (Op.div) {
if (oldop) {
var toggle = oldop == name;
imce.opShrink(oldop, toggle ? 'fadeOut' : 'hide');
if (toggle) return false;
}
var left = Op.li.offsetLeft;
var $opcon = $('#op-contents').css({left: 0});
$(Op.div).fadeIn('normal', function() {
setTimeout(function() {
if (imce.vars.op) {
var $inputs = $('input', imce.ops[imce.vars.op].div);
$inputs.eq(0).focus();
//form inputs become invisible in IE. Solution is as stupid as the behavior.
$('html').hasClass('ie') && $inputs.addClass('dummyie').removeClass('dummyie');
}
});
});
var diff = left + $opcon.width() - $('#imce-content').width();
$opcon.css({left: diff > 0 ? left - diff - 1 : left});
$(Op.li).addClass('active');
$(imce.opCloseLink).fadeIn(300);
imce.vars.op = name;
}
Op.func(true);
return true;
},
//enable a file operation
opEnable: function(name) {
var Op = imce.ops[name];
if (Op && Op.disabled) {
Op.disabled = false;
$(Op.li).show();
}
},
//disable a file operation
opDisable: function(name) {
var Op = imce.ops[name];
if (Op && !Op.disabled) {
Op.div && imce.opShrink(name);
$(Op.li).hide();
Op.disabled = true;
}
},
//hide contents of a file operation
opShrink: function(name, effect) {
if (imce.vars.op != name) return;
var Op = imce.ops[name];
$(Op.div).stop(true, true)[effect || 'hide']();
$(Op.li).removeClass('active');
$(imce.opCloseLink).hide();
Op.func(false);
imce.vars.op = null;
},
//navigate to dir
navigate: function(dir) {
if (imce.vars.navbusy || (dir == imce.conf.dir && !confirm(Drupal.t('Do you want to refresh the current directory?')))) return;
var cache = imce.vars.cache && dir != imce.conf.dir;
var set = imce.navSet(dir, cache);
if (cache && imce.cache[dir]) {//load from the cache
set.success({data: imce.cache[dir]});
set.complete();
}
else $.ajax(set);//live load
},
//ajax navigation settings
navSet: function (dir, cache) {
$(imce.tree[dir].li).addClass('loading');
imce.vars.navbusy = dir;
return {url: imce.ajaxURL('navigate', dir),
type: 'GET',
dataType: 'json',
success: function(response) {
if (response.data && !response.data.error) {
if (cache) imce.navCache(imce.conf.dir, dir);//cache the current dir
imce.navUpdate(response.data, dir);
}
imce.processResponse(response);
},
complete: function () {
$(imce.tree[dir].li).removeClass('loading');
imce.vars.navbusy = null;
}
};
},
//update directory using the given data
navUpdate: function(data, dir) {
var cached = data == imce.cache[dir], olddir = imce.conf.dir;
if (cached) data.files.id = 'file-list';
$(imce.FLW).html(data.files);
imce.dirActivate(dir);
imce.dirSubdirs(dir, data.subdirectories);
$.extend(imce.conf.perm, data.perm);
imce.refreshOps();
imce.initiateList(cached);
imce.setPreview(imce.selcount == 1 ? imce.lastFid() : null);
imce.SBW.scrollTop = 0;
imce.invoke('navigate', data, olddir, cached);
},
//set cache
navCache: function (dir, newdir) {
var C = imce.cache[dir] = {'dir': dir, files: imce.el('file-list'), dirsize: imce.el('dir-size').innerHTML, perm: $.extend({}, imce.conf.perm)};
C.files.id = 'cached-list-'+ dir;
imce.FW.appendChild(C.files);
imce.invoke('cache', C, newdir);
},
//validate upload form
uploadValidate: function (data, form, options) {
var path = $('#edit-imce').val();
if (!path) return false;
if (imce.conf.extensions != '*') {
var ext = path.substr(path.lastIndexOf('.') + 1);
if ((' '+ imce.conf.extensions +' ').indexOf(' '+ ext.toLowerCase() +' ') == -1) {
return imce.setMessage(Drupal.t('Only files with the following extensions are allowed: %files-allowed.', {'%files-allowed': imce.conf.extensions}), 'error');
}
}
options.url = imce.ajaxURL('upload');//make url contain current dir.
imce.fopLoading('upload', true);
return true;
},
//settings for upload
uploadSettings: function () {
return {
beforeSubmit: imce.uploadValidate,
success: function (response) {
try{
imce.processResponse($.parseJSON(response));
} catch(e) {}
},
complete: function () {
imce.fopLoading('upload', false);
},
resetForm: true,
dataType: 'text'
};
},
//validate default ops(delete, thumb, resize)
fopValidate: function(fop) {
if (!imce.validateSelCount(1, imce.conf.filenum)) return false;
switch (fop) {
case 'delete':
return confirm(Drupal.t('Delete selected files?'));
case 'thumb':
if (!$('input:checked', imce.ops['thumb'].div).length) {
return imce.setMessage(Drupal.t('Please select a thumbnail.'), 'error');
}
return imce.validateImage();
case 'resize':
var w = imce.el('edit-width').value, h = imce.el('edit-height').value;
var maxDim = imce.conf.dimensions.split('x');
var maxW = maxDim[0]*1, maxH = maxW ? maxDim[1]*1 : 0;
if (!(/^[1-9][0-9]*$/).test(w) || !(/^[1-9][0-9]*$/).test(h) || (maxW && (maxW < w*1 || maxH < h*1))) {
return imce.setMessage(Drupal.t('Please specify dimensions within the allowed range that is from 1x1 to @dimensions.', {'@dimensions': maxW ? imce.conf.dimensions : Drupal.t('unlimited')}), 'error');
}
return imce.validateImage();
}
var func = fop +'OpValidate';
if (imce[func]) return imce[func](fop);
return true;
},
//submit wrapper for default ops
fopSubmit: function(fop) {
switch (fop) {
case 'thumb': case 'delete': case 'resize': return imce.commonSubmit(fop);
}
var func = fop +'OpSubmit';
if (imce[func]) return imce[func](fop);
},
//common submit function shared by default ops
commonSubmit: function(fop) {
if (!imce.fopValidate(fop)) return false;
imce.fopLoading(fop, true);
$.ajax(imce.fopSettings(fop));
},
//settings for default file operations
fopSettings: function (fop) {
return {url: imce.ajaxURL(fop), type: 'POST', dataType: 'json', success: imce.processResponse, complete: function (response) {imce.fopLoading(fop, false);}, data: imce.vars.opform +'&filenames='+ encodeURIComponent(imce.serialNames()) +'&jsop='+ fop + (imce.ops[fop].div ? '&'+ $('input, select, textarea', imce.ops[fop].div).serialize() : '')};
},
//toggle loading state
fopLoading: function(fop, state) {
var el = imce.el('edit-'+ fop), func = state ? 'addClass' : 'removeClass';
if (el) {
$(el)[func]('loading');
el.disabled = state;
}
else {
$(imce.ops[fop].li)[func]('loading');
imce.ops[fop].disabled = state;
}
},
//preview a file.
setPreview: function (fid) {
var row, html = '';
imce.vars.prvfid = fid;
if (fid && (row = imce.fids[fid])) {
var width = row.cells[2].innerHTML * 1;
html = imce.vars.previewImages && width ? imce.imgHtml(fid, width, row.cells[3].innerHTML) : imce.decodePlain(fid);
html = '<a href="#" onclick="imce.send(\''+ fid +'\'); return false;" title="'+ (imce.vars.prvtitle||'') +'">'+ html +'</a>';
}
imce.el('file-preview').innerHTML = html;
},
//default file send function. sends the file to the new window.
send: function (fid) {
fid && window.open(imce.getURL(fid));
},
//add an operation for an external application to which the files are send.
setSendTo: function (title, func) {
imce.send = function (fid) { fid && func(imce.fileGet(fid), window);};
var opFunc = function () {
if (imce.selcount != 1) return imce.setMessage(Drupal.t('Please select a file.'), 'error');
imce.send(imce.vars.prvfid);
};
imce.vars.prvtitle = title;
return imce.opAdd({name: 'sendto', title: title, func: opFunc});
},
//move initial page messages into log
prepareMsgs: function () {
var msgs;
if (msgs = imce.el('imce-messages')) {
$('>div', msgs).each(function (){
var type = this.className.split(' ')[1];
var li = $('>ul li', this);
if (li.length) li.each(function () {imce.setMessage(this.innerHTML, type);});
else imce.setMessage(this.innerHTML, type);
});
$(msgs).remove();
}
},
//insert log message
setMessage: function (msg, type) {
var $box = $(imce.msgBox);
var logs = imce.el('log-messages') || $(imce.newEl('div')).appendTo('#help-box-content').before('<h4>'+ Drupal.t('Log messages') +':</h4>').attr('id', 'log-messages')[0];
var msg = '<div class="message '+ (type || 'status') +'">'+ msg +'</div>';
$box.queue(function() {
$box.css({opacity: 0, display: 'block'}).html(msg);
$box.dequeue();
});
var q = $box.queue().length, t = imce.vars.msgT || 1000;
q = q < 2 ? 1 : q < 3 ? 0.8 : q < 4 ? 0.7 : 0.4;//adjust speed with respect to queue length
$box.fadeTo(600 * q, 1).fadeTo(t * q, 1).fadeOut(400 * q);
$(logs).append(msg);
return false;
},
//invoke hooks
invoke: function (hook) {
var i, args, func, funcs;
if ((funcs = imce.hooks[hook]) && funcs.length) {
(args = $.makeArray(arguments)).shift();
for (i = 0; func = funcs[i]; i++) func.apply(this, args);
}
},
//process response
processResponse: function (response) {
if (response.data) imce.resData(response.data);
if (response.messages) imce.resMsgs(response.messages);
},
//process response data
resData: function (data) {
var i, added, removed;
if (added = data.added) {
var cnt = imce.findex.length;
for (i in added) {//add new files or update existing
imce.fileAdd(added[i]);
}
if (added.length == 1) {//if it is a single file operation
imce.highlight(added[0].name);//highlight
}
if (imce.findex.length != cnt) {//if new files added, scroll to bottom.
$(imce.SBW).animate({scrollTop: imce.SBW.scrollHeight}).focus();
}
}
if (removed = data.removed) for (i in removed) {
imce.fileRemove(removed[i]);
}
imce.conf.dirsize = data.dirsize;
imce.updateStat();
},
//set response messages
resMsgs: function (msgs) {
for (var type in msgs) for (var i in msgs[type]) {
imce.setMessage(msgs[type][i], type);
}
},
//return img markup
imgHtml: function (fid, width, height) {
return '<img src="'+ imce.getURL(fid, true) +'" width="'+ width +'" height="'+ height +'" alt="'+ imce.decodePlain(fid) +'">';
},
//check if the file is an image
isImage: function (fid) {
return imce.fids[fid].cells[2].innerHTML * 1;
},
//find the first non-image in the selection
getNonImage: function (selected) {
for (var fid in selected) {
if (!imce.isImage(fid)) return fid;
}
return false;
},
//validate current selection for images
validateImage: function () {
var nonImg = imce.getNonImage(imce.selected);
return nonImg ? imce.setMessage(Drupal.t('%filename is not an image.', {'%filename': imce.decode(nonImg)}), 'error') : true;
},
//validate number of selected files
validateSelCount: function (Min, Max) {
if (Min && imce.selcount < Min) {
return imce.setMessage(Min == 1 ? Drupal.t('Please select a file.') : Drupal.t('You must select at least %num files.', {'%num': Min}), 'error');
}
if (Max && Max < imce.selcount) {
return imce.setMessage(Drupal.t('You are not allowed to operate on more than %num files.', {'%num': Max}), 'error');
}
return true;
},
//update file count and dir size
updateStat: function () {
imce.el('file-count').innerHTML = imce.findex.length;
imce.el('dir-size').innerHTML = imce.conf.dirsize;
},
//serialize selected files. return fids with a colon between them
serialNames: function () {
var str = '';
for (var fid in imce.selected) {
str += ':'+ fid;
}
return str.substr(1);
},
//get file url. re-encode & and # for mod rewrite
getURL: function (fid, uncached) {
var url = imce.getRelpath(fid);
if (imce.conf.modfix) {
url = url.replace(/%(23|26)/g, '%25$1');
}
url = imce.conf.furl + url;
if (uncached) {
var file = imce.fileProps(fid);
url += (url.indexOf('?') === -1 ? '?' : '&') + 's' + file.bytes + 'd' + file.time;
}
return url;
},
//get encoded file path relative to root.
getRelpath: function (fid) {
var dir = imce.conf.dir;
return (dir === '.' ? '' : dir + '/') + fid;
},
//el. by id
el: function (id) {
return document.getElementById(id);
},
//find the latest selected fid
lastFid: function () {
if (imce.vars.lastfid) return imce.vars.lastfid;
for (var fid in imce.selected);
return fid;
},
//create ajax url
ajaxURL: function (op, dir) {
return imce.conf.url + (imce.conf.clean ? '?' :'&') +'jsop='+ op +'&dir='+ (dir||imce.conf.dir);
},
//fast class check
hasC: function (el, name) {
return el.className && (' '+ el.className +' ').indexOf(' '+ name +' ') != -1;
},
//highlight a single file
highlight: function (fid) {
if (imce.vars.prvfid) imce.fileClick(imce.vars.prvfid);
imce.fileClick(fid);
},
//process a row
processRow: function (row) {
row.cells[0].innerHTML = '<span>' + imce.decodePlain(row.id) + '</span>';
row.onmousedown = function(e) {
var e = e||window.event;
imce.fileClick(this, e.ctrlKey, e.shiftKey);
return !(e.ctrlKey || e.shiftKey);
};
row.ondblclick = function(e) {
imce.send(this.id);
return false;
};
},
//decode urls. uses unescape. can be overridden to use decodeURIComponent
decode: function (str) {
try {
return decodeURIComponent(str);
} catch(e) {}
return str;
},
//decode and convert to plain text
decodePlain: function (str) {
return Drupal.checkPlain(imce.decode(str));
},
//global ajax error function
ajaxError: function (e, response, settings, thrown) {
imce.setMessage(Drupal.ajaxError(response, settings.url).replace(/\n/g, '<br />'), 'error');
},
//convert button elements to standard input buttons
convertButtons: function(form) {
$('button:submit', form).each(function(){
$(this).replaceWith('<input type="submit" value="'+ $(this).text() +'" name="'+ this.name +'" class="form-submit" id="'+ this.id +'" />');
});
},
//create element
newEl: function(name) {
return document.createElement(name);
},
//scroll syncronization for section headers
syncScroll: function(scrlEl, fixEl, bottom) {
var $fixEl = $(fixEl);
var prop = bottom ? 'bottom' : 'top';
var factor = bottom ? -1 : 1;
var syncScrl = function(el) {
$fixEl.css(prop, factor * el.scrollTop);
}
$(scrlEl).scroll(function() {
var el = this;
syncScrl(el);
setTimeout(function() {
syncScrl(el);
});
});
},
//get UI ready. provide backward compatibility.
updateUI: function() {
//file urls.
var furl = imce.conf.furl, isabs = furl.indexOf('://') > -1;
var absurls = imce.conf.absurls = imce.vars.absurls || imce.conf.absurls;
var host = location.host;
var baseurl = location.protocol + '//' + host;
if (furl.charAt(furl.length - 1) != '/') {
furl = imce.conf.furl = furl + '/';
}
imce.conf.modfix = imce.conf.clean && furl.split('/')[3] === 'system';
if (absurls && !isabs) {
imce.conf.furl = baseurl + furl;
}
else if (!absurls && isabs && furl.indexOf(baseurl) == 0) {
furl = furl.substr(baseurl.length);
// Server base url is defined with a port which is missing in current page url.
if (furl.charAt(0) === ':') {
furl = furl.replace(/^:\d*/, '');
}
imce.conf.furl = furl;
}
//convert button elements to input elements.
imce.convertButtons(imce.FW);
//ops-list
$('#ops-list').removeClass('tabs secondary').addClass('clear-block clearfix');
imce.opCloseLink = $(imce.newEl('a')).attr({id: 'op-close-link', href: '#', title: Drupal.t('Close')}).click(function() {
imce.vars.op && imce.opClick(imce.vars.op);
return false;
}).appendTo('#op-contents')[0];
//navigation-header
if (!$('#navigation-header').length) {
$(imce.NW).children('.navigation-text').attr('id', 'navigation-header').wrapInner('<span></span>');
}
//log
$('#log-prv-wrapper').before($('#log-prv-wrapper > #preview-wrapper')).remove();
$('#log-clearer').remove();
//content resizer
$('#content-resizer').remove();
//message-box
imce.msgBox = imce.el('message-box') || $(imce.newEl('div')).attr('id', 'message-box').prependTo('#imce-content')[0];
//create help tab
var $hbox = $('#help-box');
$hbox.is('a') && $hbox.replaceWith($(imce.newEl('div')).attr('id', 'help-box').append($hbox.children()));
imce.hooks.load.push(function() {
imce.opAdd({name: 'help', title: $('#help-box-title').remove().text(), content: $('#help-box').show()});
});
//add ie classes
imce.ie && $('html').addClass('ie') && imce.ie < 8 && $('html').addClass('ie-7');
// enable box view for file list
imce.vars.boxW && imce.boxView();
//scrolling file list
imce.syncScroll(imce.SBW, '#file-header-wrapper');
imce.syncScroll(imce.SBW, '#dir-stat', true);
//scrolling directory tree
imce.syncScroll(imce.NW, '#navigation-header');
}
};
//initiate
$(document).ready(imce.initiate);
})(jQuery);

View File

@@ -0,0 +1,284 @@
//This pack implemets: keyboard shortcuts, file sorting, resize bars, and inline thumbnail preview.
(function($) {
// add scale calculator for resizing.
imce.hooks.load.push(function () {
$('#edit-width, #edit-height').focus(function () {
var fid, r, w, isW, val;
if (fid = imce.vars.prvfid) {
isW = this.id == 'edit-width', val = imce.el(isW ? 'edit-height' : 'edit-width').value*1;
if (val && (w = imce.isImage(fid)) && (r = imce.fids[fid].cells[3].innerHTML*1 / w))
this.value = Math.round(isW ? val/r : val*r);
}
});
});
// Shortcuts
var F = null;
imce.initiateShortcuts = function () {
$(imce.NW).attr('tabindex', '0').keydown(function (e) {
if (F = imce.dirKeys['k'+ e.keyCode]) return F(e);
});
$(imce.FLW).attr('tabindex', '0').keydown(function (e) {
if (F = imce.fileKeys['k'+ e.keyCode]) return F(e);
}).focus();
};
//shortcut key-function pairs for directories
imce.dirKeys = {
k35: function (e) {//end-home. select first or last dir
var L = imce.tree['.'].li;
if (e.keyCode == 35) while (imce.hasC(L, 'expanded')) L = L.lastChild.lastChild;
$(L.childNodes[1]).click().focus();
},
k37: function (e) {//left-right. collapse-expand directories.(right may also move focus on files)
var L, B = imce.tree[imce.conf.dir], right = e.keyCode == 39;
if (B.ul && (right ^ imce.hasC(L = B.li, 'expanded')) ) $(L.firstChild).click();
else if (right) $(imce.FLW).focus();
},
k38: function (e) {//up. select the previous directory
var B = imce.tree[imce.conf.dir];
if (L = B.li.previousSibling) {
while (imce.hasC(L, 'expanded')) L = L.lastChild.lastChild;
$(L.childNodes[1]).click().focus();
}
else if ((L = B.li.parentNode.parentNode) && L.tagName == 'LI') $(L.childNodes[1]).click().focus();
},
k40: function (e) {//down. select the next directory
var B = imce.tree[imce.conf.dir], L = B.li, U = B.ul;
if (U && imce.hasC(L, 'expanded')) $(U.firstChild.childNodes[1]).click().focus();
else do {if (L.nextSibling) return $(L.nextSibling.childNodes[1]).click().focus();
}while ((L = L.parentNode.parentNode).tagName == 'LI');
}
};
//add equal keys
imce.dirKeys.k36 = imce.dirKeys.k35;
imce.dirKeys.k39 = imce.dirKeys.k37;
//shortcut key-function pairs for files
imce.fileKeys = {
k38: function (e) {//up-down. select previous-next row
var fid = imce.lastFid(), i = fid ? imce.fids[fid].rowIndex+e.keyCode-39 : 0;
imce.fileClick(imce.findex[i], e.ctrlKey, e.shiftKey);
},
k35: function (e) {//end-home. select first or last row
imce.fileClick(imce.findex[e.keyCode == 35 ? imce.findex.length-1 : 0], e.ctrlKey, e.shiftKey);
},
k13: function (e) {//enter-insert. send file to external app.
imce.send(imce.vars.prvfid);
return false;
},
k37: function (e) {//left. focus on directories
$(imce.tree[imce.conf.dir].a).focus();
},
k65: function (e) {//ctrl+A to select all
if (e.ctrlKey && imce.findex.length) {
var fid = imce.findex[0].id;
imce.selected[fid] ? (imce.vars.lastfid = fid) : imce.fileClick(fid);//select first row
imce.fileClick(imce.findex[imce.findex.length-1], false, true);//shift+click last row
return false;
}
}
};
//add equal keys
imce.fileKeys.k40 = imce.fileKeys.k38;
imce.fileKeys.k36 = imce.fileKeys.k35;
imce.fileKeys.k45 = imce.fileKeys.k13;
//add default operation keys. delete, R(esize), T(humbnails), U(pload)
$.each({k46: 'delete', k82: 'resize', k84: 'thumb', k85: 'upload'}, function (k, op) {
imce.fileKeys[k] = function (e) {
if (imce.ops[op] && !imce.ops[op].disabled) imce.opClick(op);
};
});
//prepare column sorting
imce.initiateSorting = function() {
//add cache hook. cache the old directory's sort settings before the new one replaces it.
imce.hooks.cache.push(function (cache, newdir) {
cache.cid = imce.vars.cid, cache.dsc = imce.vars.dsc;
});
//add navigation hook. refresh sorting after the new directory content is loaded.
imce.hooks.navigate.push(function (data, olddir, cached) {
cached ? imce.updateSortState(data.cid, data.dsc) : imce.firstSort();
});
imce.vars.cid = imce.cookie('imcecid') * 1;
imce.vars.dsc = imce.cookie('imcedsc') * 1;
imce.cols = imce.el('file-header').rows[0].cells;
$(imce.cols).click(function () {imce.columnSort(this.cellIndex, imce.hasC(this, 'asc'));});
imce.firstSort();
};
//sort the list for the first time
imce.firstSort = function() {
imce.columnSort(imce.vars.cid, imce.vars.dsc);
};
//sort file list according to column index.
imce.columnSort = function(cid, dsc) {
if (imce.findex.length < 2) return;
var func = 'sort'+ (cid == 0 ? 'Str' : 'Num') + (dsc ? 'Dsc' : 'Asc');
var prop = cid == 2 || cid == 3 ? 'innerHTML' : 'id';
//sort rows
imce.findex.sort(cid ? function(r1, r2) {return imce[func](r1.cells[cid][prop], r2.cells[cid][prop])} : function(r1, r2) {return imce[func](r1.id, r2.id)});
//insert sorted rows
for (var row, i=0; row = imce.findex[i]; i++) {
imce.tbody.appendChild(row);
}
imce.updateSortState(cid, dsc);
};
//update column states
imce.updateSortState = function(cid, dsc) {
$(imce.cols[imce.vars.cid]).removeClass(imce.vars.dsc ? 'desc' : 'asc');
$(imce.cols[cid]).addClass(dsc ? 'desc' : 'asc');
imce.vars.cid != cid && imce.cookie('imcecid', imce.vars.cid = cid);
imce.vars.dsc != dsc && imce.cookie('imcedsc', (imce.vars.dsc = dsc) ? 1 : 0);
};
//sorters
imce.sortStrAsc = function(a, b) {return a.toLowerCase() < b.toLowerCase() ? -1 : 1;};
imce.sortStrDsc = function(a, b) {return imce.sortStrAsc(b, a);};
imce.sortNumAsc = function(a, b) {return a-b;};
imce.sortNumDsc = function(a, b) {return b-a};
//set resizers for resizable areas and recall previous dimensions
imce.initiateResizeBars = function () {
imce.setResizer('#navigation-resizer', 'X', imce.NW, null, 1, function(p1, p2, m) {
p1 != p2 && imce.cookie('imcenww', p2);
});
imce.setResizer('#browse-resizer', 'Y', imce.BW, imce.PW, 50, function(p1, p2, m) {
p1 != p2 && imce.cookie('imcebwh', p2);
});
imce.recallDimensions();
};
//set a resize bar
imce.setResizer = function (resizer, axis, area1, area2, Min, callback) {
var opt = axis == 'X' ? {pos: 'pageX', func: 'width'} : {pos: 'pageY', func: 'height'};
var Min = Min || 0;
var $area1 = $(area1), $area2 = area2 ? $(area2) : null, $doc = $(document);
$(resizer).mousedown(function(e) {
var pos = e[opt.pos];
var end = start = $area1[opt.func]();
var Max = $area2 ? start + $area2[opt.func]() : 1200;
var drag = function(e) {
end = Math.min(Max - Min, Math.max(start + e[opt.pos] - pos, Min));
$area1[opt.func](end);
$area2 && $area2[opt.func](Max - end);
return false;
};
var undrag = function(e) {
$doc.unbind('mousemove', drag).unbind('mouseup', undrag);
callback && callback(start, end, Max);
};
$doc.mousemove(drag).mouseup(undrag);
return false;
});
};
//get&set area dimensions of the last session from the cookie
imce.recallDimensions = function() {
var $body = $(document.body);
if (!$body.hasClass('imce')) return;
//row heights
imce.recallHeights(imce.cookie('imcebwh') * 1);
$(window).resize(function(){imce.recallHeights()});
//navigation wrapper
var nwOldWidth = imce.cookie('imcenww') * 1;
nwOldWidth && $(imce.NW).width(Math.min(nwOldWidth, $body.width() - 10));
};
//set row heights with respect to window height
imce.recallHeights = function(bwFixedHeight) {
//window & body dimensions
var winHeight = window.opera ? window.innerHeight : $(window).height();
var bodyHeight = $(document.body).outerHeight(true);
var diff = winHeight - bodyHeight;
var bwHeight = $(imce.BW).height(), pwHeight = $(imce.PW).height();
if (bwFixedHeight) {
//row heights
diff -= bwFixedHeight - bwHeight;
bwHeight = bwFixedHeight;
pwHeight += diff;
}
else {
diff = parseInt(diff/2);
bwHeight += diff;
pwHeight += diff;
}
$(imce.BW).height(bwHeight);
$(imce.PW).height(pwHeight);
};
//cookie get & set
imce.cookie = function (name, value) {
if (typeof(value) == 'undefined') {//get
return document.cookie ? imce.decode((document.cookie.match(new RegExp('(?:^|;) *' + name + '=([^;]*)(?:;|$)')) || ['', ''])[1].replace(/\+/g, '%20')) : '';
}
document.cookie = name +'='+ encodeURIComponent(value) +'; expires='+ (new Date(new Date() * 1 + 15 * 86400000)).toUTCString() +'; path=' + Drupal.settings.basePath + 'imce';//set
};
//view thumbnails(smaller than tMaxW x tMaxH) inside the rows.
//Large images can also be previewed by setting imce.vars.prvstyle to a valid image style(imagecache preset)
imce.thumbRow = function (row) {
var w = row.cells[2].innerHTML * 1;
if (!w) return;
var h = row.cells[3].innerHTML * 1;
if (imce.vars.tMaxW < w || imce.vars.tMaxH < h) {
if (!imce.vars.prvstyle || imce.conf.dir.indexOf('styles') == 0) return;
var img = new Image();
img.src = imce.imagestyleURL(imce.getURL(row.id), imce.vars.prvstyle);
img.className = 'imagestyle-' + imce.vars.prvstyle;
}
else {
var prvH = h, prvW = w;
if (imce.vars.prvW < w || imce.vars.prvH < h) {
if (h < w) {
prvW = imce.vars.prvW;
prvH = prvW*h/w;
}
else {
prvH = imce.vars.prvH;
prvW = prvH*w/h;
}
}
var img = new Image(prvW, prvH);
img.src = imce.getURL(row.id);
}
var cell = row.cells[0];
cell.insertBefore(img, cell.firstChild);
};
//convert a file URL returned by imce.getURL() to an image style(imagecache preset) URL
imce.imagestyleURL = function (url, stylename) {
var len = imce.conf.furl.length - 1;
return url.substr(0, len) + '/styles/' + stylename + '/' + imce.conf.scheme + url.substr(len);
};
// replace table view with box view for file list
imce.boxView = function () {
var w = imce.vars.boxW, h = imce.vars.boxH;
if (!w || !h || imce.ie && imce.ie < 8) return;
var $body = $(document.body);
var toggle = function() {
$body.toggleClass('box-view');
// refresh dom. required by all except FF.
$('#file-list').appendTo(imce.FW).appendTo(imce.FLW);
};
$body.append('<style type="text/css">.box-view #file-list td.name {width: ' + w + 'px;height: ' + h + 'px;} .box-view #file-list td.name span {width: ' + w + 'px;word-wrap: normal;text-overflow: ellipsis;}</style>');
imce.hooks.load.push(function() {
toggle();
imce.SBW.scrollTop = 0;
imce.opAdd({name: 'changeview', title: Drupal.t('Change view'), func: toggle});
});
imce.hooks.list.push(imce.boxViewRow);
};
// process a row for box view. include all data in box title.
imce.boxViewRow = function (row) {
var s = ' | ', w = row.cells[2].innerHTML * 1, dim = w ? s + w + 'x' + row.cells[3].innerHTML * 1 : '';
row.cells[0].title = imce.decode(row.id) + s + row.cells[1].innerHTML + (dim) + s + row.cells[4].innerHTML;
};
})(jQuery);

View File

@@ -0,0 +1,97 @@
/*
* IMCE Integration by URL
* Ex-1: http://example.com/imce?app=XEditor|url@urlFieldId|width@widthFieldId|height@heightFieldId
* Creates "Insert file" operation tab, which fills the specified fields with url, width, height properties
* of the selected file in the parent window
* Ex-2: http://example.com/imce?app=XEditor|sendto@functionName
* "Insert file" operation calls parent window's functionName(file, imceWindow)
* Ex-3: http://example.com/imce?app=XEditor|imceload@functionName
* Parent window's functionName(imceWindow) is called as soon as IMCE UI is ready. Send to operation
* needs to be set manually. See imce.setSendTo() method in imce.js
*/
(function($) {
var appFields = {}, appWindow = (top.appiFrm||window).opener || parent;
// Execute when imce loads.
imce.hooks.load.push(function(win) {
var index = location.href.lastIndexOf('app=');
if (index == -1) return;
var data = decodeURIComponent(location.href.substr(index + 4)).split('|');
var arr, prop, str, func, appName = data.shift();
// Extract fields
for (var i = 0, len = data.length; i < len; i++) {
str = data[i];
if (!str.length) continue;
if (str.indexOf('&') != -1) str = str.split('&')[0];
arr = str.split('@');
if (arr.length > 1) {
prop = arr.shift();
appFields[prop] = arr.join('@');
}
}
// Run custom onload function if available
if (appFields.imceload && (func = isFunc(appFields.imceload))) {
func(win);
delete appFields.imceload;
}
// Set custom sendto function. appFinish is the default.
var sendtoFunc = appFields.url ? appFinish : false;
//check sendto@funcName syntax in URL
if (appFields.sendto && (func = isFunc(appFields.sendto))) {
sendtoFunc = func;
delete appFields.sendto;
}
// Check old method windowname+ImceFinish.
else if (win.name && (func = isFunc(win.name +'ImceFinish'))) {
sendtoFunc = func;
}
// Highlight file
if (appFields.url) {
// Support multiple url fields url@field1,field2..
if (appFields.url.indexOf(',') > -1) {
var arr = appFields.url.split(',');
for (var i in arr) {
if ($('#'+ arr[i], appWindow.document).length) {
appFields.url = arr[i];
break;
}
}
}
var filename = $('#'+ appFields.url, appWindow.document).val() || '';
imce.highlight(filename.substr(filename.lastIndexOf('/')+1));
}
// Set send to
sendtoFunc && imce.setSendTo(Drupal.t('Insert file'), sendtoFunc);
});
// Default sendTo function
var appFinish = function(file, win) {
var $doc = $(appWindow.document);
for (var i in appFields) {
$doc.find('#'+ appFields[i]).val(file[i]);
}
if (appFields.url) {
try{
$doc.find('#'+ appFields.url).blur().change().focus();
}catch(e){
try{
$doc.find('#'+ appFields.url).trigger('onblur').trigger('onchange').trigger('onfocus');//inline events for IE
}catch(e){}
}
}
appWindow.focus();
win.close();
};
// Checks if a string is a function name in the given scope.
// Returns function reference. Supports x.y.z notation.
var isFunc = function(str, scope) {
var obj = scope || appWindow;
var parts = str.split('.'), len = parts.length;
for (var i = 0; i < len && (obj = obj[parts[i]]); i++);
return obj && i == len && (typeof obj == 'function' || typeof obj != 'string' && !obj.nodeName && obj.constructor != Array && /^[\s[]?function/.test(obj.toString())) ? obj : false;
}
})(jQuery);

View File

@@ -0,0 +1,58 @@
(function($) {
var ii = window.imceInline = {};
// Drupal behavior
Drupal.behaviors.imceInline = {attach: function(context, settings) {
$('div.imce-inline-wrapper', context).not('.processed').addClass('processed').show().find('a').click(function() {
var i = this.name.indexOf('-IMCE-');
ii.activeTextarea = $('#'+ this.name.substr(0, i)).get(0);
ii.activeType = this.name.substr(i+6);
if (typeof ii.pop == 'undefined' || ii.pop.closed) {
ii.pop = window.open(this.href + (this.href.indexOf('?') < 0 ? '?' : '&') +'app=nomatter|imceload@imceInline.load', '', 'width='+ 760 +',height='+ 560 +',resizable=1');
}
ii.pop.focus();
return false;
});
}};
//function to be executed when imce loads.
ii.load = function(win) {
win.imce.setSendTo(Drupal.t('Insert file'), ii.insert);
$(window).bind('unload', function() {
if (ii.pop && !ii.pop.closed) ii.pop.close();
});
};
//insert html at cursor position
ii.insertAtCursor = function (field, txt, type) {
field.focus();
if ('undefined' != typeof(field.selectionStart)) {
if (type == 'link' && (field.selectionEnd-field.selectionStart)) {
txt = txt.split('">')[0] +'">'+ field.value.substring(field.selectionStart, field.selectionEnd) +'</a>';
}
field.value = field.value.substring(0, field.selectionStart) + txt + field.value.substring(field.selectionEnd, field.value.length);
}
else if (document.selection) {
if (type == 'link' && document.selection.createRange().text.length) {
txt = txt.split('">')[0] +'">'+ document.selection.createRange().text +'</a>';
}
document.selection.createRange().text = txt;
}
else {
field.value += txt;
}
};
//sendTo function
ii.insert = function (file, win) {
var type = ii.activeType == 'link' ? 'link' : (file.width ? 'image' : 'link');
var html = type == 'image' ? ('<img src="'+ file.url +'" width="'+ file.width +'" height="'+ file.height +'" alt="'+ file.name +'" />') : ('<a href="'+ file.url +'">'+ file.name +' ('+ file.size +')</a>');
ii.activeType = null;
win.blur();
ii.insertAtCursor(ii.activeTextarea, html, type);
};
})(jQuery);

View File

@@ -0,0 +1,31 @@
/*!
* jQuery Form Plugin
* version: 3.17 (25-SEP-2012)
* @requires jQuery v1.3.2 or later
*/
(function(c){'use strict';function v(a){var d=a.data;a.isDefaultPrevented()||(a.preventDefault(),c(a.target).ajaxSubmit(d))}function y(a){var d=a.target,g=c(d);if(!g.is(":submit,input:image")){d=g.closest(":submit");if(0===d.length)return;d=d[0]}var f=this;f.clk=d;"image"==d.type&&(void 0!==a.offsetX?(f.clk_x=a.offsetX,f.clk_y=a.offsetY):"function"==typeof c.fn.offset?(g=g.offset(),f.clk_x=a.pageX-g.left,f.clk_y=a.pageY-g.top):(f.clk_x=a.pageX-d.offsetLeft,f.clk_y=a.pageY-d.offsetTop));setTimeout(function(){f.clk=
f.clk_x=f.clk_y=null},100)}function s(){if(c.fn.ajaxSubmit.debug){var a="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(a):window.opera&&window.opera.postError&&window.opera.postError(a)}}var x,z;x=void 0!==c("<input type='file'/>").get(0).files;z=void 0!==window.FormData;c.fn.ajaxSubmit=function(a){function d(b){b=c.param(b,a.traditional).replace(/\+/g," ").split("&");var f=b.length,h=[],d,e;for(d=0;d<f;d++)e=b[d].split("="),h.push([decodeURIComponent(e[0]),
decodeURIComponent(e[1])]);return h}function g(b){for(var f=new FormData,g=0;g<b.length;g++)f.append(b[g].name,b[g].value);if(a.extraData)for(b=d(a.extraData),g=0;g<b.length;g++)f.append(b[g][0],b[g][1]);a.data=null;g=c.extend(!0,{},c.ajaxSettings,a,{contentType:!1,processData:!1,cache:!1,type:h||"POST"});a.uploadProgress&&(g.xhr=function(){var e=c.ajaxSettings.xhr();e.upload&&(e.upload.onprogress=function(c){var e=0,b=c.loaded||c.position,f=c.total;c.lengthComputable&&(e=Math.ceil(b/f*100));a.uploadProgress(c,
b,f,e)});return e});g.data=null;var l=g.beforeSend;g.beforeSend=function(c,b){b.data=a.formData||f;l&&l.call(this,c,b)};return c.ajax(g)}function f(b){function f(){function a(){try{var c=(q.contentWindow?q.contentWindow.document:q.contentDocument?q.contentDocument:q.document).readyState;s("state = "+c);c&&"uninitialized"==c.toLowerCase()&&setTimeout(a,50)}catch(b){s("Server abort: ",b," (",b.name,")"),g(x),v&&clearTimeout(v),v=void 0}}var b=d.target,k=d.action,l=d.enctype||d.encoding||"multipart/form-data";
d.target=m;d.action=e.url;if(!h||/post/i.test(h))d.method="POST";e.skipEncodingOverride||h&&!/post/i.test(h)||(d.enctype="multipart/form-data");e.timeout&&(v=setTimeout(function(){w=!0;g(y)},e.timeout));var p=[];try{if(e.extraData)for(var n in e.extraData)e.extraData.hasOwnProperty(n)&&(e.extraData[n].constructor===Object&&e.extraData[n].hasOwnProperty("name")&&e.extraData[n].hasOwnProperty("value")?p.push(c('<input type="hidden" name="'+e.extraData[n].name+'">').val(e.extraData[n].value).appendTo(d)[0]):
p.push(c('<input type="hidden" name="'+n+'">').val(e.extraData[n]).appendTo(d)[0]));e.iframeTarget||(r.appendTo("body"),q.attachEvent?q.attachEvent("onload",g):q.addEventListener("load",g,!1));setTimeout(a,15);d.submit.call?d.submit():document.createElement("form").submit.call(d)}finally{d.action=k,d.target=b,d.enctype=l,c(p).remove()}}function g(a){if(!k.aborted&&!C){try{t=q.contentWindow?q.contentWindow.document:q.contentDocument?q.contentDocument:q.document}catch(b){s("cannot access response document: ",
b),a=x}if(a===y&&k)k.abort("timeout");else if(a==x&&k)k.abort("server abort");else if(t&&t.location.href!=e.iframeSrc||w){q.detachEvent?q.detachEvent("onload",g):q.removeEventListener("load",g,!1);a="success";var d;try{if(w)throw"timeout";var f="xml"==e.dataType||t.XMLDocument||c.isXMLDoc(t);s("isXml="+f);if(!f&&window.opera&&(null===t.body||!t.body.innerHTML)&&--E){s("requeing onLoad callback, DOM not available");setTimeout(g,250);return}var h=t.body?t.body:t.documentElement;k.responseText=h?h.innerHTML:
null;k.responseXML=t.XMLDocument?t.XMLDocument:t;f&&(e.dataType="xml");k.getResponseHeader=function(a){return{"content-type":e.dataType}[a.toLowerCase()]};h&&(k.status=Number(h.getAttribute("status"))||k.status,k.statusText=h.getAttribute("statusText")||k.statusText);var m=(e.dataType||"").toLowerCase(),n=/(json|script|text)/.test(m);if(n||e.textarea){var p=t.getElementsByTagName("textarea")[0];if(p)k.responseText=p.value,k.status=Number(p.getAttribute("status"))||k.status,k.statusText=p.getAttribute("statusText")||
k.statusText;else if(n){var u=t.getElementsByTagName("pre")[0],A=t.getElementsByTagName("body")[0];u?k.responseText=u.textContent?u.textContent:u.innerText:A&&(k.responseText=A.textContent?A.textContent:A.innerText)}}else"xml"==m&&!k.responseXML&&k.responseText&&(k.responseXML=F(k.responseText));try{z=G(k,m,e)}catch(D){a="parsererror",k.error=d=D||a}}catch(B){s("error caught: ",B),a="error",k.error=d=B||a}k.aborted&&(s("upload aborted"),a=null);k.status&&(a=200<=k.status&&300>k.status||304===k.status?
"success":"error");"success"===a?(e.success&&e.success.call(e.context,z,"success",k),l&&c.event.trigger("ajaxSuccess",[k,e])):a&&(void 0===d&&(d=k.statusText),e.error&&e.error.call(e.context,k,a,d),l&&c.event.trigger("ajaxError",[k,e,d]));l&&c.event.trigger("ajaxComplete",[k,e]);l&&!--c.active&&c.event.trigger("ajaxStop");e.complete&&e.complete.call(e.context,k,a);C=!0;e.timeout&&clearTimeout(v);setTimeout(function(){e.iframeTarget||r.remove();k.responseXML=null},100)}}}var d=n[0],e,l,m,r,q,k,u,w,
v;if(b)for(b=0;b<p.length;b++)p[b].disabled=!1;e=c.extend(!0,{},c.ajaxSettings,a);e.context=e.context||e;m="jqFormIO"+(new Date).getTime();e.iframeTarget?(r=c(e.iframeTarget),(u=r[0].name)?m=u:r[0].name=m):(r=c('<iframe name="'+m+'" src="'+e.iframeSrc+'" />'),r.css({position:"absolute",top:"-1000px",left:"-1000px"}));q=r[0];k={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(a){var b=
"timeout"===a?"timeout":"aborted";s("aborting upload... "+b);this.aborted=1;try{q.contentWindow.document.execCommand&&q.contentWindow.document.execCommand("Stop")}catch(d){}q.src=e.iframeSrc;k.error=b;e.error&&e.error.call(e.context,k,b,a);l&&c.event.trigger("ajaxError",[k,e,b]);e.complete&&e.complete.call(e.context,k,b)}};(l=e.global)&&0===c.active++&&c.event.trigger("ajaxStart");l&&c.event.trigger("ajaxSend",[k,e]);if(e.beforeSend&&!1===e.beforeSend.call(e.context,k,e))e.global&&c.active--;else if(!k.aborted){(b=
d.clk)&&(u=b.name)&&!b.disabled&&(e.extraData=e.extraData||{},e.extraData[u]=b.value,"image"==b.type&&(e.extraData[u+".x"]=d.clk_x,e.extraData[u+".y"]=d.clk_y));var y=1,x=2;b=c("meta[name=csrf-token]").attr("content");(u=c("meta[name=csrf-param]").attr("content"))&&b&&(e.extraData=e.extraData||{},e.extraData[u]=b);e.forceSync?f():setTimeout(f,10);var z,t,E=50,C,F=c.parseXML||function(a,b){window.ActiveXObject?(b=new ActiveXObject("Microsoft.XMLDOM"),b.async="false",b.loadXML(a)):b=(new DOMParser).parseFromString(a,
"text/xml");return b&&b.documentElement&&"parsererror"!=b.documentElement.nodeName?b:null},H=c.parseJSON||function(a){return window.eval("("+a+")")},G=function(a,b,e){var d=a.getResponseHeader("content-type")||"",f="xml"===b||!b&&0<=d.indexOf("xml");a=f?a.responseXML:a.responseText;f&&"parsererror"===a.documentElement.nodeName&&c.error&&c.error("parsererror");e&&e.dataFilter&&(a=e.dataFilter(a,b));"string"===typeof a&&("json"===b||!b&&0<=d.indexOf("json")?a=H(a):("script"===b||!b&&0<=d.indexOf("javascript"))&&
c.globalEval(a));return a}}}if(!this.length)return s("ajaxSubmit: skipping submit process - no element selected"),this;var h,b,n=this;a?"function"===typeof a&&(a={success:a}):a={};h=a.type||n[0].method;b=a.url||n[0].action;(b=(b="string"===typeof b?c.trim(b):"")||window.location.href||"")&&(b=(b.match(/^([^#]+)/)||[])[1]);a=c.extend(!0,{url:b,success:c.ajaxSettings.success,type:h||c.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},a);b={};this.trigger("form-pre-serialize",
[this,a,b]);if(b.veto)return s("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(a.beforeSerialize&&!1===a.beforeSerialize(this,a))return s("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var m=a.traditional;void 0===m&&(m=c.ajaxSettings.traditional);var p=[],l,r=this.formToArray(a.semantic,p);a.data&&(a.extraData=a.data,l=c.param(a.data,m));if(a.beforeSubmit&&!1===a.beforeSubmit(r,this,a))return s("ajaxSubmit: submit aborted via beforeSubmit callback"),this;this.trigger("form-submit-validate",
[r,this,a,b]);if(b.veto)return s("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;b=c.param(r,m);l&&(b=b?b+"&"+l:l);"GET"==a.type.toUpperCase()?(a.url+=(0<=a.url.indexOf("?")?"&":"?")+b,a.data=null):a.data=b;var w=[];a.resetForm&&w.push(function(){n.resetForm()});a.clearForm&&w.push(function(){n.clearForm(a.includeHidden)});if(!a.dataType&&a.target){var v=a.success||function(){};w.push(function(b){var d=a.replaceTarget?"replaceWith":"html";c(a.target)[d](b).each(v,arguments)})}else a.success&&
w.push(a.success);a.success=function(b,c,d){for(var f=a.context||this,e=0,g=w.length;e<g;e++)w[e].apply(f,[b,c,d||n,n])};l=0<c("input:file:enabled[value]",this).length;b="multipart/form-data"==n[0].enctype||"multipart/form-data"==n[0].encoding;m=x&&z;s("fileAPI :"+m);!1!==a.iframe&&(a.iframe||(l||b)&&!m)?a.closeKeepAlive?c.get(a.closeKeepAlive,function(){f(r)}):f(r):a.jqxhr=(l||b)&&m?g(r):c.ajax(a);for(l=0;l<p.length;l++)p[l]=null;this.trigger("form-submit-notify",[this,a]);return this};c.fn.ajaxForm=
function(a){a=a||{};a.delegation=a.delegation&&c.isFunction(c.fn.on);if(!a.delegation&&0===this.length){var d=this.selector,g=this.context;if(!c.isReady&&d)return s("DOM not ready, queuing ajaxForm"),c(function(){c(d,g).ajaxForm(a)}),this;s("terminating; zero elements found by selector"+(c.isReady?"":" (DOM not ready)"));return this}return a.delegation?(c(document).off("submit.form-plugin",this.selector,v).off("click.form-plugin",this.selector,y).on("submit.form-plugin",this.selector,a,v).on("click.form-plugin",
this.selector,a,y),this):this.ajaxFormUnbind().bind("submit.form-plugin",a,v).bind("click.form-plugin",a,y)};c.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")};c.fn.formToArray=function(a,d){var g=[];if(0===this.length)return g;var f=this[0],h=a?f.getElementsByTagName("*"):f.elements;if(!h||!h.length)return g;var b,n,m,p,l,r;b=0;for(r=h.length;b<r;b++)if(l=h[b],(m=l.name)&&!l.disabled)if(a&&f.clk&&"image"==l.type)f.clk==l&&(g.push({name:m,value:c(l).val(),type:l.type}),
g.push({name:m+".x",value:f.clk_x},{name:m+".y",value:f.clk_y}));else if((p=c.fieldValue(l,!0))&&p.constructor==Array)for(d&&d.push(l),n=0,l=p.length;n<l;n++)g.push({name:m,value:p[n]});else if(x&&"file"==l.type)if(d&&d.push(l),p=l.files,p.length)for(n=0;n<p.length;n++)g.push({name:m,value:p[n],type:l.type});else g.push({name:m,value:"",type:l.type});else null!==p&&"undefined"!=typeof p&&(d&&d.push(l),g.push({name:m,value:p,type:l.type,required:l.required}));!a&&f.clk&&(h=c(f.clk),b=h[0],(m=b.name)&&
!b.disabled&&"image"==b.type&&(g.push({name:m,value:h.val()}),g.push({name:m+".x",value:f.clk_x},{name:m+".y",value:f.clk_y})));return g};c.fn.formSerialize=function(a){return c.param(this.formToArray(a))};c.fn.fieldSerialize=function(a){var d=[];this.each(function(){var g=this.name;if(g){var f=c.fieldValue(this,a);if(f&&f.constructor==Array)for(var h=0,b=f.length;h<b;h++)d.push({name:g,value:f[h]});else null!==f&&"undefined"!=typeof f&&d.push({name:this.name,value:f})}});return c.param(d)};c.fn.fieldValue=
function(a){for(var d=[],g=0,f=this.length;g<f;g++){var h=c.fieldValue(this[g],a);null===h||"undefined"==typeof h||h.constructor==Array&&!h.length||(h.constructor==Array?c.merge(d,h):d.push(h))}return d};c.fieldValue=function(a,d){var g=a.name,f=a.type,h=a.tagName.toLowerCase();void 0===d&&(d=!0);if(d&&(!g||a.disabled||"reset"==f||"button"==f||("checkbox"==f||"radio"==f)&&!a.checked||("submit"==f||"image"==f)&&a.form&&a.form.clk!=a||"select"==h&&-1==a.selectedIndex))return null;if("select"==h){var b=
a.selectedIndex;if(0>b)return null;for(var g=[],h=a.options,n=(f="select-one"==f)?b+1:h.length,b=f?b:0;b<n;b++){var m=h[b];if(m.selected){var p=m.value;p||(p=m.attributes&&m.attributes.value&&!m.attributes.value.specified?m.text:m.value);if(f)return p;g.push(p)}}return g}return c(a).val()};c.fn.clearForm=function(a){return this.each(function(){c("input,select,textarea",this).clearFields(a)})};c.fn.clearFields=c.fn.clearInputs=function(a){var d=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;
return this.each(function(g,f){var h=this.type,b=this.tagName.toLowerCase();d.test(h)||"textarea"==b?this.value="":"checkbox"==h||"radio"==h?this.checked=!1:"file"==h?c(this).val("").val()&&(h=document.createElement("form"),b=this.parentNode)&&(h.style.display="none",b.insertBefore(h,this),h.appendChild(this),h.reset(),b.insertBefore(this,h),b.removeChild(h)):"select"==b?this.selectedIndex=-1:a&&(!0===a&&/hidden/.test(h)||"string"==typeof a&&c(this).is(a))&&(this.value="")})};c.fn.resetForm=function(){return this.each(function(){("function"==
typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset()})};c.fn.enable=function(a){void 0===a&&(a=!0);return this.each(function(){this.disabled=!a})};c.fn.selected=function(a){void 0===a&&(a=!0);return this.each(function(){var d=this.type;"checkbox"==d||"radio"==d?this.checked=a:"option"==this.tagName.toLowerCase()&&(d=c(this).parent("select"),a&&d[0]&&"select-one"==d[0].type&&d.find("option").selected(!1),this.selected=a)})};c.fn.ajaxSubmit.debug=!1})(jQuery);