2012-08-23 30 views
2

我在我的ASP.NET MVC項目中的文件,這取決於Jquery如何整合requirejs?

// namespace pattern 
var diem = diem || {}; 
diem .defineNamespace = function(ns_string) { 
    var parts = ns_string.split('.'); 
    var parent = diem ; 
    var i; 

    if(parts[0] === "diem ") { 
     parts = parts.slice(1); 
    } 

    for(i = 0; i < parts.length; i += 1) {  
     if(typeof parent[parts[i]] === "undefined") { 
      parent[parts[i]] = {}; 
      parent = parent[parts[i]]; 
     } 
     return parent; 
    } 
}; 

diem.defineNamespace('diem.utils'); 

// module pattern 
diem.utils = (function() { 
    // private API 
    // ... 
    // public API 
    return { 
     handleFileInputs: function(container) { 
      $(container + ' ' + 'input[type="image"]').click(function(e) { 
       // prevent from submission 
       e.preventDefault(); 
       // handle add/remove items 
       if($(this).hasClass('add')) { 
        $(this).parent().append('<p><input type="file" accept="image/jpeg,image/png,image/gif" name="files" /></p>'); 
       } else { 
        $(this).parent().find('p:last-child').remove(); 
       } // if($(this).hasClass('add')) { 
      }); 
     }, // handleFileAttachments: function() { 
     handleLabelWidths: function(container) { 
      var max = 0; 
      $(container + ' ' + 'label.autoWidth').each(function() { 
       if($(this).width() > max) { 
        max = $(this).width(); 
       } 
      }); 
      $(container + ' ' + 'label.autoWidth').width(max + 5); 
     } // handleLabelWidths: function(container) { 
    } // return { 
})(); // streamlined.utils = (function() { 

也有依賴於Modernizr庫中的代碼。

如何將我的代碼JQuery,Modernizrrequirejs一起使用?

謝謝!

回答

1

假設你把你所有的.js文件的 「腳本」 子目錄

<script data-main="scripts/main.js" src="scripts/require-jquery.js"></script> 

main.js

require(["jquery", "jquery.alpha", "jquery.beta"], function($) { 
    //the jquery.alpha.js and jquery.beta.js plugins have been loaded. 
    $(function() { 
     $('body').alpha().beta(); 
    }); 
}); 
+0

是'腳本/ main'區分大小寫? – lexeme

+1

@brick:AFAIK,'src'屬性中的文件名和文件夾名都不區分大小寫。 –