Last active
August 29, 2015 14:26
-
-
Save carlosvillu/fb260f62ff8a2c2d934f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BusEvents { | |
on(event, fn){} | |
emit(event, ...data){} | |
} | |
class JQueryBusEvents extends BusEvents{ | |
constructor($=window.jQuery){ | |
super(); | |
this.$doc = $(document); | |
} | |
on(event, fn) { | |
this.$doc.on(event, fn) | |
} | |
emit(event, ...data){ | |
this.$doc.trigger.apply(this.$doc, [event].concat(data)); | |
} | |
} | |
window.bus = new JQueryBusEvents(); | |
////// En la modal | |
window.bus.on('close-modal', function(){/*Aqui cierro la modal*/}); | |
//// En otra parte de tu código | |
$('#button-id').on('click', function(){ | |
window.bus.emit('close-modal'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment