Advertisement
jiue123

Load file .js inside file .module config structure (Drupal)

Aug 24th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. Tạo file example_block.js bỏ trong thư mục của bạn.
  2.  
  3. Ở file example_block.module của bạn thêm vào hook_init để tải file js:
  4.  
  5. <?php
  6. function example_block_init() {
  7. drupal_add_js(drupal_get_path('module', 'example_block') . '/example_block.js', 'module', 'header');
  8. }
  9. ?>
  10. -------------------------------------------------- Content file .js
  11. (function ($) {
  12. Drupal.behaviors.exampleModule = function (context) {
  13. // Chặn sự kiện submit
  14. $('form#example_block_form').submit(function () {
  15. // Kiểm tra trạng thái của textfield, nếu đang ẩn thì cho hiện ra và ngược lại
  16. var textBox = $(this).children('input[type="text"]');
  17. if (textBox.is(':hidden')) {
  18. // Đang ẩn, hiện ra lại cho nhập liệu
  19. textBox.show().focus();
  20. } else {
  21. textBox.hide();
  22. // Hiện ra dòng chữ
  23. // ....
  24. }
  25. return false;
  26. });
  27. }
  28. })(jQuery);
  29.  
  30. Link tham khão (https://groups.drupal.org/node/66868)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement