PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/public/admin/assets/js/media-player/jplayer.playlist.min.js

https://gitlab.com/fayimora/pp
JavaScript | 226 lines | 209 code | 0 blank | 17 comment | 34 complexity | c83f71510c220d2e0c7377cababa21ec MD5 | raw file
  1. /*
  2. * Playlist Object for the jPlayer Plugin
  3. * http://www.jplayer.org
  4. *
  5. * Copyright (c) 2009 - 2013 Happyworm Ltd
  6. * Dual licensed under the MIT and GPL licenses.
  7. * - http://www.opensource.org/licenses/mit-license.php
  8. * - http://www.gnu.org/copyleft/gpl.html
  9. *
  10. * Author: Mark J Panaghiston
  11. * Version: 2.3.0
  12. * Date: 20th April 2013
  13. *
  14. * Requires:
  15. * - jQuery 1.7.0+
  16. * - jPlayer 2.3.0+
  17. */
  18. (function (b, f) {
  19. jPlayerPlaylist = function (a, c, d) {
  20. var e = this;
  21. this.current = 0;
  22. this.removing = this.shuffled = this.loop = !1;
  23. this.cssSelector = b.extend({}, this._cssSelector, a);
  24. this.options = b.extend(!0, {keyBindings: {next: {key: 39, fn: function () {
  25. e.next()
  26. }}, previous: {key: 37, fn: function () {
  27. e.previous()
  28. }}}}, this._options, d);
  29. this.playlist = [];
  30. this.original = [];
  31. this._initPlaylist(c);
  32. this.cssSelector.title = this.cssSelector.cssSelectorAncestor + " .jp-title";
  33. this.cssSelector.playlist = this.cssSelector.cssSelectorAncestor + " .jp-playlist";
  34. this.cssSelector.next = this.cssSelector.cssSelectorAncestor + " .jp-next";
  35. this.cssSelector.previous = this.cssSelector.cssSelectorAncestor + " .jp-previous";
  36. this.cssSelector.shuffle = this.cssSelector.cssSelectorAncestor + " .jp-shuffle";
  37. this.cssSelector.shuffleOff = this.cssSelector.cssSelectorAncestor + " .jp-shuffle-off";
  38. this.options.cssSelectorAncestor = this.cssSelector.cssSelectorAncestor;
  39. this.options.repeat = function (a) {
  40. e.loop = a.jPlayer.options.loop
  41. };
  42. b(this.cssSelector.jPlayer).bind(b.jPlayer.event.ready, function () {
  43. e._init()
  44. });
  45. b(this.cssSelector.jPlayer).bind(b.jPlayer.event.ended, function () {
  46. e.next()
  47. });
  48. b(this.cssSelector.jPlayer).bind(b.jPlayer.event.play, function () {
  49. b(this).jPlayer("pauseOthers")
  50. });
  51. b(this.cssSelector.jPlayer).bind(b.jPlayer.event.resize, function (a) {
  52. a.jPlayer.options.fullScreen ? b(e.cssSelector.title).show() : b(e.cssSelector.title).hide()
  53. });
  54. b(this.cssSelector.previous).click(function () {
  55. e.previous();
  56. b(this).blur();
  57. return!1
  58. });
  59. b(this.cssSelector.next).click(function () {
  60. e.next();
  61. b(this).blur();
  62. return!1
  63. });
  64. b(this.cssSelector.shuffle).click(function () {
  65. e.shuffle(!0);
  66. return!1
  67. });
  68. b(this.cssSelector.shuffleOff).click(function () {
  69. e.shuffle(!1);
  70. return!1
  71. }).hide();
  72. this.options.fullScreen || b(this.cssSelector.title).hide();
  73. b(this.cssSelector.playlist + " ul").empty();
  74. this._createItemHandlers();
  75. b(this.cssSelector.jPlayer).jPlayer(this.options)
  76. };
  77. jPlayerPlaylist.prototype = {_cssSelector: {jPlayer: "#jquery_jplayer_1", cssSelectorAncestor: "#jp_container_1"}, _options: {playlistOptions: {autoPlay: !1, loopOnPrevious: !1, shuffleOnLoop: !0, enableRemoveControls: !1, displayTime: "slow", addTime: "fast",
  78. removeTime: "fast", shuffleTime: "slow", itemClass: "jp-playlist-item", freeGroupClass: "jp-free-media", freeItemClass: "jp-playlist-item-free", removeItemClass: "jp-playlist-item-remove"}}, option: function (a, b) {
  79. if (b === f)return this.options.playlistOptions[a];
  80. this.options.playlistOptions[a] = b;
  81. switch (a) {
  82. case "enableRemoveControls":
  83. this._updateControls();
  84. break;
  85. case "itemClass":
  86. case "freeGroupClass":
  87. case "freeItemClass":
  88. case "removeItemClass":
  89. this._refresh(!0), this._createItemHandlers()
  90. }
  91. return this
  92. }, _init: function () {
  93. var a =
  94. this;
  95. this._refresh(function () {
  96. a.options.playlistOptions.autoPlay ? a.play(a.current) : a.select(a.current)
  97. })
  98. }, _initPlaylist: function (a) {
  99. this.current = 0;
  100. this.removing = this.shuffled = !1;
  101. this.original = b.extend(!0, [], a);
  102. this._originalPlaylist()
  103. }, _originalPlaylist: function () {
  104. var a = this;
  105. this.playlist = [];
  106. b.each(this.original, function (b) {
  107. a.playlist[b] = a.original[b]
  108. })
  109. }, _refresh: function (a) {
  110. var c = this;
  111. if (a && !b.isFunction(a))b(this.cssSelector.playlist + " ul").empty(), b.each(this.playlist, function (a) {
  112. b(c.cssSelector.playlist +
  113. " ul").append(c._createListItem(c.playlist[a]))
  114. }), this._updateControls(); else {
  115. var d = b(this.cssSelector.playlist + " ul").children().length ? this.options.playlistOptions.displayTime : 0;
  116. b(this.cssSelector.playlist + " ul").slideUp(d, function () {
  117. var d = b(this);
  118. b(this).empty();
  119. b.each(c.playlist, function (a) {
  120. d.append(c._createListItem(c.playlist[a]))
  121. });
  122. c._updateControls();
  123. b.isFunction(a) && a();
  124. c.playlist.length ? b(this).slideDown(c.options.playlistOptions.displayTime) : b(this).show()
  125. })
  126. }
  127. }, _createListItem: function (a) {
  128. var c =
  129. this, d = "<li><div>", d = d + ("<a href='javascript:;' class='" + this.options.playlistOptions.removeItemClass + "'>&times;</a>");
  130. if (a.free) {
  131. var e = !0, d = d + ("<span class='" + this.options.playlistOptions.freeGroupClass + "'>(");
  132. b.each(a, function (a, f) {
  133. b.jPlayer.prototype.format[a] && (e ? e = !1 : d += " | ", d += "<a class='" + c.options.playlistOptions.freeItemClass + "' href='" + f + "' tabindex='1'>" + a + "</a>")
  134. });
  135. d += ")</span>"
  136. }
  137. d += "<a href='javascript:;' class='" + this.options.playlistOptions.itemClass + "' tabindex='1'>" + a.title + (a.artist ?
  138. " <span class='jp-artist'>by " + a.artist + "</span>" : "") + "</a>";
  139. return d += "</div></li>"
  140. }, _createItemHandlers: function () {
  141. var a = this;
  142. b(this.cssSelector.playlist).off("click", "a." + this.options.playlistOptions.itemClass).on("click", "a." + this.options.playlistOptions.itemClass, function () {
  143. var c = b(this).parent().parent().index();
  144. a.current !== c ? a.play(c) : b(a.cssSelector.jPlayer).jPlayer("play");
  145. b(this).blur();
  146. return!1
  147. });
  148. b(this.cssSelector.playlist).off("click", "a." + this.options.playlistOptions.freeItemClass).on("click",
  149. "a." + this.options.playlistOptions.freeItemClass, function () {
  150. b(this).parent().parent().find("." + a.options.playlistOptions.itemClass).click();
  151. b(this).blur();
  152. return!1
  153. });
  154. b(this.cssSelector.playlist).off("click", "a." + this.options.playlistOptions.removeItemClass).on("click", "a." + this.options.playlistOptions.removeItemClass, function () {
  155. var c = b(this).parent().parent().index();
  156. a.remove(c);
  157. b(this).blur();
  158. return!1
  159. })
  160. }, _updateControls: function () {
  161. this.options.playlistOptions.enableRemoveControls ? b(this.cssSelector.playlist +
  162. " ." + this.options.playlistOptions.removeItemClass).show() : b(this.cssSelector.playlist + " ." + this.options.playlistOptions.removeItemClass).hide();
  163. this.shuffled ? (b(this.cssSelector.shuffleOff).show(), b(this.cssSelector.shuffle).hide()) : (b(this.cssSelector.shuffleOff).hide(), b(this.cssSelector.shuffle).show())
  164. }, _highlight: function (a) {
  165. this.playlist.length && a !== f && (b(this.cssSelector.playlist + " .jp-playlist-current").removeClass("jp-playlist-current"), b(this.cssSelector.playlist + " li:nth-child(" + (a + 1) +
  166. ")").addClass("jp-playlist-current").find(".jp-playlist-item").addClass("jp-playlist-current"), b(this.cssSelector.title + " li").html(this.playlist[a].title + (this.playlist[a].artist ? " <span class='jp-artist'>by " + this.playlist[a].artist + "</span>" : "")))
  167. }, setPlaylist: function (a) {
  168. this._initPlaylist(a);
  169. this._init()
  170. }, add: function (a, c) {
  171. b(this.cssSelector.playlist + " ul").append(this._createListItem(a)).find("li:last-child").hide().slideDown(this.options.playlistOptions.addTime);
  172. this._updateControls();
  173. this.original.push(a);
  174. this.playlist.push(a);
  175. c ? this.play(this.playlist.length - 1) : 1 === this.original.length && this.select(0)
  176. }, remove: function (a) {
  177. var c = this;
  178. if (a === f)return this._initPlaylist([]), this._refresh(function () {
  179. b(c.cssSelector.jPlayer).jPlayer("clearMedia")
  180. }), !0;
  181. if (this.removing)return!1;
  182. a = 0 > a ? c.original.length + a : a;
  183. 0 <= a && a < this.playlist.length && (this.removing = !0, b(this.cssSelector.playlist + " li:nth-child(" + (a + 1) + ")").slideUp(this.options.playlistOptions.removeTime, function () {
  184. b(this).remove();
  185. if (c.shuffled) {
  186. var d =
  187. c.playlist[a];
  188. b.each(c.original, function (a) {
  189. if (c.original[a] === d)return c.original.splice(a, 1), !1
  190. })
  191. } else c.original.splice(a, 1);
  192. c.playlist.splice(a, 1);
  193. c.original.length ? a === c.current ? (c.current = a < c.original.length ? c.current : c.original.length - 1, c.select(c.current)) : a < c.current && c.current-- : (b(c.cssSelector.jPlayer).jPlayer("clearMedia"), c.current = 0, c.shuffled = !1, c._updateControls());
  194. c.removing = !1
  195. }));
  196. return!0
  197. }, select: function (a) {
  198. a = 0 > a ? this.original.length + a : a;
  199. 0 <= a && a < this.playlist.length ? (this.current =
  200. a, this._highlight(a), b(this.cssSelector.jPlayer).jPlayer("setMedia", this.playlist[this.current])) : this.current = 0
  201. }, play: function (a) {
  202. a = 0 > a ? this.original.length + a : a;
  203. 0 <= a && a < this.playlist.length ? this.playlist.length && (this.select(a), b(this.cssSelector.jPlayer).jPlayer("play")) : a === f && b(this.cssSelector.jPlayer).jPlayer("play")
  204. }, pause: function () {
  205. b(this.cssSelector.jPlayer).jPlayer("pause")
  206. }, next: function () {
  207. var a = this.current + 1 < this.playlist.length ? this.current + 1 : 0;
  208. this.loop ? 0 === a && this.shuffled && this.options.playlistOptions.shuffleOnLoop &&
  209. 1 < this.playlist.length ? this.shuffle(!0, !0) : this.play(a) : 0 < a && this.play(a)
  210. }, previous: function () {
  211. var a = 0 <= this.current - 1 ? this.current - 1 : this.playlist.length - 1;
  212. (this.loop && this.options.playlistOptions.loopOnPrevious || a < this.playlist.length - 1) && this.play(a)
  213. }, shuffle: function (a, c) {
  214. var d = this;
  215. a === f && (a = !this.shuffled);
  216. (a || a !== this.shuffled) && b(this.cssSelector.playlist + " ul").slideUp(this.options.playlistOptions.shuffleTime, function () {
  217. (d.shuffled = a) ? d.playlist.sort(function () {
  218. return 0.5 - Math.random()
  219. }) :
  220. d._originalPlaylist();
  221. d._refresh(!0);
  222. c || !b(d.cssSelector.jPlayer).data("jPlayer").status.paused ? d.play(0) : d.select(0);
  223. b(this).slideDown(d.options.playlistOptions.shuffleTime)
  224. })
  225. }}
  226. })(jQuery);