| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 // $Id: imce.js,v 1.16.2.11 2010/12/12 07:24:43 ufku Exp $ 2 3 (function($) { 4 //Global container. 5 window.imce = {tree: {}, findex: [], fids: {}, selected: {}, selcount: 0, ops: {}, cache: {}, urlId: {}, 6 vars: {previewImages: 1, cache: 1}, 7 hooks: {load: [], list: [], navigate: [], cache: []}, 8 9 //initiate imce. 10 initiate: function() { 11 imce.conf = Drupal.settings.imce || {}; 12 if (imce.conf.error != false) return; 13 imce.FLW = imce.el('file-list-wrapper'), imce.SBW = imce.el('sub-browse-wrapper'); 14 imce.NW = imce.el('navigation-wrapper'), imce.BW = imce.el('browse-wrapper'); 15 imce.PW = imce.el('preview-wrapper'), imce.FW = imce.el('forms-wrapper'); 16 imce.updateUI(); 17 imce.prepareMsgs();//process initial status messages 18 imce.initiateTree();//build directory tree 19 imce.hooks.list.unshift(imce.processRow);//set the default list-hook. 20 imce.initiateList();//process file list 21 imce.initiateOps();//prepare operation tabs 22 imce.refreshOps(); 23 imce.invoke('load', window);//run functions set by external applications. 24 }, 25 26 //process navigation tree 27 initiateTree: function() { 28 $('#navigation-tree li').each(function(i) { 29 var a = this.firstChild, txt = a.firstChild; 30 txt && (txt.data = imce.decode(txt.data)); 31 var branch = imce.tree[a.title] = {'a': a, li: this, ul: this.lastChild.tagName == 'UL' ? this.lastChild : null}; 32 if (a.href) imce.dirClickable(branch); 33 imce.dirCollapsible(branch); 34 }); 35 }, 36 37 //Add a dir to the tree under parent 38 dirAdd: function(dir, parent, clickable) { 39 if (imce.tree[dir]) return clickable ? imce.dirClickable(imce.tree[dir]) : imce.tree[dir]; 40 var parent = parent || imce.tree['.']; 41 parent.ul = parent.ul ? parent.ul : parent.li.appendChild(imce.newEl('ul')); 42 var branch = imce.dirCreate(dir, imce.decode(dir.substr(dir.lastIndexOf('/')+1)), clickable); 43 parent.ul.appendChild(branch.li); 44 return branch; 45 }, 46 47 //create list item for navigation tree 48 dirCreate: function(dir, text, clickable) { 49 if (imce.tree[dir]) return imce.tree[dir]; 50 var branch = imce.tree[dir] = {li: imce.newEl('li'), a: imce.newEl('a')}; 51 $(branch.a).addClass('folder').text(text).attr('title', dir).appendTo(branch.li); 52 imce.dirCollapsible(branch); 53 return clickable ? imce.dirClickable(branch) : branch; 54 }, 55 56 //change currently active directory 57 dirActivate: function(dir) { 58 if (dir != imce.conf.dir) { 59 if (imce.tree[imce.conf.dir]){ 60 $(imce.tree[imce.conf.dir].a).removeClass('active'); 61 } 62 $(imce.tree[dir].a).addClass('active'); 63 imce.conf.dir = dir; 64 } 65 return imce.tree[imce.conf.dir]; 66 }, 67 68 //make a dir accessible 69 dirClickable: function(branch) { 70 if (branch.clkbl) return branch; 71 $(branch.a).attr('href', '#').removeClass('disabled').click(function() {imce.navigate(this.title); return false;}); 72 branch.clkbl = true; 73 return branch; 74 }, 75 76 //sub-directories expand-collapse ability 77 dirCollapsible: function (branch) { 78 if (branch.clpsbl) return branch; 79 $(imce.newEl('span')).addClass('expander').html(' ').click(function() { 80 if (branch.ul) { 81 $(branch.ul).toggle(); 82 $(branch.li).toggleClass('expanded'); 83 $.browser.msie && $('#navigation-header').css('top', imce.NW.scrollTop); 84 } 85 else if (branch.clkbl){ 86 $(branch.a).click(); 87 } 88 }).prependTo(branch.li); 89 branch.clpsbl = true; 90 return branch; 91 }, 92 93 //update navigation tree after getting subdirectories. 94 dirSubdirs: function(dir, subdirs) { 95 var branch = imce.tree[dir]; 96 if (subdirs && subdirs.length) { 97 var prefix = dir == '.' ? '' : dir +'/'; 98 for (var i in subdirs) {//add subdirectories 99 imce.dirAdd(prefix + subdirs[i], branch, true); 100 } 101 $(branch.li).removeClass('leaf').addClass('expanded'); 102 $(branch.ul).show(); 103 } 104 else if (!branch.ul){//no subdirs->leaf 105 $(branch.li).removeClass('expanded').addClass('leaf'); 106 } 107 }, 108 109 //process file list 110 initiateList: function(cached) { 111 var L = imce.hooks.list, dir = imce.conf.dir, token = {'%dir': dir == '.' ? $(imce.tree['.'].a).text() : imce.decode(dir)} 112 imce.findex = [], imce.fids = {}, imce.selected = {}, imce.selcount = 0, imce.vars.lastfid = null; 113 imce.tbody = imce.el('file-list').tBodies[0]; 114 if (imce.tbody.rows.length) { 115 for (var row, i = 0; row = imce.tbody.rows[i]; i++) { 116 var fid = row.id; 117 imce.findex[i] = imce.fids[fid] = row; 118 if (cached) { 119 if (imce.hasC(row, 'selected')) { 120 imce.selected[imce.vars.lastfid = fid] = row; 121 imce.selcount++; 122 } 123 } 124 else { 125 for (var func, j = 0; func = L[j]; j++) func(row);//invoke list-hook 126 } 127 } 128 } 129 if (!imce.conf.perm.browse) { 130 imce.setMessage(Drupal.t('File browsing is disabled in directory %dir.', token), 'error'); 131 } 132 }, 133 134 //add a file to the list. (having properties name,size,formatted size,width,height,date,formatted date) 135 fileAdd: function(file) { 136 var row, fid = file.name, i = imce.findex.length, attr = ['name', 'size', 'width', 'height', 'date']; 137 if (!(row = imce.fids[fid])) { 138 row = imce.findex[i] = imce.fids[fid] = imce.tbody.insertRow(i); 139 for (var i in attr) row.insertCell(i).className = attr[i]; 140 } 141 row.cells[0].innerHTML = row.id = fid; 142 row.cells[1].innerHTML = file.fsize; row.cells[1].id = file.size; 143 row.cells[2].innerHTML = file.width; 144 row.cells[3].innerHTML = file.height; 145 row.cells[4].innerHTML = file.fdate; row.cells[4].id = file.date; 146 imce.invoke('list', row); 147 if (imce.vars.prvfid == fid) imce.setPreview(fid); 148 if (file.id) imce.urlId[imce.getURL(fid)] = file.id; 149 }, 150 151 //remove a file from the list 152 fileRemove: function(fid) { 153 if (!(row = imce.fids[fid])) return; 154 imce.fileDeSelect(fid); 155 imce.findex.splice(row.rowIndex, 1); 156 $(row).remove(); 157 delete imce.fids[fid]; 158 if (imce.vars.prvfid == fid) imce.setPreview(); 159 }, 160 161 //return a file object containing all properties. 162 fileGet: function (fid) { 163 var row = imce.fids[fid]; 164 var url = imce.getURL(fid); 165 return row ? { 166 name: imce.decode(fid), 167 url: url, 168 size: row.cells[1].innerHTML, 169 bytes: row.cells[1].id * 1, 170 width: row.cells[2].innerHTML * 1, 171 height: row.cells[3].innerHTML * 1, 172 date: row.cells[4].innerHTML, 173 time: row.cells[4].id * 1, 174 id: imce.urlId[url] || 0, //file id for newly uploaded files 175 relpath: (imce.conf.dir == '.' ? '' : imce.conf.dir +'/') + fid //rawurlencoded path relative to file directory path. 176 } : null; 177 }, 178 179 //simulate row click. selection-highlighting 180 fileClick: function(row, ctrl, shft) { 181 if (!row) return; 182 var fid = typeof(row) == 'string' ? row : row.id; 183 if (ctrl || fid == imce.vars.prvfid) { 184 imce.fileToggleSelect(fid); 185 } 186 else if (shft) { 187 var last = imce.lastFid(); 188 var start = last ? imce.fids[last].rowIndex : -1; 189 var end = imce.fids[fid].rowIndex; 190 var step = start > end ? -1 : 1; 191 while (start != end) { 192 start += step; 193 imce.fileSelect(imce.findex[start].id); 194 } 195 } 196 else { 197 for (var fname in imce.selected) { 198 imce.fileDeSelect(fname); 199 } 200 imce.fileSelect(fid); 201 } 202 //set preview 203 imce.setPreview(imce.selcount == 1 ? imce.lastFid() : null); 204 }, 205 206 //file select/deselect functions 207 fileSelect: function (fid) { 208 if (imce.selected[fid] || !imce.fids[fid]) return; 209 imce.selected[fid] = imce.fids[imce.vars.lastfid=fid]; 210 $(imce.selected[fid]).addClass('selected'); 211 imce.selcount++; 212 }, 213 fileDeSelect: function (fid) { 214 if (!imce.selected[fid] || !imce.fids[fid]) return; 215 if (imce.vars.lastfid == fid) imce.vars.lastfid = null; 216 $(imce.selected[fid]).removeClass('selected'); 217 delete imce.selected[fid]; 218 imce.selcount--; 219 }, 220 fileToggleSelect: function (fid) { 221 imce['file'+ (imce.selected[fid] ? 'De' : '') +'Select'](fid); 222 }, 223 224 //process file operation form and create operation tabs. 225 initiateOps: function() { 226 imce.setHtmlOps(); 227 imce.setUploadOp();//upload 228 imce.setFileOps();//thumb, delete, resize 229 }, 230 231 //process existing html ops. 232 setHtmlOps: function () { 233 $(imce.el('ops-list')).children('li').each(function() { 234 if (!this.firstChild) return $(this).remove(); 235 var name = this.id.substr(8); 236 var Op = imce.ops[name] = {div: imce.el('op-content-'+ name), li: imce.el('op-item-'+ name)}; 237 Op.a = Op.li.firstChild; 238 Op.title = Op.a.innerHTML; 239 $(Op.a).click(function() {imce.opClick(name); return false;}); 240 }); 241 }, 242 243 //convert upload form to an op. 244 setUploadOp: function () { 245 var form = imce.el('imce-upload-form'); 246 if (!form) return; 247 $(form).ajaxForm(imce.uploadSettings()).find('fieldset').each(function() {//clean up fieldsets 248 this.removeChild(this.firstChild); 249 $(this).after(this.childNodes); 250 }).remove(); 251 imce.opAdd({name: 'upload', title: Drupal.t('Upload'), content: form});//add op 252 }, 253 254 //convert fileop form submit buttons to ops. 255 setFileOps: function () { 256 var form = imce.el('imce-fileop-form'); 257 if (!form) return; 258 $(form.elements.filenames).parent().remove(); 259 $(form).find('fieldset').each(function() {//remove fieldsets 260 var $sbmt = $('input:submit', this); 261 if (!$sbmt.size()) return; 262 var Op = {name: $sbmt.attr('id').substr(5)}; 263 var func = function() {imce.fopSubmit(Op.name); return false;}; 264 $sbmt.click(func); 265 Op.title = $(this).children('legend').remove().text() || $sbmt.val(); 266 Op.name == 'delete' ? (Op.func = func) : (Op.content = this.childNodes); 267 imce.opAdd(Op); 268 }).remove(); 269 imce.vars.opform = $(form).serialize();//serialize remaining parts. 270 }, 271 272 //refresh ops states. enable/disable 273 refreshOps: function() { 274 for (var p in imce.conf.perm) { 275 if (imce.conf.perm[p]) imce.opEnable(p); 276 else imce.opDisable(p); 277 } 278 }, 279 280 //add a new file operation 281 opAdd: function (op) { 282 var oplist = imce.el('ops-list'), opcons = imce.el('op-contents'); 283 var name = op.name || ('op-'+ $(oplist).children('li').size()); 284 var title = op.title || 'Untitled'; 285 var Op = imce.ops[name] = {title: title}; 286 if (op.content) { 287 Op.div = imce.newEl('div'); 288 $(Op.div).attr({id: 'op-content-'+ name, 'class': 'op-content'}).appendTo(opcons).append(op.content); 289 } 290 Op.a = imce.newEl('a'); 291 Op.li = imce.newEl('li'); 292 $(Op.a).attr({href: '#', name: name, title: title}).html('<span>' + title +'</span>').click(imce.opClickEvent); 293 $(Op.li).attr('id', 'op-item-'+ name).append(Op.a).appendTo(oplist); 294 Op.func = op.func || imce.opVoid; 295 return Op; 296 }, 297 298 //click event for file operations 299 opClickEvent: function(e) { 300 imce.opClick(this.name); 301 return false; 302 }, 303 304 //void operation function 305 opVoid: function() {}, 306 307 //perform op click 308 opClick: function(name) { 309 var Op = imce.ops[name], oldop = imce.vars.op; 310 if (!Op || Op.disabled) { 311 return imce.setMessage(Drupal.t('You can not perform this operation.'), 'error'); 312 } 313 if (Op.div) { 314 if (oldop) { 315 var toggle = oldop == name; 316 imce.opShrink(oldop, toggle ? 'fadeOut' : 'hide'); 317 if (toggle) return false; 318 } 319 var left = Op.li.offsetLeft; 320 var $opcon = $('#op-contents').css({left: 0}); 321 $(Op.div).fadeIn('normal', function() { 322 setTimeout(function() { 323 if (imce.vars.op) { 324 var $inputs = $('input', imce.ops[imce.vars.op].div); 325 $inputs.eq(0).focus(); 326 //form inputs become invisible in IE. Solution is as stupid as the behavior. 327 $('html').is('.ie') && $inputs.addClass('dummyie').removeClass('dummyie'); 328 } 329 }); 330 }); 331 var diff = left + $opcon.width() - $('#imce-content').width(); 332 $opcon.css({left: diff > 0 ? left - diff : left}); 333 $(Op.li).addClass('active'); 334 $(imce.opCloseLink).fadeIn(300); 335 imce.vars.op = name; 336 } 337 Op.func(true); 338 return true; 339 }, 340 341 //enable a file operation 342 opEnable: function(name) { 343 var Op = imce.ops[name]; 344 if (Op && Op.disabled) { 345 Op.disabled = false; 346 $(Op.li).show(); 347 } 348 }, 349 350 //disable a file operation 351 opDisable: function(name) { 352 var Op = imce.ops[name]; 353 if (Op && !Op.disabled) { 354 Op.div && imce.opShrink(name); 355 $(Op.li).hide(); 356 Op.disabled = true; 357 } 358 }, 359 360 //hide contents of a file operation 361 opShrink: function(name, effect) { 362 if (imce.vars.op != name) return; 363 var Op = imce.ops[name]; 364 $(Op.div).stop(true, true)[effect || 'hide'](); 365 $(Op.li).removeClass('active'); 366 $(imce.opCloseLink).hide(); 367 Op.func(false); 368 imce.vars.op = null; 369 }, 370 371 //navigate to dir 372 navigate: function(dir) { 373 if (imce.vars.navbusy || (dir == imce.conf.dir && !confirm(Drupal.t('Do you want to refresh the current directory?')))) return; 374 var cache = imce.vars.cache && dir != imce.conf.dir; 375 var set = imce.navSet(dir, cache); 376 if (cache && imce.cache[dir]) {//load from the cache 377 set.success({data: imce.cache[dir]}); 378 set.complete(); 379 } 380 else $.ajax(set);//live load 381 }, 382 383 //ajax navigation settings 384 navSet: function (dir, cache) { 385 $(imce.tree[dir].li).addClass('loading'); 386 imce.vars.navbusy = dir; 387 return {url: imce.ajaxURL('navigate', dir), 388 type: 'GET', 389 dataType: 'json', 390 success: function(response) { 391 if (response.data && !response.data.error) { 392 if (cache) imce.navCache(imce.conf.dir, dir);//cache the current dir 393 imce.navUpdate(response.data, dir); 394 } 395 imce.processResponse(response); 396 }, 397 complete: function () { 398 $(imce.tree[dir].li).removeClass('loading'); 399 imce.vars.navbusy = null; 400 } 401 }; 402 }, 403 404 //update directory using the given data 405 navUpdate: function(data, dir) { 406 var cached = data == imce.cache[dir], olddir = imce.conf.dir; 407 if (cached) data.files.id = 'file-list'; 408 $(imce.FLW).html(data.files); 409 imce.dirActivate(dir); 410 imce.dirSubdirs(dir, data.subdirectories); 411 $.extend(imce.conf.perm, data.perm); 412 imce.refreshOps(); 413 imce.initiateList(cached); 414 imce.setPreview(imce.selcount == 1 ? imce.lastFid() : null); 415 imce.SBW.scrollTop = 0; 416 imce.invoke('navigate', data, olddir, cached); 417 }, 418 419 //set cache 420 navCache: function (dir, newdir) { 421 var C = imce.cache[dir] = {'dir': dir, files: imce.el('file-list'), dirsize: imce.el('dir-size').innerHTML, perm: $.extend({}, imce.conf.perm)}; 422 C.files.id = 'cached-list-'+ dir; 423 imce.FW.appendChild(C.files); 424 imce.invoke('cache', C, newdir); 425 }, 426 427 //validate upload form 428 uploadValidate: function (data, form, options) { 429 var path = data[0].value; 430 if (!path) return false; 431 if (imce.conf.extensions != '*') { 432 var ext = path.substr(path.lastIndexOf('.') + 1); 433 if ((' '+ imce.conf.extensions +' ').indexOf(' '+ ext.toLowerCase() +' ') == -1) { 434 return imce.setMessage(Drupal.t('Only files with the following extensions are allowed: %files-allowed.', {'%files-allowed': imce.conf.extensions}), 'error'); 435 } 436 } 437 var sep = path.indexOf('/') == -1 ? '\\' : '/'; 438 options.url = imce.ajaxURL('upload');//make url contain current dir. 439 imce.fopLoading('upload', true); 440 return true; 441 }, 442 443 //settings for upload 444 uploadSettings: function () { 445 return {beforeSubmit: imce.uploadValidate, success: function (response) {imce.processResponse(Drupal.parseJson(response));}, complete: function () {imce.fopLoading('upload', false);}, resetForm: true}; 446 }, 447 448 //validate default ops(delete, thumb, resize) 449 fopValidate: function(fop) { 450 if (!imce.validateSelCount(1, imce.conf.filenum)) return false; 451 switch (fop) { 452 case 'delete': 453 return confirm(Drupal.t('Delete selected files?')); 454 case 'thumb': 455 if (!$('input:checked', imce.ops['thumb'].div).size()) { 456 return imce.setMessage(Drupal.t('Please select a thumbnail.'), 'error'); 457 } 458 return imce.validateImage(); 459 case 'resize': 460 var w = imce.el('edit-width').value, h = imce.el('edit-height').value; 461 var maxDim = imce.conf.dimensions.split('x'); 462 var maxW = maxDim[0]*1, maxH = maxW ? maxDim[1]*1 : 0; 463 if (!(/^[1-9][0-9]*$/).test(w) || !(/^[1-9][0-9]*$/).test(h) || (maxW && (maxW < w*1 || maxH < h*1))) { 464 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'); 465 } 466 return imce.validateImage(); 467 } 468 469 var func = fop +'OpValidate'; 470 if (imce[func]) return imce[func](fop); 471 return true; 472 }, 473 474 //submit wrapper for default ops 475 fopSubmit: function(fop) { 476 switch (fop) { 477 case 'thumb': case 'delete': case 'resize': return imce.commonSubmit(fop); 478 } 479 var func = fop +'OpSubmit'; 480 if (imce[func]) return imce[func](fop); 481 }, 482 483 //common submit function shared by default ops 484 commonSubmit: function(fop) { 485 if (!imce.fopValidate(fop)) return false; 486 imce.fopLoading(fop, true); 487 $.ajax(imce.fopSettings(fop)); 488 }, 489 490 //settings for default file operations 491 fopSettings: function (fop) { 492 return {url: imce.ajaxURL(fop), type: 'POST', dataType: 'json', success: imce.processResponse, complete: function (response) {imce.fopLoading(fop, false);}, data: imce.vars.opform +'&filenames='+ imce.serialNames() +'&jsop='+ fop + (imce.ops[fop].div ? '&'+ $('input, select, textarea', imce.ops[fop].div).serialize() : '')}; 493 }, 494 495 //toggle loading state 496 fopLoading: function(fop, state) { 497 var el = imce.el('edit-'+ fop), func = state ? 'addClass' : 'removeClass' 498 if (el) { 499 $(el)[func]('loading').attr('disabled', state); 500 } 501 else { 502 $(imce.ops[fop].li)[func]('loading'); 503 imce.ops[fop].disabled = state; 504 } 505 }, 506 507 //preview a file. 508 setPreview: function (fid) { 509 var row, html = ''; 510 imce.vars.prvfid = fid; 511 if (fid && (row = imce.fids[fid])) { 512 var width = row.cells[2].innerHTML * 1; 513 html = imce.vars.previewImages && width ? imce.imgHtml(fid, width, row.cells[3].innerHTML) : imce.decodePlain(fid); 514 html = '<a href="#" onclick="imce.send(\''+ fid +'\'); return false;" title="'+ (imce.vars.prvtitle||'') +'">'+ html +'</a>'; 515 } 516 imce.el('file-preview').innerHTML = html; 517 }, 518 519 //default file send function. sends the file to the new window. 520 send: function (fid) { 521 fid && window.open(imce.getURL(fid)); 522 }, 523 524 //add an operation for an external application to which the files are send. 525 setSendTo: function (title, func) { 526 imce.send = function (fid) { fid && func(imce.fileGet(fid), window);}; 527 var opFunc = function () { 528 if (imce.selcount != 1) return imce.setMessage(Drupal.t('Please select a file.'), 'error'); 529 imce.send(imce.vars.prvfid); 530 }; 531 imce.vars.prvtitle = title; 532 return imce.opAdd({name: 'sendto', title: title, func: opFunc}); 533 }, 534 535 //move initial page messages into log 536 prepareMsgs: function () { 537 var msgs; 538 if (msgs = imce.el('imce-messages')) { 539 $('>div', msgs).each(function (){ 540 var type = this.className.split(' ')[1]; 541 var li = $('>ul li', this); 542 if (li.size()) li.each(function () {imce.setMessage(this.innerHTML, type);}); 543 else imce.setMessage(this.innerHTML, type); 544 }); 545 $(msgs).remove(); 546 } 547 }, 548 549 //insert log message 550 setMessage: function (msg, type) { 551 var $box = $(imce.msgBox); 552 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]; 553 var msg = '<div class="message '+ (type || 'status') +'">'+ msg +'</div>'; 554 $box.queue(function() { 555 $box.css({opacity: 0, display: 'block'}).html(msg); 556 $box.dequeue(); 557 }); 558 var q = $box.queue().length; 559 q = q < 2 ? 1 : q < 3 ? 0.8 : q < 4 ? 0.7 : 0.4;//adjust speed with respect to queue length 560 $box.fadeTo(600 * q, 1).fadeTo(1000 * q, 1).fadeOut(400 * q); 561 $(logs).append(msg); 562 return false; 563 }, 564 565 //invoke hooks 566 invoke: function (hook) { 567 var i, args, func, funcs; 568 if ((funcs = imce.hooks[hook]) && funcs.length) { 569 (args = $.makeArray(arguments)).shift(); 570 for (i = 0; func = funcs[i]; i++) func.apply(this, args); 571 } 572 }, 573 574 //process response 575 processResponse: function (response) { 576 if (response.data) imce.resData(response.data); 577 if (response.messages) imce.resMsgs(response.messages); 578 }, 579 580 //process response data 581 resData: function (data) { 582 var i, added, removed; 583 if (added = data.added) { 584 var cnt = imce.findex.length; 585 for (i in added) {//add new files or update existing 586 imce.fileAdd(added[i]); 587 } 588 if (added.length == 1) {//if it is a single file operation 589 imce.highlight(added[0].name);//highlight 590 } 591 if (imce.findex.length != cnt) {//if new files added, scroll to bottom. 592 $(imce.SBW).animate({scrollTop: imce.SBW.scrollHeight}).focus(); 593 } 594 } 595 if (removed = data.removed) for (i in removed) { 596 imce.fileRemove(removed[i]); 597 } 598 imce.conf.dirsize = data.dirsize; 599 imce.updateStat(); 600 }, 601 602 //set response messages 603 resMsgs: function (msgs) { 604 for (var type in msgs) for (var i in msgs[type]) { 605 imce.setMessage(msgs[type][i], type); 606 } 607 }, 608 609 //return img markup 610 imgHtml: function (fid, width, height) { 611 return '<img src="'+ imce.getURL(fid) +'" width="'+ width +'" height="'+ height +'" alt="'+ imce.decodePlain(fid) +'">'; 612 }, 613 614 //check if the file is an image 615 isImage: function (fid) { 616 return imce.fids[fid].cells[2].innerHTML * 1; 617 }, 618 619 //find the first non-image in the selection 620 getNonImage: function (selected) { 621 for (var fid in selected) { 622 if (!imce.isImage(fid)) return fid; 623 } 624 return false; 625 }, 626 627 //validate current selection for images 628 validateImage: function () { 629 var nonImg = imce.getNonImage(imce.selected); 630 return nonImg ? imce.setMessage(Drupal.t('%filename is not an image.', {'%filename': imce.decode(nonImg)}), 'error') : true; 631 }, 632 633 //validate number of selected files 634 validateSelCount: function (Min, Max) { 635 if (Min && imce.selcount < Min) { 636 return imce.setMessage(Min == 1 ? Drupal.t('Please select a file.') : Drupal.t('You must select at least %num files.', {'%num': Min}), 'error'); 637 } 638 if (Max && Max < imce.selcount) { 639 return imce.setMessage(Drupal.t('You are not allowed to operate on more than %num files.', {'%num': Max}), 'error'); 640 } 641 return true; 642 }, 643 644 //update file count and dir size 645 updateStat: function () { 646 imce.el('file-count').innerHTML = imce.findex.length; 647 imce.el('dir-size').innerHTML = imce.conf.dirsize; 648 }, 649 650 //serialize selected files. return fids with a colon between them 651 serialNames: function () { 652 var str = ''; 653 for (var fid in imce.selected) { 654 str += ':'+ fid; 655 } 656 return str.substr(1); 657 }, 658 659 //get file url. re-encode & and # for mod rewrite 660 getURL: function (fid) { 661 var path = (imce.conf.dir == '.' ? '' : imce.conf.dir +'/') + fid; 662 return imce.conf.furl + (imce.conf.modfix ? path.replace(/%(23|26)/g, '%25$1') : path); 663 }, 664 665 //el. by id 666 el: function (id) { 667 return document.getElementById(id); 668 }, 669 670 //find the latest selected fid 671 lastFid: function () { 672 if (imce.vars.lastfid) return imce.vars.lastfid; 673 for (var fid in imce.selected); 674 return fid; 675 }, 676 677 //create ajax url 678 ajaxURL: function (op, dir) { 679 return imce.conf.url + (imce.conf.clean ? '?' :'&') +'jsop='+ op +'&dir='+ (dir||imce.conf.dir); 680 }, 681 682 //fast class check 683 hasC: function (el, name) { 684 return el.className && (' '+ el.className +' ').indexOf(' '+ name +' ') != -1; 685 }, 686 687 //highlight a single file 688 highlight: function (fid) { 689 if (imce.vars.prvfid) imce.fileClick(imce.vars.prvfid); 690 imce.fileClick(fid); 691 }, 692 693 //process a row 694 processRow: function (row) { 695 row.cells[0].innerHTML = '<span>' + imce.decodePlain(row.id) + '</span>'; 696 row.onmousedown = function(e) { 697 var e = e||window.event; 698 imce.fileClick(this, e.ctrlKey, e.shiftKey); 699 return !(e.ctrlKey || e.shiftKey); 700 }; 701 row.ondblclick = function(e) { 702 imce.send(this.id); 703 return false; 704 }; 705 }, 706 707 //decode urls. uses unescape. can be overridden to use decodeURIComponent 708 decode: function (str) { 709 return unescape(str); 710 }, 711 712 //decode and convert to plain text 713 decodePlain: function (str) { 714 return Drupal.checkPlain(imce.decode(str)); 715 }, 716 717 //global ajax error function 718 ajaxError: function (e, response, settings, thrown) { 719 imce.setMessage(Drupal.ahahError(response, settings.url).replace(/\n/g, '<br />'), 'error'); 720 }, 721 722 //convert button elements to standard input buttons 723 convertButtons: function(form) { 724 $('button:submit', form).each(function(){ 725 $(this).replaceWith('<input type="submit" value="'+ $(this).text() +'" name="'+ this.name +'" class="form-submit" id="'+ this.id +'" />'); 726 }); 727 }, 728 729 //create element 730 newEl: function(name) { 731 return document.createElement(name); 732 }, 733 734 //scroll syncronization for section headers 735 syncScroll: function(scrlEl, fixEl, bottom) { 736 var $fixEl = $(fixEl); 737 var prop = bottom ? 'bottom' : 'top'; 738 var factor = bottom ? -1 : 1; 739 var syncScrl = function(el) { 740 $fixEl.css(prop, factor * el.scrollTop); 741 } 742 $(scrlEl).scroll(function() { 743 var el = this; 744 syncScrl(el); 745 setTimeout(function() { 746 syncScrl(el); 747 }); 748 }); 749 }, 750 751 //get UI ready. provide backward compatibility. 752 updateUI: function() { 753 //file urls. 754 var furl = imce.conf.furl, isabs = furl.indexOf('://') > -1; 755 var absurls = imce.conf.absurls = imce.vars.absurls || imce.conf.absurls; 756 var host = location.host; 757 var baseurl = location.protocol + '//' + host; 758 if (furl.charAt(furl.length - 1) != '/') { 759 furl = imce.conf.furl = furl + '/'; 760 } 761 imce.conf.modfix = imce.conf.clean && furl.indexOf(host + '/system/') > -1; 762 if (absurls && !isabs) { 763 imce.conf.furl = baseurl + furl; 764 } 765 else if (!absurls && isabs && furl.indexOf(baseurl) == 0) { 766 imce.conf.furl = furl.substr(baseurl.length); 767 } 768 //convert button elements to input elements. 769 imce.convertButtons(imce.FW); 770 //ops-list 771 $('#ops-list').removeClass('tabs secondary').addClass('clear-block clearfix'); 772 imce.opCloseLink = $(imce.newEl('a')).attr({id: 'op-close-link', href: '#', title: Drupal.t('Close')}).click(function() { 773 imce.vars.op && imce.opClick(imce.vars.op); 774 return false; 775 }).appendTo('#op-contents')[0]; 776 //navigation-header 777 if (!$('#navigation-header').size()) { 778 $(imce.NW).children('.navigation-text').attr('id', 'navigation-header').wrapInner('<span></span>'); 779 } 780 //log 781 $('#log-prv-wrapper').before($('#log-prv-wrapper > #preview-wrapper')).remove(); 782 $('#log-clearer').remove(); 783 //content resizer 784 $('#content-resizer').remove(); 785 //message-box 786 imce.msgBox = imce.el('message-box') || $(imce.newEl('div')).attr('id', 'message-box').prependTo('#imce-content')[0]; 787 //create help tab 788 var $hbox = $('#help-box'); 789 $hbox.is('a') && $hbox.replaceWith($(imce.newEl('div')).attr('id', 'help-box').append($hbox.children())); 790 imce.hooks.load.push(function() { 791 imce.opAdd({name: 'help', title: $('#help-box-title').remove().text(), content: $('#help-box').show()}); 792 }); 793 //add ie classes 794 $.browser.msie && $('html').addClass('ie') && parseFloat($.browser.version) < 8 && $('html').addClass('ie-7'); 795 // enable box view for file list 796 imce.vars.boxW && imce.boxView(); 797 //scrolling file list 798 imce.syncScroll(imce.SBW, '#file-header-wrapper'); 799 imce.syncScroll(imce.SBW, '#dir-stat', true); 800 //scrolling directory tree 801 imce.syncScroll(imce.NW, '#navigation-header'); 802 } 803 804 }; 805 806 //initiate 807 $(document).ready(imce.initiate).ajaxError(imce.ajaxError); 808 809 })(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |