home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (imce_set_inline.js)

This example Drupal source code file (imce_set_inline.js) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

directory, file, function, height, html, if, image, link, php, txt, type, undefined, var, width

The imce_set_inline.js Drupal example source code

// $Id: imce_set_inline.js,v 1.4.2.1 2010/06/02 08:32:34 ufku Exp $

(function($) {

var ii = window.imceInline = {};

ii.initiate = function() {
  $('div.imce-inline-wrapper').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).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);
};

$(document).ready(ii.initiate);

})(jQuery);

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal imce_set_inline.js source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.