2014-01-10 66 views
0

我試圖讓所有以下腳本從一個js文件加載。如果在body標籤之前插入了所有代碼段,但它們在插入一個js文件時不起作用。定製jquery初始化腳本優化

連接可能是錯誤的,但我對js沒有任何瞭解。我應該怎麼做才能將所有文件放在一個文件中?

// Profile flip 
$('#pm-flip').click(function() { 
    $('#flip-card').toggleClass('rotated'); 
}); 


// TinyScrollBar 
$(document).ready(function() { 
    $('#scrollbar-two').tinyscrollbar(); 
}); 


// popover and tooltip for rel element 
/* Tooltips */ 
$.fn.tooltip && $('[rel="tooltip"]').tooltip(); 
/* Popovers */ 
$.fn.popover && $('[rel="popover"]').popover(); 


// footable table init 
$(function() { 
    /* FooTable */ 
    if ($('.footable').length) $('.footable').footable(); 
}); 

//select picker init 
$('.selectpicker').selectpicker(); 


// Tooltip Btn grp fix 
$('.btn-group [title]').tooltip({ 
    container: 'body' 
}) 

// Twitter plugin 

// ##### Twitter Setting ##### 
// A simple example to get my latest tweet and write to a HTML element with 
// id "tweets". Also automatically hyperlinks URLS and user mentions and 
// hashtags. 
// Change the number below as per your Twitter Widget ID. 
// You need to create your Widget from your twitter account 
// Chnage the number 3 to the number of tweets that you want to display 
twitterFetcher.fetch('3914079076786768776', 'example1', 3, true); 

//Twitter plugin--> 

// Lodaing state for buttons --> 

$('button[data-loading-text]') 
    .click(function() { 
    var btn = $(this) 
    btn.button('loading') 
    setTimeout(function() { 
     btn.button('reset') 
    }, 3000) 
}); 


//ScrollUp 
$(function() { 
    $.scrollUp({ 
     scrollName: 'scrollUp', // Element ID 
     topDistance: '300', // Distance from top before showing element (px) 
     topSpeed: 300, // Speed back to top (ms) 
     animation: 'slide', // Fade, slide, none 
     animationInSpeed: 400, // Animation in speed (ms) 
     animationOutSpeed: 400, // Animation out speed (ms) 
     scrollText: 'Scroll to top', // Text for element 
     activeOverlay: false, // Set CSS color to display scrollUp active point, e.g '#00FFFF' 
    }); 
}); 


// icon switch fix --> 

$('#target-col').on('show hide', function (e) { 
    if ($(e.target).attr("id") != "target-col") return; 
    $('#target-shown').toggleClass('icon-arrow-up icon-arrow-down', 200); 
}); 

// icon switch fix --> 

// Tooltip on a attribute --> 

jQuery(function ($) { 
    $("a").tooltip({ 
     html: true, 
     container: 'body' 
    }); 
}); 


// Tooltip Btn grp fix --> 

$('.btn-group [title]').tooltip({ 
    container: 'body' 
}) 

// Tooltip Btn grp fix --> 
+0

你不應該有任何問題將它們結合在一個單獨的js文件中,然後將這個js插入到標題中,那麼肯定會遇到不同的問題。 – ElliotM

+1

如果您有JavaScript語法問題,請先解決這些問題,然後重試。使用這個工具來突出顯示什麼是錯的。 http://www.javascriptlint.com/online_lint.php – Marko

+1

如果將所有這些組合到一個js文件中,是否將它全部包裝在$(document).ready(function(){})中; ? – mituw16

回答

1

我已經修復了代碼中的所有問題。將以下內容粘貼到文件中,並確保它低於所有其他JavaScript文件,順序非常重要。

$(document).ready(function() { 

      // Profile flip 
      $('#pm-flip').click(function() { 
      $('#flip-card').toggleClass('rotated'); 
      }); 


      // TinyScrollBar 
      $(document).ready(function(){ 
       $('#scrollbar-two').tinyscrollbar(); 
      }); 


      // popover and tooltip for rel element 
      /* Tooltips */ 
      $.fn.tooltip && $('[rel="tooltip"]').tooltip(); 
      /* Popovers */ 
      $.fn.popover && $('[rel="popover"]').popover(); 


      // footable table init 
      $(function() 
      { 
       /* FooTable */ 
       if ($('.footable').length) { 
        $('.footable').footable(); 
       } 
      }); 

      //select picker init 
      $('.selectpicker').selectpicker(); 


      // Tooltip Btn grp fix 
      $('.btn-group [title]').tooltip({ 
       container: 'body' 
      }); 

      // Twitter plugin 

      // ##### Twitter Setting ##### 
      // A simple example to get my latest tweet and write to a HTML element with 
      // id "tweets". Also automatically hyperlinks URLS and user mentions and 
      // hashtags. 
      // Change the number below as per your Twitter Widget ID. 
      // You need to create your Widget from your twitter account 
      // Chnage the number 3 to the number of tweets that you want to display 
       twitterFetcher.fetch('3914079076786768776', 'example1', 3, true); 

      //Twitter plugin--> 

      // Lodaing state for buttons --> 

      $('button[data-loading-text]').click(function() { 
        var btn = $(this); 
        btn.button('loading'); 
        setTimeout(function() { 
         btn.button('reset'); 
        }, 3000); 
       }); 


      //ScrollUp 
      $(function() { 
      $.scrollUp({ 
      scrollName: 'scrollUp', // Element ID 
      topDistance: '300', // Distance from top before showing element (px) 
      topSpeed: 300, // Speed back to top (ms) 
      animation: 'slide', // Fade, slide, none 
      animationInSpeed: 400, // Animation in speed (ms) 
      animationOutSpeed: 400, // Animation out speed (ms) 
      scrollText: 'Scroll to top', // Text for element 
      activeOverlay: false // Set CSS color to display scrollUp active point, e.g '#00FFFF' 
      }); 
      }); 


      // icon switch fix --> 

      $('#target-col').on('show hide', function (e) { 
       if($(e.target).attr("id") != "target-col") { 
        return; 
       } 

       $('#target-shown').toggleClass('icon-arrow-up icon-arrow-down', 200); 
      }); 

      // icon switch fix --> 

      // Tooltip on a attribute --> 

       jQuery(function ($) { 
        $("a").tooltip({ html : true, container: 'body'}); 
       }); 


      // Tooltip Btn grp fix --> 

      $('.btn-group [title]').tooltip({ 
       container: 'body' 
      }); 

      // Tooltip Btn grp fix --> 

}); 
0

你在代碼中有一些語法錯誤。先解決這些問題,你最好改變這一部分:

$.fn.tooltip && $('[rel="tooltip"]').tooltip(); 

而且這樣的:

$.fn.popover && $('[rel="popover"]').popover(); 

他們大概應該是這樣的:

if($.fn.tooltip) $('[rel="tooltip"]').tooltip(); 
if($.fn.popover) $('[rel="popover"]').popover(); 

你有其他的問題是這部分:

animationOutSpeed: 400, // Animation out speed (ms) 
scrollText: 'Scroll to top', // Text for element 
activeOverlay: false, 

cha nge它到

animationOutSpeed: 400, // Animation out speed (ms) 
scrollText: 'Scroll to top', // Text for element 
activeOverlay: false 

我剛剛刪除了代碼中的最後一個額外','它的工作。