1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update jquery mobile to use normal browser events

This commit is contained in:
Luke Pulverenti 2015-11-29 16:44:09 -05:00
parent 905a6c819e
commit 404073e540
7 changed files with 69 additions and 75 deletions

View file

@ -39,6 +39,6 @@
"commit": "cec8e49744a1e18b14a711eea77e201bb70de544" "commit": "cec8e49744a1e18b14a711eea77e201bb70de544"
}, },
"_source": "git://github.com/desandro/doc-ready.git", "_source": "git://github.com/desandro/doc-ready.git",
"_target": "~1.0.4", "_target": "1.0.x",
"_originalSource": "doc-ready" "_originalSource": "doc-ready"
} }

View file

@ -30,6 +30,6 @@
"commit": "14d2ca3df97da64c820829a8310f9198fbafbcfa" "commit": "14d2ca3df97da64c820829a8310f9198fbafbcfa"
}, },
"_source": "git://github.com/desandro/eventie.git", "_source": "git://github.com/desandro/eventie.git",
"_target": "^1", "_target": "~1.0.3",
"_originalSource": "eventie" "_originalSource": "eventie"
} }

View file

@ -26,14 +26,14 @@
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0" "webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
}, },
"main": "iron-meta.html", "main": "iron-meta.html",
"homepage": "https://github.com/PolymerElements/iron-meta", "homepage": "https://github.com/polymerelements/iron-meta",
"_release": "1.1.1", "_release": "1.1.1",
"_resolution": { "_resolution": {
"type": "version", "type": "version",
"tag": "v1.1.1", "tag": "v1.1.1",
"commit": "e171ee234b482219c9514e6f9551df48ef48bd9f" "commit": "e171ee234b482219c9514e6f9551df48ef48bd9f"
}, },
"_source": "git://github.com/PolymerElements/iron-meta.git", "_source": "git://github.com/polymerelements/iron-meta.git",
"_target": "^1.0.0", "_target": "^1.0.0",
"_originalSource": "PolymerElements/iron-meta" "_originalSource": "polymerelements/iron-meta"
} }

View file

@ -9,6 +9,21 @@
} else { } else {
elem.setAttribute("src", url); elem.setAttribute("src", url);
} }
if (browserInfo.chrome && !browserInfo.mobile) {
if (!elem.classList.contains('noFade')) {
fadeIn(elem, 1);
}
}
}
function fadeIn(elem, iterations) {
var keyframes = [
{ opacity: '0', offset: 0 },
{ opacity: '1', offset: 1 }];
var timing = { duration: 200, iterations: iterations };
return elem.animate(keyframes, timing);
} }
// Request Quota (only for File System API) // Request Quota (only for File System API)

View file

