1

I am trying to use a tooltip plugin called tipso. And I am using angular along with browserify as my dependency manager.

I have everything working out for me except for this plugin. Every little thing is little harder in browserify but this one seems to be turning into a nightmare.

I have followed the documentation of tipso which is pretty simple. But when I run the app, I keep getting an error message stating that Uncaught TypeError: $(...).tipso is not a function in the chrome console.

This is my broserify-shim config

   "browserify-shim": {
   "jquery": "$",
   "bootstrap": {
     "depends": [
       "jquery"
     ]
   },
   "tipso": {
       "depends": [
           "bootstrap"
       ]
    }
  }

I have required tipso

var tipso = require('tipso');

This is how I have initialized tipso

//runs when DOM is completely loaded
angular.element(document).ready(function ($http, $rootScope) {    
    $('.tipso').tipso();
});

Any suggestion will be appreciated.

2 Answers 2

1

I finally figured it out, I hope this helps someone.

  1. The trick is to expose jQuery in the global scope (I know I am not supposed to do this and the alternative for this is to expose it wherever I want the plugin to work).

    global.$ = global.jQuery = require('jquery');
    
  2. Once that is done, we'll make an Angular directive

    rootModule.directive('cooltip', function () {
      return {
          restrict: 'A',
          link: function (scope, element, attributes) {
              $(element).tipso({
                  position: 'right',
                  delay: 600
            });
          }
       };
    });
    
  3. Use this directive to use apply the jQuery plugin's properties on an element in html

    <button cooltip class="btn"> Hover over me </button>
    

Depending on the jQuery plugin and it;s funtionality decide on the directive type (Element, Attribute, Comment etc).

Sign up to request clarification or add additional context in comments.

Comments

0

If you're using it like $(...).tipso per the error, and you're requiring jQuery as $ per your Browserify Shim config, I'm assuming Tipso is a jQuery plugin. You need to specify that this it depends on jQuery, like so:

 "browserify-shim": {
   "jquery": "$",
   "bootstrap": {
     "depends": [
       "jquery"
     ]
   },
   "tipso": {
       "depends": [
           "jquery",
           "bootstrap"
       ],
    "exports": "$.fn.tipso"
    }
  }

4 Comments

Same thing, as mentioned in the question, the global namespace is not polluted, I checked by typing in $ in chrome console.
Try explicitly exporting the plugin per my update. I have one more idea if that doesn't work. Sometimes these are a little touchy which is a terrible way to think as a programmer but I don't know Browserify Shim yet well enough to know a better solution offhand :).
If you want to pollute your global namespace you need to do that explicitly in your build, like window.$ = require('jquery'); require('tipso');
I am totally surprised and slightly scared that about the no of views a question gets on stack overflow these days...

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.