2

I have a file in my ASP.NET MVC project which depends on Jquery:

// 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() {

Also there's a code that depends on Modernizr library.

How do I use my code, JQuery, Modernizr, and requirejs together?

Thanks!

1 Answer 1

1

Assuming you put all your .js files in a "scripts" subdirectory

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

In 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();
    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

is scripts/main case sensitive?
@brick: AFAIK, neither file name nor folder name are case sensitive in the src attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.