Révision 5721e759
Ajouté par Assos Assos il y a presque 10 ans
drupal7/sites/all/modules/token_insert/token_insert_text/token_insert_text.js | ||
---|---|---|
1 |
|
|
1 |
/*jshint strict:true, browser:true, curly:true, eqeqeq:true, expr:true, forin:true, latedef:true, newcap:true, noarg:true, trailing: true, undef:true, unused:true */ |
|
2 |
/*global Drupal:true, jQuery: true*/ |
|
2 | 3 |
/** |
3 | 4 |
* Behavior to add "Insert" buttons. |
4 | 5 |
*/ |
5 |
(function ($) { |
|
6 |
Drupal.behaviors.TokenInsertText = { |
|
7 |
attach: function(context) { |
|
8 |
// Add the click handler to the insert button. |
|
9 |
if(!(typeof(Drupal.settings.token_insert) == 'undefined')){ |
|
10 |
for(var key in Drupal.settings.token_insert.buttons){ |
|
11 |
$("#" + key, context).click(insert); |
|
6 |
(function ($, Drupal) { |
|
7 |
"use strict"; |
|
8 |
Drupal.behaviors.TokenInsertText = { |
|
9 |
attach: function(context) { |
|
10 |
function insert (e){ |
|
11 |
var $self = $(this); |
|
12 |
e.preventDefault(); |
|
13 |
var token = $self.text(); |
|
14 |
var id = $self.closest('.token-insert-text-table').attr('id'); |
|
15 |
$('#' + Drupal.settings.token_insert.tables[id]).insertAtCursor(token); |
|
16 |
} |
|
17 |
function bindInsert(id) { |
|
18 |
$(context).find("#" + key).find('.token-insert-table .token-key').once('token-insert-table', function() { |
|
19 |
var newThis = $('<a href="javascript:void(0);" title="' + Drupal.t('Insert this token into your form') + '">' + $(this).html() + '</a>').click(insert); |
|
20 |
$(this).html(newThis); |
|
21 |
}); |
|
12 | 22 |
} |
13 |
} |
|
14 | 23 |
|
15 |
function insert() { |
|
16 |
var field = $(this).attr('id'); |
|
17 |
var selectbox = field.replace('button', 'select'); |
|
18 |
var content = '[' + $('#' + selectbox ).val() + ']'; |
|
19 |
$('#' + Drupal.settings.token_insert.buttons[field]).insertAtCursor(content); |
|
20 |
return false; |
|
24 |
// Add the click handler to the insert button. |
|
25 |
if (typeof(Drupal.settings.token_insert) !== 'undefined') { |
|
26 |
for (var key in Drupal.settings.token_insert.tables) { |
|
27 |
if (Drupal.settings.token_insert.tables.hasOwnProperty(key)) { |
|
28 |
bindInsert(key, context); |
|
29 |
} |
|
30 |
} |
|
31 |
} |
|
21 | 32 |
} |
22 |
} |
|
23 |
}; |
|
24 |
})(jQuery); |
|
25 |
|
|
33 |
}; |
|
34 |
})(jQuery, Drupal); |
Formats disponibles : Unified diff
Weekly update of contrib modules