Why can unregisterModules not take a parameter jQuery-Object/DOM-Node as context?

68 views
Skip to first unread message

TJ

unread,
Nov 21, 2012, 8:09:19 AM11/21/12
to terrific...@googlegroups.com
This regards TerrificJS 2.0.1. 

Modules can be added dynamically using registerModules (via sandbox.addModules) which allows a context (jquery object) as a parameter. RegisterModules will find and initialize all modules it finds within the given context.

It would be great if unregisterModules would also take a context. Currently unregisterModules takes an array of module instances. I'm not sure how to get module instances other than using "self" within a module.

Is there an alternative way of unregistering certain instances of certain modules?


Remo Brunschwiler

unread,
Nov 21, 2012, 10:05:58 AM11/21/12
to terrific...@googlegroups.com
Hi TJ

This is a really nice idea! I just added this to the upcoming feature list https://github.com/brunschgi/terrificjs/issues/19

In the meantime you can do this quite easily by yourself. As all registered modules have a dynamically added data-id attribute, you just have to loop through the corresponding DOM part.

Example

var self = this,
     $part = $('.part),
     modules = [];

$('.mod', $part).each(function() {
      var $this = $(this),
            module = self.sandbox.getModuleById($this.data('id'));

      if(module) {
            modules.push(module)
      }

     self.sandbox.removeModules(modules);
});


Hope this helps

Cheers
Remo


TJ

unread,
Nov 21, 2012, 10:23:38 AM11/21/12
to terrific...@googlegroups.com
Hi Remo

Thanks. I forgot about the data-id attribute, otherwise I would have used getModuleById.

I managed to solve my issue another way. Since I was adding the modules dynamically, I knew which modules had been added and saved the array for the removal. For the info, the modules were loaded in an overlay.

Cheers
TJ
Reply all
Reply to author
Forward
0 new messages