Thứ Ba, 15 tháng 7, 2014

Sửa lỗi Uncaught TypeError: undefined is not a function trong module views_accordion

Để sửa lỗi Drupal jQuery Plugins của module views_accordion không hoạt động do lỗi báo ở dòng lệnh "$(displaySelector +':not(.ui-accordion)').accordion({" trong file views_accordion.js. Lỗi cụ thể là "Uncaught TypeError: undefined is not a function" trong file views_accordion.js Bạn hãy làm như sau: 
-Drupal.behaviors.views_accordion = {
-  attach: function(context) {
-    if(Drupal.settings.views_accordion){
-      (function ($) {
+(function ($) {
+  Drupal.behaviors.views_accordion = {
+    attach: function(context) {
+      if(Drupal.settings.views_accordion){
         $.each(Drupal.settings.views_accordion, function(id) {
           /* Our view settings */
           var usegroupheader = this.usegroupheader;
@@ -17,7 +17,7 @@ Drupal.behaviors.views_accordion = {

           /* Prepare our markup for jquery ui accordion */
           $(displaySelector + ' ' + headerSelector + ':not(.ui-accordion-header)').each(function(i){
          // Hash to use for accordion navigation option.
             var hash = "#" + viewname + "-" + display + "-" + i;
             var $this = $(this);
             var $link = $this.find('a');
@@ -54,7 +54,7 @@ Drupal.behaviors.views_accordion = {
               clearstyle: this.clearstyle
           });
         });
-      })(jQuery);
+      }
     }
-  }
-};
+  };
+})(jQuery);

File cuối cùng sẽ chạy được là:


(function ($) {
Drupal.behaviors.views_accordion =  {
  attach: function(context) {
    if(Drupal.settings.views_accordion){
        $.each(Drupal.settings.views_accordion, function(id) {
          /* Our view settings */
          var usegroupheader = this.usegroupheader;
          var viewname = this.viewname;
          var display = this.display;
           /* the selectors we have to play with */
          var displaySelector = '.view-id-'+ viewname +'.view-display-id-'+ display +' .view-content';
          var headerSelector = this.header;

          /* Prepare our markup for jquery ui accordion */
          $(displaySelector +' '+ headerSelector +':not(.ui-accordion-header)').each(function(i){
            // hash to use for accordion navigation option
var hash = "#"+ viewname +"-"+ display +"-"+ i;
            var $this = $(this);
            var $link = $this.find('a');
            // if the header is not already using an anchor tag, add one
            if($link.length == 0){
              // setup anchor tag for navigation
              $this.wrapInner('<a href="'+hash+'"></a>');
            }
            // if there are already, they wont be clickable with js enabled, we'll use them for accordion navigation
            else{
              // @FIXME ?
              // We are currently destroying the original link, though search crawlers will stil see it.
              // Links in accordions are NOT clickable and leaving them would kill deep linking.
              $link.get(0).href = hash;
            }
            // Wrap the accordion content within a div if necessary
            if (!usegroupheader) {
              $this.siblings().wrapAll('<div></div>');
            }
          });
          /* jQuery UI accordion call */
          $(displaySelector +':not(.ui-accordion)').accordion({
              header: headerSelector,
              animated: this.animated,
              active: this.rowstartopen,
              collapsible: this.collapsible,
              autoHeight: this.autoheight,
              event: this.event,
              fillSpace: this.fillspace,
              navigation: this.navigation,
              clearstyle: this.clearstyle
          });
        });
}
  }
};
})(jQuery);

Không có nhận xét nào:

Đăng nhận xét