diff --git a/lib/client/dom.js b/lib/client/dom.js index 11681c2c..5fe02d2b 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -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 * diff --git a/lib/client/view.js b/lib/client/view.js index a06db111..c4e71dae 100644 --- a/lib/client/view.js +++ b/lib/client/view.js @@ -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(); }