mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(view) add pause/start of music on SPACE pressed
This commit is contained in:
parent
b885223d12
commit
802b80432c
2 changed files with 31 additions and 4 deletions
|
|
@ -414,6 +414,16 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
return this.add('keydown', pListener, pElement, pUseCapture);
|
||||
};
|
||||
|
||||
/**
|
||||
* safe remove event click listener
|
||||
*
|
||||
* @param pListener
|
||||
* @param pUseCapture
|
||||
*/
|
||||
this.rmKey = function(pListener, pElement, pUseCapture) {
|
||||
return this.remove('keydown', pListener, pElement, pUseCapture);
|
||||
};
|
||||
|
||||
/**
|
||||
* safe add event click listener
|
||||
*
|
||||
|
|
|
|||
|
|
@ -94,12 +94,19 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
$.fancybox.open(path, config);
|
||||
} else if (isMusic(path))
|
||||
getMusicElement(path, function(element) {
|
||||
var audio = element.querySelector('audio'),
|
||||
onKey = Util.bind(onMusicKey, audio);
|
||||
|
||||
$.fancybox.open(element, {
|
||||
beforeShow : function() {
|
||||
Config.beforeShow();
|
||||
musicBeforeShow();
|
||||
Events.addKey(onKey);
|
||||
},
|
||||
beforeClose : Config.beforeClose
|
||||
beforeClose : function() {
|
||||
Config.beforeClose();
|
||||
Events.rmKey(onKey);
|
||||
}
|
||||
});
|
||||
});
|
||||
else
|
||||
|
|
@ -148,19 +155,29 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
name: Info.name
|
||||
});
|
||||
|
||||
element = $(rendered);
|
||||
|
||||
element = $(rendered)[0];
|
||||
Util.exec(callback, element);
|
||||
});
|
||||
}
|
||||
|
||||
function onMusicKey(audio, event) {
|
||||
var key = event.keyCode;
|
||||
|
||||
if (key === Key.SPACE) {
|
||||
if (audio.paused)
|
||||
audio.play();
|
||||
else
|
||||
audio.pause();
|
||||
}
|
||||
}
|
||||
|
||||
function musicBeforeShow() {
|
||||
var audioDiv = $('#js-audio'),
|
||||
audio = audioDiv.find('audio'),
|
||||
width = audio.width() +'px';
|
||||
|
||||
audioDiv.width(width);
|
||||
|
||||
|
||||
Images.hideLoad();
|
||||
Key.unsetBind();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue