Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** video preview */ ! function(a) {
- var s = null,
- u = null;
- function r() {
- s && (a(s.parentNode).removeClass("preview-loading"), a(s).remove()), u && clearTimeout(u), u = s = null
- }
- a(document).on("mousemove", function(t) {
- if (s) {
- var e = a(s).offset(),
- n = t.pageX,
- o = t.pageY;
- (n < e.left || n > e.left + a(s).width() || o < e.top || o > e.top + a(s).height()) && r()
- }
- }), a(document).mousemove(function(t) {
- if (s) {
- var e = a(s).offset(),
- n = t.pageX,
- o = t.pageY;
- (n < e.left || n > e.left + a(s).width() || o < e.top || o > e.top + a(s).height()) && r()
- }
- }), a(window).on("blur", function() {
- r()
- }), a.fn.videopreview = function() {
- return this.each(function() {
- var t = this,
- e = a(this).attr("data-preview");
- if (e) {
- var n = function() {
- r(), u = setTimeout(function() {
- a(t.parentNode).addClass("preview-loading")
- }, 100), s = document.createElement("VIDEO"), a(s).css({
- position: "absolute",
- left: "0",
- top: "0",
- width: t.offsetWidth + "px",
- height: t.offsetHeight + "px",
- background: "#000000",
- visibility: "hidden"
- }), a(s).on("error", function() {
- r()
- }), a(s).on("loadeddata", function() {
- u && clearTimeout(u), a(s.parentNode).removeClass("preview-loading"), a(s).css({
- visibility: "visible"
- })
- }), s.controls = !1, s.autoplay = !0, s.muted = !0, s.loop = !0, s.src = e, s.setAttribute("webkit-playsinline", "true"), s.setAttribute("playsinline", "true"), t.parentNode.appendChild(s)
- };
- if ("ontouchstart" in document) {
- a(this).offsetParent().append(a('<span class="touch-preview"></span>').on("touchstart", function(t) {
- t.preventDefault(), n()
- }).on("contextmenu", function(t) {
- t.preventDefault()
- }));
- var o = 0,
- i = !1;
- a(this).on("touchstart", function(t) {
- var e = t.originalEvent ? t.originalEvent.touches : t.touches;
- e && e.length && (o = e[0].clientX, i = !0)
- }), a(this).on("touchmove", function(t) {
- var e = t.originalEvent ? t.originalEvent.touches : t.touches;
- e && e.length && i && 40 < Math.abs(o - e[0].clientX) && (n(), o = 0, i = !1)
- })
- } else a(this).mouseover(n)
- }
- }), this
- }
- }(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement