Projet

Général

Profil

Paste
Télécharger (2,09 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / imce / js / imce_set_inline.js @ 6eb8d15f

1
(function($) {
2

    
3
var ii = window.imceInline = {};
4

    
5
// Drupal behavior
6
Drupal.behaviors.imceInline = {attach: function(context, settings) {
7
  $('div.imce-inline-wrapper', context).not('.processed').addClass('processed').show().find('a').click(function() {
8
    var i = this.name.indexOf('-IMCE-');
9
    ii.activeTextarea = $('#'+ this.name.substr(0, i)).get(0);
10
    ii.activeType = this.name.substr(i+6);
11
 
12
    if (typeof ii.pop == 'undefined' || ii.pop.closed) {
13
      ii.pop = window.open(this.href + (this.href.indexOf('?') < 0 ? '?' : '&') +'app=nomatter|imceload@imceInline.load', '', 'width='+ 760 +',height='+ 560 +',resizable=1');
14
    }
15

    
16
    ii.pop.focus();
17
    return false;
18
  });
19
}};
20

    
21
//function to be executed when imce loads.
22
ii.load = function(win) {
23
  win.imce.setSendTo(Drupal.t('Insert file'), ii.insert);
24
  $(window).bind('unload', function() {
25
    if (ii.pop && !ii.pop.closed) ii.pop.close();
26
  });
27
};
28

    
29
//insert html at cursor position
30
ii.insertAtCursor = function (field, txt, type) {
31
  field.focus();
32
  if ('undefined' != typeof(field.selectionStart)) {
33
    if (type == 'link' && (field.selectionEnd-field.selectionStart)) {
34
      txt = txt.split('">')[0] +'">'+ field.value.substring(field.selectionStart, field.selectionEnd) +'</a>';
35
    }
36
    field.value = field.value.substring(0, field.selectionStart) + txt + field.value.substring(field.selectionEnd, field.value.length);
37
  }
38
  else if (document.selection) {
39
    if (type == 'link' && document.selection.createRange().text.length) {
40
      txt = txt.split('">')[0] +'">'+ document.selection.createRange().text +'</a>';
41
    }
42
    document.selection.createRange().text = txt;
43
  }
44
  else {
45
    field.value += txt;
46
  }
47
};
48

    
49
//sendTo function
50
ii.insert = function (file, win) {
51
  var type = ii.activeType == 'link' ? 'link' : (file.width ? 'image' : 'link');
52
  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>');
53
  ii.activeType = null;
54
  win.blur();
55
  ii.insertAtCursor(ii.activeTextarea, html, type);
56
};
57

    
58
})(jQuery);