[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/imce/js/ -> imce_set_inline.js (source)

   1  // $Id: imce_set_inline.js,v 1.4.2.1 2010/06/02 08:32:34 ufku Exp $
   2  
   3  (function($) {
   4  
   5  var ii = window.imceInline = {};
   6  
   7  ii.initiate = function() {
   8    $('div.imce-inline-wrapper').show().find('a').click(function() {
   9      var i = this.name.indexOf('-IMCE-');
  10      ii.activeTextarea = $('#'+ this.name.substr(0, i)).get(0);
  11      ii.activeType = this.name.substr(i+6);
  12   
  13      if (typeof ii.pop == 'undefined' || ii.pop.closed) {
  14        ii.pop = window.open(this.href + (this.href.indexOf('?') < 0 ? '?' : '&') +'app=nomatter|imceload@imceInline.load', '', 'width='+ 760 +',height='+ 560 +',resizable=1');
  15      }
  16  
  17      ii.pop.focus();
  18      return false;
  19    });
  20  };
  21  
  22  //function to be executed when imce loads.
  23  ii.load = function(win) {
  24    win.imce.setSendTo(Drupal.t('Insert file'), ii.insert);
  25    $(window).unload(function() {
  26      if (ii.pop && !ii.pop.closed) ii.pop.close();
  27    });
  28  };
  29  
  30  //insert html at cursor position
  31  ii.insertAtCursor = function (field, txt, type) {
  32    field.focus();
  33    if ('undefined' != typeof(field.selectionStart)) {
  34      if (type == 'link' && (field.selectionEnd-field.selectionStart)) {
  35        txt = txt.split('">')[0] +'">'+ field.value.substring(field.selectionStart, field.selectionEnd) +'</a>';
  36      }
  37      field.value = field.value.substring(0, field.selectionStart) + txt + field.value.substring(field.selectionEnd, field.value.length);
  38    }
  39    else if (document.selection) {
  40      if (type == 'link' && document.selection.createRange().text.length) {
  41        txt = txt.split('">')[0] +'">'+ document.selection.createRange().text +'</a>';
  42      }
  43      document.selection.createRange().text = txt;
  44    }
  45    else {
  46      field.value += txt;
  47    }
  48  };
  49  
  50  //sendTo function
  51  ii.insert = function (file, win) {
  52    var type = ii.activeType == 'link' ? 'link' : (file.width ? 'image' : 'link');
  53    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>');
  54    ii.activeType = null;
  55    win.blur();
  56    ii.insertAtCursor(ii.activeTextarea, html, type);
  57  };
  58  
  59  $(document).ready(ii.initiate);
  60  
  61  })(jQuery);


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7