views_php.js 913 B

12345678910111213141516171819202122232425262728293031
  1. (function ($) {
  2. /**
  3. * Attach views php clickable variables behavior.
  4. */
  5. Drupal.behaviors.viewsPHPVariables = {
  6. attach: function (context) {
  7. $('.views-php-variables', context).delegate('a', 'click', function() {
  8. var textarea = $(this.href.replace(/^.*#/, '#'))[0];
  9. var text = $(this).text();
  10. textarea.focus();
  11. if (!isNaN(textarea.selectionStart)) {
  12. textarea.value = textarea.value.substring(0, textarea.selectionStart) + text + textarea.value.substring(textarea.selectionEnd);
  13. textarea.selectionStart = textarea.selectionStart + text.length;
  14. textarea.selectionEnd = textarea.selectionEnd + text.length;
  15. }
  16. // IE support.
  17. else if (document.selection) {
  18. document.selection.createRange().text = text;
  19. }
  20. else {
  21. textarea.value += text;
  22. }
  23. textarea.focus();
  24. return false;
  25. });
  26. }
  27. };
  28. })(jQuery);