Skip to content

Commit

Permalink
Merge pull request mozilla-b2g#7527 from davidflanagan/bug828963
Browse files Browse the repository at this point in the history
Bug 828936 - make video deletion work r=daleharvey a=blocking+
  • Loading branch information
daleharvey committed Jan 10, 2013
2 parents c8c7f69 + 35fbf72 commit 7485a3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
6 changes: 1 addition & 5 deletions apps/video/index.html
Expand Up @@ -12,12 +12,8 @@

<div id="throbber"><div></div></div>

<menu type="context" id="thumbnail-menu">
<menuitem label="Delete Video" data-l10n-id="delete-video" id="delete-confirmation-button"></menuitem>
</menu>

<!-- title bar + thumbnail list -->
<ul id="thumbnails" contextmenu="thumbnail-menu"></ul>
<ul id="thumbnails"></ul>

<!-- 'fullscreen' (maximized) video player -->
<div id="videoFrame" class="hidden">
Expand Down
47 changes: 20 additions & 27 deletions apps/video/js/video.js
Expand Up @@ -6,8 +6,7 @@ var ids = ['player', 'thumbnails', 'overlay', 'overlay-title',
'overlay-text', 'videoControls', 'videoFrame', 'videoBar',
'close', 'play', 'playHead', 'timeSlider', 'elapsedTime',
'video-title', 'duration-text', 'elapsed-text', 'bufferedTime',
'slider-wrapper', 'throbber', 'delete-video-button',
'delete-confirmation-button'];
'slider-wrapper', 'throbber', 'delete-video-button'];

ids.forEach(function createElementRef(name) {
dom[toCamelCase(name)] = document.getElementById(name);
Expand All @@ -20,8 +19,7 @@ var playing = false;
// if this is true then the video tag is showing
// if false, then the gallery is showing
var playerShowing = false;
var ctxTriggered = false;
var selectedVideo;
var ctxTriggered = false; // Workaround for bug 766813

// keep the screen on when playing
var screenLock;
Expand Down Expand Up @@ -82,8 +80,14 @@ function init() {
event.detail.forEach(videoDeleted);
};

dom.deleteConfirmationButton.addEventListener('click',
deleteSelectedVideoFile, false);
// We can't do this in the mouse down handler below because
// calling confirm() from the mousedown generates a contextmenu
// event when the alert goes away.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=829214
dom.deleteVideoButton.onclick = function() {
document.mozCancelFullScreen();
deleteFile(currentVideo.name);
};
}

function videoAdded(videodata) {
Expand Down Expand Up @@ -130,10 +134,11 @@ function videoAdded(videodata) {
thumbnail.appendChild(hr);

thumbnail.addEventListener('click', function(e) {
selectedVideo = videodata.name;
});

thumbnail.addEventListener('click', function(e) {
// When the user presses and holds to delete a video, we get a
// contextmenu event, but still apparently get a click event after
// they lift their finger. This ctxTriggered flag prevents us from
// playing a video after a contextmenu event.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=766813
if (!ctxTriggered) {
showPlayer(videodata, true);
} else {
Expand All @@ -145,29 +150,20 @@ function videoAdded(videodata) {

dom.thumbnails.addEventListener('contextmenu', function(evt) {
var node = evt.target;
var found = false;
while (!found && node) {
while (node) {
if (node.dataset.name) {
found = true;
selectedVideo = node.dataset.name;
} else {
node = node.parentNode;
ctxTriggered = true;
deleteFile(node.dataset.name);
return;
}
node = node.parentNode;
}
ctxTriggered = true;
});

function deleteSelectedVideoFile() {
if (selectedVideo) {
deleteFile(selectedVideo);
}
}

function deleteFile(file) {
var msg = navigator.mozL10n.get('confirm-delete');
if (confirm(msg + ' ' + file)) {
videodb.deleteFile(file);
selectedVideo = null;
}
}

Expand Down Expand Up @@ -377,9 +373,6 @@ function playerMousedown(event) {
document.mozCancelFullScreen();
} else if (event.target == dom.sliderWrapper) {
dragSlider(event);
} else if (event.target == dom.deleteVideoButton) {
document.mozCancelFullScreen();
deleteFile(currentVideo.name);
} else {
setControlsVisibility(false);
}
Expand Down

0 comments on commit 7485a3d

Please sign in to comment.