@ -2,9 +2,9 @@
function paperDialogHashHandler(dlg, hash, lockDocumentScroll) { function paperDialogHashHandler(dlg, hash, lockDocumentScroll) {
function onHashChange(e, data) { function onHashChange(e) {
data = data.state; var data = e.detail.state || {};
var isActive = data.hash == '#' + hash; var isActive = data.hash == '#' + hash;
if (data.direction == 'back') { if (data.direction == 'back') {
@ -25,7 +25,7 @@
dlg = null; dlg = null;
if (enableHashChange()) { if (enableHashChange()) {
$(window).off('navigate', onHashChange); window.removeEventListener('navigate', onHashChange);
if (window.location.hash == '#' + hash) { if (window.location.hash == '#' + hash) {
history.back(); history.back();
@ -33,9 +33,7 @@
} }
} }
var self = this; dlg.addEventListener('iron-overlay-closed', onDialogClosed);
$(dlg).on('iron-overlay-closed', onDialogClosed);
dlg.open(); dlg.open();
if (lockDocumentScroll !== false) { if (lockDocumentScroll !== false) {
@ -46,7 +44,7 @@
window.location.hash = hash; window.location.hash = hash;
$(window).on('navigate', onHashChange); window.addEventListener('navigate', onHashChange);
} }
} }

View file

@ -973,9 +973,12 @@
var isCurrentNavBack = false; var isCurrentNavBack = false;
$(window).on("navigate", function (e, data) { window.addEventListener("navigate", function (e) {
data = data.state || {};
isCurrentNavBack = data.direction == 'back'; var data = e.detail.state || {};
var direction = data.direction;
isCurrentNavBack = direction == 'back';
}); });
function isBack() { function isBack() {

View file

@ -91,62 +91,31 @@
$.event.special.navigate = self = { $.event.special.navigate = self = {
bound: false, bound: false,
originalEventName: undefined,
// TODO a lot of duplication between popstate and hashchange // TODO a lot of duplication between popstate and hashchange
popstate: function (event) { popstate: function (event) {
var newEvent = new $.Event("navigate"), var state = event.state || {};
state = event.originalEvent.state || {};
if (event.historyState) {
$.extend(state, event.historyState);
}
// Make sure the original event is tracked for the end
// user to inspect incase they want to do something special
newEvent.originalEvent = event;
// NOTE we let the current stack unwind because any assignment to // NOTE we let the current stack unwind because any assignment to
// location.hash will stop the world and run this event handler. By // location.hash will stop the world and run this event handler. By
// doing this we create a similar behavior to hashchange on hash // doing this we create a similar behavior to hashchange on hash
// assignment // assignment
setTimeout(function () { setTimeout(function () {
$win.trigger(newEvent, {
state: state
});
}, 0);
},
hashchange: function (event /*, data */) { if (event.historyState) {
$.extend(state, event.historyState);
// Trigger the hashchange with state provided by the user
// that altered the hash
window.dispatchEvent(new CustomEvent("navigate", {
detail: {
// Users that want to fully normalize the two events
// will need to do history management down the stack and
// add the state to the event before this binding is fired
// TODO consider allowing for the explicit addition of callbacks
// to be fired before this value is set to avoid event timing issues
state: event.hashchangeState || {}
} }
}));
},
// TODO We really only want to set this up once window.dispatchEvent(new CustomEvent("navigate", {
// but I'm not clear if there's a beter way to achieve detail: {
// this with the jQuery special event structure state: state,
setup: function ( /* data, namespaces */) { originalEvent: event
if (self.bound) { }
return; }));
} }, 0);
self.bound = true;
self.originalEventName = "popstate";
$win.bind("popstate.navigate", self.popstate);
} }
}; };
window.addEventListener('popstate', self.popstate);
})(jQuery); })(jQuery);
jQuery.mobile.widgets = {}; jQuery.mobile.widgets = {};
@ -699,9 +668,7 @@
this.history = history; this.history = history;
this.ignoreInitialHashChange = true; this.ignoreInitialHashChange = true;
$(window).bind({ window.addEventListener('popstate', $.proxy(this.popstate, this));
"popstate.history": $.proxy(this.popstate, this)
});
}; };
$.extend($.mobile.Navigator.prototype, { $.extend($.mobile.Navigator.prototype, {
@ -802,12 +769,6 @@
title: document.title title: document.title
}, data); }, data);
popstateEvent = new $.Event("popstate");
popstateEvent.originalEvent = {
type: "popstate",
state: null
};
this.squash(url, state); this.squash(url, state);
// Trigger a new faux popstate event to replace the one that we // Trigger a new faux popstate event to replace the one that we
@ -815,7 +776,14 @@
if (!noEvents) { if (!noEvents) {
this.ignorePopState = true; this.ignorePopState = true;
//$(window).trigger(popstateEvent); //$(window).trigger(popstateEvent);
window.dispatchEvent(new CustomEvent(popstateEvent, {})); window.dispatchEvent(new CustomEvent("popstate", {
detail: {
originalEvent: {
type: "popstate",
state: null
}
}
}));
} }
// record the history entry so that the information can be included // record the history entry so that the information can be included
@ -849,12 +817,14 @@
return; return;
} }
var originalEventState = event.state || (event.detail ? event.detail.originalEvent.state : event.state);
// If there is no state, and the history stack length is one were // If there is no state, and the history stack length is one were
// probably getting the page load popstate fired by browsers like chrome // probably getting the page load popstate fired by browsers like chrome
// avoid it and set the one time flag to false. // avoid it and set the one time flag to false.
// TODO: Do we really need all these conditions? Comparing location hrefs // TODO: Do we really need all these conditions? Comparing location hrefs
// should be sufficient. // should be sufficient.
if (!event.originalEvent.state && if (!originalEventState &&
this.history.stack.length === 1 && this.history.stack.length === 1 &&
this.ignoreInitialHashChange) { this.ignoreInitialHashChange) {
this.ignoreInitialHashChange = false; this.ignoreInitialHashChange = false;
@ -872,7 +842,7 @@
// TODO it might be better to only add to the history stack // TODO it might be better to only add to the history stack
// when the hash is adjacent to the active history entry // when the hash is adjacent to the active history entry
hash = path.parseLocation().hash; hash = path.parseLocation().hash;
if (!event.originalEvent.state && hash) { if (!originalEventState && hash) {
// squash the hash that's been assigned on the URL with replaceState // squash the hash that's been assigned on the URL with replaceState
// also grab the resulting state object for storage // also grab the resulting state object for storage
state = this.squash(hash); state = this.squash(hash);
@ -893,11 +863,12 @@
// If all else fails this is a popstate that comes from the back or forward buttons // If all else fails this is a popstate that comes from the back or forward buttons
// make sure to set the state of our history stack properly, and record the directionality // make sure to set the state of our history stack properly, and record the directionality
this.history.direct({ this.history.direct({
url: (event.originalEvent.state || {}).url || hash, url: (originalEventState || {}).url || hash,
// When the url is either forward or backward in history include the entry // When the url is either forward or backward in history include the entry
// as data on the event object for merging as data in the navigate event // as data on the event object for merging as data in the navigate event
present: function (historyEntry, direction) { present: function (historyEntry, direction) {
// make sure to create a new object to pass down as the navigate event data // make sure to create a new object to pass down as the navigate event data
event.historyState = $.extend({}, historyEntry); event.historyState = $.extend({}, historyEntry);
event.historyState.direction = direction; event.historyState.direction = direction;
@ -993,14 +964,21 @@
self.element = containerElem; self.element = containerElem;
self.initSelector = false; self.initSelector = false;
$(window).on("navigate", function (e, data) { window.addEventListener("navigate", function (e) {
var url; var url;
if (e.defaultPrevented) {
if (e.originalEvent && e.originalEvent.isDefaultPrevented()) {
return; return;
} }
url = e.originalEvent.type.indexOf("hashchange") > -1 ? data.state.hash : data.state.url; var originalEvent = e.detail.originalEvent;
if (originalEvent && originalEvent.defaultPrevented) {
return;
}
var data = e.detail;
url = originalEvent.type.indexOf("hashchange") > -1 ? data.state.hash : data.state.url;
if (!url) { if (!url) {
url = $.mobile.path.parseLocation().hash; url = $.mobile.path.parseLocation().hash;