Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added utils.events.dispatch #62

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reverted from CustomEvent to standard Event
Reverted from CustomEvent to standard Event for IE compatibility as
well as simplicity.  There was a bug in the properties I passed as
well, but I’m not going to get into it and I wasn’t able to properly
pass custom event details for some reason anyways. This works just fine.
MistahWrite committed Mar 15, 2015
commit 75709726fe700ceb143aa0cfb40751ac1317e10a
29 changes: 7 additions & 22 deletions demo/bar-ui/script/bar-ui.js
Original file line number Diff line number Diff line change
@@ -294,25 +294,9 @@

var dispatch, add, remove, preventDefault;

dispatch = function(evtName, custom) {
custom = typeof custom !== 'undefined' ? custom : null;

//how we can use dispatch inside bar-ui.js:
// utils.events.dispatch('sm2-bar-ui-select', { 'detail': 0 });
//
//how to listen for events in an external script:
// function evtHandler(e) {
// log('The value is: ' + e.detail);
// }
// var evtName = 'sm2-bar-ui-setTitle';
// if (window.addEventListener) {
// window.addEventListener(evtName, evtHandler, false);
// } else {
// window.attachEvent('on' + evtName, evtHandler);
// }

// create new event with the name we give
var event = new CustomEvent(evtName, custom);
dispatch = function(evtName) {
// create new event with the name we give
var event = new Event(evtName);

// Dispatch the event.
return window.dispatchEvent(event);
@@ -783,7 +767,7 @@
// if this is an <li> with an inner link, grab and use the text from that.
var links = item.getElementsByTagName('a');

utils.events.dispatch('sm2-bar-ui-setTitle', {'item': item});
utils.events.dispatch('sm2-bar-ui-setTitle');

if (links.length) {
item = links[0];
@@ -796,7 +780,6 @@
// this item can use <marquee>, in fact.
dom.playlistTarget.innerHTML = '<ul class="sm2-playlist-bd"><li><marquee>' + item.innerHTML + '</marquee></li></ul>';
}

}

function makeSound(url) {
@@ -1391,6 +1374,8 @@
// playlist
dom.playlistContainer.style.height = (isOpen ? dom.playlistContainer.scrollHeight : 0) + 'px';

utils.events.dispatch('sm2-bar-ui-menu');

},

adjustVolume: function(e) {
@@ -1504,4 +1489,4 @@
window.sm2BarPlayers = players;
window.SM2BarPlayer = Player;

}(window));
}(window));