Skip to content

Instantly share code, notes, and snippets.

@jbmoelker
Last active January 15, 2016 19:22
Show Gist options
  • Select an option

  • Save jbmoelker/b8c3c4359db7ca94439f to your computer and use it in GitHub Desktop.

Select an option

Save jbmoelker/b8c3c4359db7ca94439f to your computer and use it in GitHub Desktop.

Revisions

  1. jbmoelker revised this gist May 25, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions bootstrap.js
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,7 @@ define({
    require.config({ shim: shim });

    req(['jquery', component], function ($, value) {
    // return jQuery, just like jQuery's own $.fn methods do
    onload($);
    });
    }
  2. jbmoelker created this gist May 25, 2014.
    21 changes: 21 additions & 0 deletions bootstrap.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    // Create shim for requested bootstrap component and require
    // and return jQuery so you do not have to inject it separately
    // every time you use a bootstrap component.
    define({
    load: function (name, req, onload, config) {
    // Set this path to wherever the bootstrap components live.
    // Contents should match https://github.com/twbs/bootstrap/tree/master/js
    var component = 'path/to/bootstrap/js/'+name;

    var shim = {};
    shim[component] = {
    deps: ['jquery'],
    exports: '$.fn.'+name
    }
    require.config({ shim: shim });

    req(['jquery', component], function ($, value) {
    onload($);
    });
    }
    });
    16 changes: 16 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    <!DOCTYPE html>
    <html>
    <head>
    <link rel="stylesheet" href="path/to/bootstrap.min.css" />
    </head>
    <body class="container">

    <h1>Demo: Load bootstrap tooltip as module using RequireJS plugin.</h1>

    <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Tooltip on top">
    Tooltip on top
    </button>

    <script data-main="index.js" src="path/to/require.js"></script>
    </body>
    </html>
    8 changes: 8 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    // Simply use the bootstrap plugin helper.
    // No need to include jQuery manually.
    define(['bootstrap!tooltip'], function($){
    $('[data-toggle="tooltip"]').tooltip();
    });

    // Note: if bootstrap.js is not in the baseUrl, then first set path:
    // require.config({ paths:{ bootstrap: 'path/to/bootstrap-plugin' }});