PageRenderTime 69ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/ajax/libs/jmpress/0.4.1/jmpress.allplugins.js

https://gitlab.com/Mirros/cdnjs
JavaScript | 307 lines | 264 code | 12 blank | 31 comment | 32 complexity | a5a9f85f1808a5333bf1a3d670736eee MD5 | raw file
  1. /*!
  2. * plugin for jmpress.js v0.4.1
  3. *
  4. * Copyright 2012 Kyle Robinson Young @shama & Tobias Koppers @sokra
  5. * Licensed MIT
  6. * http://www.opensource.org/licenses/mit-license.php
  7. */
  8. /*!
  9. * jmpress.toggle plugin
  10. * For binding a key to toggle de/initialization of jmpress.js.
  11. */
  12. (function( $, document, window, undefined ) {
  13. 'use strict';
  14. $.jmpress("register", "toggle", function( key, config, initial ) {
  15. var jmpress = this;
  16. $(document).bind("keydown", function( event ) {
  17. if ( event.keyCode === key ) {
  18. if ($(jmpress).jmpress("initialized")) {
  19. $(jmpress).jmpress("deinit");
  20. } else {
  21. $(jmpress).jmpress(config);
  22. }
  23. }
  24. });
  25. if ( initial ) {
  26. $(jmpress).jmpress(config);
  27. }
  28. });
  29. }(jQuery, document, window));
  30. /*!
  31. * jmpress.secondary plugin
  32. * Apply a secondary animation when step is selected.
  33. */
  34. (function( $, document, window, undefined ) {
  35. 'use strict';
  36. $.jmpress("initStep", function( step, eventData ) {
  37. for(var name in eventData.data) {
  38. if(name.indexOf("secondary") === 0) {
  39. eventData.stepData[name] = eventData.data[name];
  40. }
  41. }
  42. });
  43. function exchangeIf(childStepData, condition, step) {
  44. if(childStepData.secondary &&
  45. childStepData.secondary.split(" ").indexOf(condition) !== -1) {
  46. for(var name in childStepData) {
  47. if(name.length > 9 && name.indexOf("secondary") === 0) {
  48. var tmp = childStepData[name];
  49. var normal = name.substr(9);
  50. normal = normal.substr(0, 1).toLowerCase() + normal.substr(1);
  51. childStepData[name] = childStepData[normal];
  52. childStepData[normal] = tmp;
  53. }
  54. }
  55. $(this).jmpress("reapply", $(step));
  56. }
  57. }
  58. $.jmpress("beforeActive", function( step, eventData ) {
  59. exchangeIf.call(eventData.jmpress, $(step).data("stepData"), "self", step);
  60. var parent = $(step).parent();
  61. $(parent)
  62. .children(eventData.settings.stepSelector)
  63. .each(function(idx, child) {
  64. var childStepData = $(child).data("stepData");
  65. exchangeIf.call(eventData.jmpress, childStepData, "siblings", child);
  66. });
  67. function grandchildrenFunc(idx, child) {
  68. var childStepData = $(child).data("stepData");
  69. exchangeIf.call(eventData.jmpress, childStepData, "grandchildren", child);
  70. }
  71. for(var i = 1; i < eventData.parents.length; i++) {
  72. $(eventData.parents[i])
  73. .children(eventData.settings.stepSelector)
  74. .each();
  75. }
  76. });
  77. $.jmpress("setInactive", function( step, eventData ) {
  78. exchangeIf.call(eventData.jmpress, $(step).data("stepData"), "self", step);
  79. var parent = $(step).parent();
  80. $(parent)
  81. .children(eventData.settings.stepSelector)
  82. .each(function(idx, child) {
  83. var childStepData = $(child).data("stepData");
  84. exchangeIf.call(eventData.jmpress, childStepData, "siblings", child);
  85. });
  86. function grandchildrenFunc(idx, child) {
  87. var childStepData = $(child).data("stepData");
  88. exchangeIf.call(eventData.jmpress, childStepData, "grandchildren", child);
  89. }
  90. for(var i = 1; i < eventData.parents.length; i++) {
  91. $(eventData.parents[i])
  92. .children(eventData.settings.stepSelector)
  93. .each(grandchildrenFunc);
  94. }
  95. });
  96. }(jQuery, document, window));
  97. /*!
  98. * jmpress.duration plugin
  99. * For auto advancing steps after a given duration and optionally displaying a
  100. * progress bar.
  101. */
  102. (function( $, document, window, undefined ) {
  103. 'use strict';
  104. $.jmpress("defaults").duration = {
  105. defaultValue: -1
  106. ,defaultAction: "next"
  107. ,barSelector: undefined
  108. ,barProperty: "width"
  109. ,barPropertyStart: "0"
  110. ,barPropertyEnd: "100%"
  111. };
  112. $.jmpress("initStep", function( step, eventData ) {
  113. eventData.stepData.duration = eventData.data.duration;
  114. eventData.stepData.durationAction = eventData.data.durationAction;
  115. });
  116. $.jmpress("setInactive", function( step, eventData ) {
  117. var settings = eventData.settings,
  118. durationSettings = settings.duration,
  119. current = eventData.current;
  120. var dur = eventData.stepData.duration || durationSettings.defaultValue;
  121. if( dur && dur > 0 ) {
  122. if( durationSettings.barSelector ) {
  123. var css = {
  124. transitionProperty: durationSettings.barProperty
  125. ,transitionDuration: '0'
  126. ,transitionDelay: '0'
  127. ,transitionTimingFunction: 'linear'
  128. };
  129. css[durationSettings.barProperty] = durationSettings.barPropertyStart;
  130. var bars = $(durationSettings.barSelector);
  131. $.jmpress("css", bars, css);
  132. bars.each(function(idx, element) {
  133. var next = $(element).next();
  134. var parent = $(element).parent();
  135. $(element).detach();
  136. if(next.length) {
  137. next.insertBefore(element);
  138. } else {
  139. parent.append(element);
  140. }
  141. });
  142. }
  143. if(current.durationTimeout) {
  144. clearTimeout(current.durationTimeout);
  145. current.durationTimeout = undefined;
  146. }
  147. }
  148. });
  149. $.jmpress("setActive", function( step, eventData ) {
  150. var settings = eventData.settings,
  151. durationSettings = settings.duration,
  152. current = eventData.current;
  153. var dur = eventData.stepData.duration || durationSettings.defaultValue;
  154. if( dur && dur > 0 ) {
  155. if( durationSettings.barSelector ) {
  156. var css = {
  157. transitionProperty: durationSettings.barProperty
  158. ,transitionDuration: (dur-settings.transitionDuration*2/3-100)+"ms"
  159. ,transitionDelay: (settings.transitionDuration*2/3)+'ms'
  160. ,transitionTimingFunction: 'linear'
  161. };
  162. css[durationSettings.barProperty] = durationSettings.barPropertyEnd;
  163. $.jmpress("css", $(durationSettings.barSelector), css);
  164. }
  165. var jmpress = this;
  166. if(current.durationTimeout) {
  167. clearTimeout(current.durationTimeout);
  168. current.durationTimeout = undefined;
  169. }
  170. current.durationTimeout = setTimeout(function() {
  171. var action = eventData.stepData.durationAction || durationSettings.defaultAction;
  172. $(jmpress).jmpress(action);
  173. }, dur);
  174. }
  175. });
  176. }(jQuery, document, window));
  177. /*!
  178. * jmpress.presentation-mode plugin
  179. * Display a window for the presenter with notes and a control and view of the
  180. * presentation
  181. */
  182. (function( $, document, window, undefined ) {
  183. 'use strict';
  184. var $jmpress = $.jmpress;
  185. /* FUNCTIONS */
  186. function randomString() {
  187. return "" + Math.round(Math.random() * 100000, 0);
  188. }
  189. /* DEFAULTS */
  190. $jmpress("defaults").presentationMode = {
  191. use: true,
  192. url: "presentation-screen.html",
  193. notesUrl: false,
  194. transferredValues: ["userZoom", "userTranslateX", "userTranslateY"]
  195. };
  196. $jmpress("defaults").keyboard.keys[80] = "presentationPopup"; // p key
  197. /* HOOKS */
  198. $jmpress("afterInit", function( nil, eventData) {
  199. var current = eventData.current;
  200. current.selectMessageListeners = [];
  201. if(eventData.settings.presentationMode.use) {
  202. window.addEventListener("message", function(event) {
  203. // We do not test orgin, because we want to accept messages
  204. // from all orgins
  205. try {
  206. var json = JSON.parse(event.data);
  207. switch(json.type) {
  208. case "select":
  209. // TODO SECURITY filter targetId
  210. $.each(eventData.settings.presentationMode.transferredValues, function(idx, name) {
  211. eventData.current[name] = json[name];
  212. });
  213. $(eventData.jmpress).jmpress("select", {step: "#"+json.targetId, substep: json.substep}, json.reason);
  214. break;
  215. case "listen":
  216. current.selectMessageListeners.push(event.source);
  217. break;
  218. case "ok":
  219. clearTimeout(current.presentationPopupTimeout);
  220. break;
  221. case "read":
  222. try {
  223. event.source.postMessage(JSON.stringify({type: "url", url: window.location.href, notesUrl: eventData.settings.presentationMode.notesUrl}), "*");
  224. } catch(e) {
  225. $.error("Cannot post message to source: " + e);
  226. }
  227. break;
  228. default:
  229. throw "Unknown message type: " + json.type;
  230. }
  231. } catch(e) {
  232. $.error("Recieved message is malformed: " + e);
  233. }
  234. });
  235. try {
  236. if(window.parent && window.parent !== window) {
  237. window.parent.postMessage(JSON.stringify({
  238. "type": "afterInit"
  239. }), "*");
  240. }
  241. } catch(e) {
  242. $.error("Cannot post message to parent: " + e);
  243. }
  244. }
  245. });
  246. $jmpress("afterDeinit", function( nil, eventData) {
  247. if(eventData.settings.presentationMode.use) {
  248. try {
  249. if(window.parent && window.parent !== window) {
  250. window.parent.postMessage(JSON.stringify({
  251. "type": "afterDeinit"
  252. }), "*");
  253. }
  254. } catch(e) {
  255. $.error("Cannot post message to parent: " + e);
  256. }
  257. }
  258. });
  259. $jmpress("setActive", function( step, eventData) {
  260. var stepId = $(eventData.delegatedFrom).attr("id"),
  261. substep = eventData.substep,
  262. reason = eventData.reason;
  263. $.each(eventData.current.selectMessageListeners, function(idx, listener) {
  264. try {
  265. var msg = {
  266. "type": "select",
  267. "targetId": stepId,
  268. "substep": substep,
  269. "reason": reason
  270. };
  271. $.each(eventData.settings.presentationMode.transferredValues, function(idx, name) {
  272. msg[name] = eventData.current[name];
  273. });
  274. listener.postMessage(JSON.stringify(msg), "*");
  275. } catch(e) {
  276. $.error("Cannot post message to listener: " + e);
  277. }
  278. });
  279. });
  280. $jmpress("register", "presentationPopup", function() {
  281. function trySend() {
  282. jmpress.jmpress("current").presentationPopupTimeout = setTimeout(trySend, 100);
  283. try {
  284. popup.postMessage(JSON.stringify({type: "url", url: window.location.href, notesUrl: jmpress.jmpress("settings").presentationMode.notesUrl}), "*");
  285. } catch(e) {
  286. }
  287. }
  288. var jmpress = $(this),
  289. popup;
  290. if(jmpress.jmpress("settings").presentationMode.use) {
  291. popup = window.open($(this).jmpress("settings").presentationMode.url);
  292. jmpress.jmpress("current").presentationPopupTimeout = setTimeout(trySend, 100);
  293. }
  294. });
  295. }(jQuery, document, window));