jee.js 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. /*
  2. _ _
  3. |_|___ _ _ ___ ___ ___ ___| |_ ___ ___ ___ ___ ___ ___ ___
  4. | | -_| | | | -_|_ -| | -_| _| | -_| | . | .'| . | -_|_ -|
  5. _| |___|___|_|_|___|___| |___|_| |___|_|_|_ |__,|_ |___|___|
  6. |___| |___| |___|
  7. Bachir Soussi Chiadmi
  8. 2015
  9. */
  10. jQuery(document).ready(function($) {
  11. console.log('Hello Jee');
  12. var _debug = true,
  13. _avgDelay = 1,
  14. _lastDraw = new Date,
  15. _fps,
  16. _$nav_cursor;
  17. var _$body = $('body'),
  18. _$header = $("#header"),
  19. _$chapitres = $('.node-chapitre', '#main'),
  20. _chapitres_len = _$chapitres.length,
  21. _chapters = [],
  22. _$container = $('#main'),
  23. _container = {
  24. w:_$container.width(),
  25. h:_$container.height()
  26. },
  27. _center = {x:_container.w/2,y:_container.h/2},
  28. _nav_pos = {x:0, y:0},
  29. _mouse_down_pos = {x:0,y:0},
  30. _prev_mouse_pos = {x:0,y:0},
  31. _fps = 1000/12,
  32. _dragging = false, _timeout_dragging;
  33. var _$chapter_wrapper = $('<div>').attr('id', 'chapter-wrapper').appendTo(_$container),
  34. _loaded_chapter = false;
  35. var _bubbles = new Array(),
  36. _stars = new Array();
  37. function init(){
  38. if(_debug)
  39. initDebug();
  40. initChapterWrapper();
  41. initChapters();
  42. launchNav();
  43. // FULL SCREEN
  44. var $fullscreenBtn = $('<div>enter</div>').attr('id','fullscreen-btn').appendTo("#root");
  45. $fullscreenBtn.on('click', onFullScreen);
  46. // create bubbles
  47. for (var i = 2; i > 0; i--) {
  48. _bubbles.push($('<div>').addClass('bubble bubble-'+i).prependTo(_$container));
  49. };
  50. // create stars
  51. for (var i = 20; i > 0; i--) {
  52. _stars.push(
  53. $('<div>')
  54. .addClass('star star-'+i)
  55. .css({
  56. left:randB(-400, _container.w+400),
  57. top:randB(-400, _container.h+400)
  58. })
  59. .prependTo(_$container)
  60. );
  61. };
  62. };
  63. function initDebug(){
  64. $('<p>').attr('id', 'fps').appendTo(_$container);
  65. _fps = document.getElementById('fps');
  66. requestAnimationFrame(displayFps);
  67. _$nav_cursor = $('<div id="nav-cursor"></div>').appendTo(_$container);
  68. moveDebugCursor();
  69. };
  70. function displayFps(){
  71. requestAnimationFrame(displayFps);
  72. var now = new Date;
  73. var delay = now - _lastDraw;
  74. _avgDelay += (delay - _avgDelay) / 10;
  75. _lastDraw = now;
  76. _fps.innerHTML = (1000/_avgDelay).toFixed(1) + " fps";
  77. };
  78. function moveDebugCursor(){
  79. _$nav_cursor.css({
  80. left:_nav_pos.x+_center.x+"px",
  81. top:_nav_pos.y+_center.y+"px"
  82. });
  83. };
  84. function initChapterWrapper(){
  85. $('<div id="home-btn">')
  86. .on("click", closeChapterWrapper)
  87. .appendTo(_$chapter_wrapper);
  88. };
  89. function closeChapterWrapper(e){
  90. _loaded_chapter = false;
  91. _$chapter_wrapper.removeClass('visible');
  92. _$body.removeClass('chapter-displayed');
  93. };
  94. function initChapters(){
  95. // Place each chapters on the ellipse contained on the screen
  96. var base_a = Math.random() *360;
  97. _$chapitres.each(function(i, e) {
  98. // Lets create the chapter object and place him self
  99. _chapters.push(new Chapter(i, e, base_a));
  100. });
  101. };
  102. function launchNav(){
  103. $(document)
  104. /*
  105. ____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____
  106. | \| __| __| | |_ _| | _ | | __| | | __| | |_ _| __|
  107. | | | __|__ | -| | | | | | __| | __| | | __| | | | | | |__ |
  108. |____/|_____|_____|__|__| |_| |_____|__| |_____|\___/|_____|_|___| |_| |_____|
  109. */
  110. .bind('mousedown', function(e){
  111. console.log('document mousedown');
  112. clearTimeout(_timeout_dragging);
  113. if(_loaded_chapter)
  114. return false;
  115. // set initial cursor pos
  116. _mouse_down_pos.x = e.clientX;
  117. _mouse_down_pos.y = e.clientY;
  118. updateNavPos(e.clientX, e.clientY, true);
  119. $(this).bind('mousemove', function(e){
  120. console.log('document mousemove');
  121. updateNavPos(e.clientX, e.clientY, false);
  122. });
  123. // activate dragging if already activated
  124. if(!_dragging){
  125. _dragging = true;
  126. startMoveNav();
  127. }
  128. })
  129. .bind('mouseup', function(e){
  130. console.log('document mouseup');
  131. if(_loaded_chapter)
  132. return false;
  133. stopMoveNav();
  134. $(this).unbind('mousemove');
  135. // close all preview
  136. if(Math.abs(e.clientX - _mouse_down_pos.x) < 2
  137. && Math.abs(e.clientY - _mouse_down_pos.y) < 2)
  138. for (var i = _chapitres_len - 1; i >= 0; i--)
  139. _chapters[i].closePreview().unMitigate();
  140. })
  141. /*
  142. _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____
  143. |_ _| | | | | | | | __| | | __| | |_ _| __|
  144. | | | | | | | --| | | __| | | __| | | | | | |__ |
  145. |_| |_____|_____|_____|__|__| |_____|\___/|_____|_|___| |_| |_____|
  146. */
  147. .bind('document touchstart', function(e){
  148. console.log('touchstart');
  149. clearTimeout(_timeout_dragging);
  150. if(_loaded_chapter)
  151. return false;
  152. // set initial pos
  153. updateNavPos(e.originalEvent.touches[0].clientX, e.originalEvent.touches[0].clientY, true);
  154. // activate dragging if already activated
  155. if(!_dragging){
  156. _dragging = true;
  157. startMoveNav();
  158. }
  159. })
  160. .bind('touchmove', function(e){
  161. console.log('document touchmove');
  162. if(_loaded_chapter)
  163. return false;
  164. updateNavPos(e.originalEvent.touches[0].clientX, e.originalEvent.touches[0].clientY, false);
  165. })
  166. .bind('touchend', function(e){
  167. console.log("document touchend");
  168. if(_loaded_chapter)
  169. return false;
  170. stopMoveNav();
  171. });
  172. // TODO : nav on scroll events
  173. };
  174. function updateNavPos(x,y,init){
  175. if(!init){
  176. _nav_pos.x += x - _prev_mouse_pos.x;
  177. _nav_pos.y += y - _prev_mouse_pos.y;
  178. // constrain nav pos on container
  179. _nav_pos.x = _nav_pos.x < -_center.x*2
  180. ? -_center.x*2
  181. : _nav_pos.x > _center.x*2
  182. ? _center.x*2
  183. : _nav_pos.x;
  184. _nav_pos.y = _nav_pos.y < -_center.y*2
  185. ? -_center.y*2
  186. : _nav_pos.y > _center.y*2
  187. ? _center.y*2
  188. : _nav_pos.y;
  189. }
  190. _prev_mouse_pos.x = x;
  191. _prev_mouse_pos.y = y;
  192. // debuging cursor
  193. if(_debug)
  194. moveDebugCursor();
  195. };
  196. function startMoveNav(){
  197. window.requestAnimationFrame(moveNav);
  198. };
  199. function moveNav(){
  200. // console.log("moveNav");
  201. if(!_dragging) return;
  202. window.requestAnimationFrame(moveNav);
  203. // move chapters
  204. for (var i = _chapitres_len - 1; i >= 0; i--)
  205. _chapters[i].move();
  206. // move header
  207. _$header.css({
  208. transform:"translate3d("+(_nav_pos.x)*0.2+"px, "+(_nav_pos.y)*0.2+"px,0)"
  209. });
  210. // bubbles and stars dont move so smoothly on tablette ...
  211. // should keep it only on desktop
  212. // move bubbles
  213. // for (var i = _bubbles.length - 1; i >= 0; i--) {
  214. // _bubbles[i].css({
  215. // transform:"translate3d("+(_nav_pos.x)*0.4+"px, "+(_nav_pos.y)*0.4+"px,0)"
  216. // });
  217. // };
  218. // move stars
  219. // for (var i = _stars.length - 1; i >= 0; i--) {
  220. // _stars[i].css({
  221. // transform:"translate3d("+(_nav_pos.x)*-0.3+"px, "+(_nav_pos.y)*-0.3+"px,0)"
  222. // });
  223. // };
  224. };
  225. function stopMoveNav(){
  226. console.log('stopMoveNav');
  227. clearTimeout(_timeout_dragging);
  228. _timeout_dragging = setTimeout(function(){
  229. console.log("dragging stoped");
  230. _dragging = false;
  231. },3000);
  232. };
  233. function moveToChapter(chapter){
  234. // fake a mousdown by providing first pos as current pos
  235. _prev_mouse_pos.x = _nav_pos.x;
  236. _prev_mouse_pos.y = _nav_pos.y;
  237. // calculate the second pos of faked mousemove
  238. var xl = _center.x - chapter.pos.x - chapter.geom.w/2;
  239. var yl = 100 - chapter.pos.y;
  240. updateNavPos(xl, yl, false);
  241. startMoveNav();
  242. stopMoveNav();
  243. };
  244. function onFullScreen(e){
  245. launchIntoFullscreen(document.getElementById("root"));
  246. if(_loaded_chapter)
  247. setTimeout(_loaded_chapter.buildVideos(), 100);
  248. };
  249. /*
  250. ________ __
  251. / ____/ /_ ____ _____ / /____ _____
  252. / / / __ \/ __ `/ __ \/ __/ _ \/ ___/
  253. / /___/ / / / /_/ / /_/ / /_/ __/ /
  254. \____/_/ /_/\__,_/ .___/\__/\___/_/
  255. /_/
  256. */
  257. function Chapter(i, e, base_a){
  258. // $e.obj = this;
  259. this.i = i;
  260. this.e = e;
  261. this.$e = $(e);
  262. this.nid = this.$e.attr("id").match(/^node-(\d+)/)[1];
  263. this.geom = {
  264. base_a:base_a,
  265. a:0,
  266. r:0,
  267. w:this.$e.outerWidth(true),
  268. h:this.$e.outerHeight(true)
  269. }
  270. this.pos = {x:0,y:0};
  271. this.trans = {x:0, y:0,z:0};
  272. this.ease = randB(0.05, 0.3);
  273. //drifting
  274. this.$title = $('h2.node-title', this.$e);
  275. this.$content = $('.content:first', this.$e);
  276. this.title_x = 0;
  277. this.content_x = 0;
  278. this.drifting_direction = Math.random()-0.5 > 0 ? 1 : -1;
  279. this.drifting_time = null;
  280. //preview
  281. this.is_previewed = false;
  282. //mitigate
  283. this.is_mitigated = false;
  284. //parties
  285. this.$parties = $('.field-name-field-partie', e);
  286. this.parts_pos = {xs:new Array(), ys:new Array()};
  287. this.lines = new Array();
  288. this.linesAnimeStartTime = 0,
  289. this.linesAnimeDuration = 2000; // milli sec
  290. // chapter
  291. this.$n = false;
  292. this.$blocks = false;
  293. this.$vids_container = false;
  294. this.$vids = false;
  295. this.texts_pos = shuffleArray([1,2,3]);
  296. this.dimvideo = {w:0, h:0};
  297. this.$slider = null;
  298. this.cur_vid_playing = 0;
  299. // prototypes
  300. if (typeof Chapter.initialized == "undefined") {
  301. Chapter.prototype.init = function(){
  302. this.setInitPos();
  303. this.drawLines();
  304. this.setEvents();
  305. this.initDrifiting();
  306. };
  307. Chapter.prototype.setInitPos = function(){
  308. // distribute elements arround the center
  309. this.geom.a = (360/_chapitres_len*this.i+this.geom.base_a)*Math.PI/180;
  310. // console.log("Chapter :: setInitPos", this.$e);
  311. this.geom.c = Math.cos(this.geom.a);
  312. this.geom.s = Math.sin(this.geom.a);
  313. this.geom.abs_c = Math.abs(this.geom.c);
  314. this.geom.abs_s = Math.abs(this.geom.s);
  315. if (this.geom.abs_c * _container.h > this.geom.abs_s * _container.w) {
  316. // It crosses left or right side
  317. this.geom.r = (_center.x / this.geom.abs_c)*0.5;
  318. }else {
  319. // Top or bottom side
  320. this.geom.r = (_center.y / this.geom.abs_s)*0.5;
  321. }
  322. // change randomly radius
  323. if(this.i%2){
  324. this.geom.r = randB(this.geom.r*1.5, this.geom.r*2);
  325. }else{
  326. this.geom.r = randB(this.geom.r*0.8, this.geom.r*1.5);
  327. }
  328. this.pos.x = Math.round(_center.x+this.geom.r * this.geom.c) - this.geom.w/2;
  329. this.pos.y = Math.round(_center.y+this.geom.r * -this.geom.s) - this.geom.h/2;
  330. console.log('this', this);
  331. this.$e.css({
  332. left:this.pos.x,
  333. top:this.pos.y
  334. });
  335. };// setIniPos()
  336. Chapter.prototype.setEvents = function(){
  337. //http://technify.me/user-experience/javascript/jquery/trigger-custom-events-with-jquery/
  338. // click to preview chapter
  339. $('h2.node-title, .field-name-field-partie:first>.field-name-field-vignette', this.$e)
  340. .on('click', this, function(e){
  341. // e.stopImmediatePropagation();
  342. e.stopPropagation();
  343. e.preventDefault();
  344. e.data.preview(e);
  345. return false;
  346. });
  347. $('.links a', this.$e)
  348. .on('click', this, function(e){
  349. e.stopPropagation();
  350. e.preventDefault();
  351. e.data.loadNode();
  352. return false;
  353. });
  354. };
  355. Chapter.prototype.initDrifiting = function(){
  356. // an other option could be to drift the whole page with the same engine than draging
  357. requestAnimationFrame(this.drift.bind(this));
  358. };
  359. Chapter.prototype.drift = function(timestamp){
  360. requestAnimationFrame(this.drift.bind(this));
  361. var now = new Date().getTime(),
  362. dt = now - (this.drifting_time || now);
  363. this.drifting_time = now;
  364. if(!this.is_previewed){
  365. this.title_x += (10/1000)*dt*this.drifting_direction;
  366. this.content_x += (6/1000)*dt*this.drifting_direction;
  367. this.drifting_direction =
  368. this.content_x > randB(100,130)
  369. ? -1
  370. : this.content_x < -randB(100,130)
  371. ? 1
  372. : this.drifting_direction;
  373. this.$title.css({
  374. transform:"translate3d("+this.title_x+"px,0,0)",
  375. });
  376. this.$content.css({
  377. transform:"translate3d("+this.content_x+"px,0,0)",
  378. });
  379. }
  380. };
  381. Chapter.prototype.move = function(){
  382. this.trans.x += (_nav_pos.x - this.trans.x)*this.ease;
  383. this.trans.y += (_nav_pos.y - this.trans.y)*this.ease;
  384. // this.trans.z = Math.floor(Math.sqrt(
  385. // Math.pow(
  386. // _center.x-(this.pos.x+this.trans.x)
  387. // ,2
  388. // )
  389. // +
  390. // Math.pow(
  391. // _center.y-(this.pos.y+this.trans.y)
  392. // ,2
  393. // )
  394. // ));
  395. // if(this.i === 0)
  396. // console.log(this.i+" this.trans.z", this.trans.z);
  397. this.$e.css({
  398. transform:'translate3d('+this.trans.x+'px,'+this.trans.y+'px,0)'
  399. // scale:this.trans.z
  400. });
  401. };
  402. Chapter.prototype.preview = function(){
  403. // don't relaunch preview more that one time
  404. if(this.is_previewed) return;
  405. console.log('preview', this.i);
  406. this.unMitigate();
  407. this.is_previewed = true;
  408. // close other chapters
  409. for (var i = _chapitres_len - 1; i >= 0; i--)
  410. if(i !== this.i)
  411. _chapters[i].closePreview().mitigate();
  412. this.displayPreview();
  413. moveToChapter(this);
  414. };
  415. Chapter.prototype.displayPreview = function(e){
  416. // define randomly position of parties
  417. this.resetPartsPos();
  418. // apply new position to parties
  419. var that = this;
  420. this.$parties.each(function(i, e) {
  421. setTimeout(
  422. (function(i, e, xs, ys){
  423. return function(){
  424. $(e)
  425. .css({
  426. transform:"translate3d("+xs[i]+"px,"+ys[i]+"px,0)",
  427. });
  428. }
  429. }(i, e, that.parts_pos.xs, that.parts_pos.ys)),
  430. 10);
  431. }); // each $parties
  432. this.$e.addClass('previewed');
  433. requestAnimationFrame(this.animeLines.bind(this));
  434. };
  435. Chapter.prototype.resetPartsPos = function(){
  436. this.parts_pos = {xs:new Array(), ys:new Array()};
  437. for (var i = 0; i < 3; i++) {
  438. switch(i){
  439. case 0:
  440. this.parts_pos.xs.push(randB(-30,30)); this.parts_pos.ys.push(randB(90,110)); break;
  441. case 1:
  442. this.parts_pos.xs.push(randB(180,280)); this.parts_pos.ys.push(randB(250,350)); break;
  443. case 2:
  444. this.parts_pos.xs.push(randB(-280,-180)); this.parts_pos.ys.push(randB(430,530)); break;
  445. }
  446. };
  447. this.parts_pos.xs = shuffleArray(this.parts_pos.xs);
  448. this.parts_pos.ys = shuffleArray(this.parts_pos.ys);
  449. };
  450. Chapter.prototype.closePreview = function(){
  451. if(!this.is_previewed) return this;
  452. this.$e.removeClass('previewed')
  453. .find('.field-name-field-partie')
  454. .css({transform:"none"});
  455. requestAnimationFrame(this.animeLines.bind(this));
  456. this.is_previewed = false;
  457. return this;
  458. };
  459. Chapter.prototype.mitigate = function(){
  460. if(this.is_mitigated) return this;
  461. this.$e.addClass('mitigated');
  462. return this;
  463. };
  464. Chapter.prototype.unMitigate = function(){
  465. if(this.is_mitigated) return this;
  466. this.$e.removeClass('mitigated');
  467. return this;
  468. };
  469. Chapter.prototype.drawLines = function(){
  470. for (var i = 0; i < 2; i++) {
  471. this.lines.push({
  472. $line:$("<div>").addClass('line', 'line-'+i).prependTo(this.$parties[i])
  473. });
  474. };
  475. };
  476. Chapter.prototype.animeLines = function(timestamp){
  477. // console.log("anime line "+this.nid);
  478. // get the time on first anime launch
  479. if(this.linesAnimeStartTime === 0)
  480. this.linesAnimeStartTime = timestamp;
  481. // limit the animation time
  482. if(timestamp - this.linesAnimeStartTime < this.linesAnimeDuration){
  483. requestAnimationFrame(this.animeLines.bind(this));
  484. }else{
  485. this.linesAnimeStartTime = 0;
  486. }
  487. // get the lines length
  488. var l, a, pos1, pos2;
  489. for (var i = 0; i < this.lines.length; i++) {
  490. pos1 = this.$parties.eq(i).position();
  491. pos2 = this.$parties.eq(i+1).position();
  492. l = Math.sqrt(
  493. Math.pow(
  494. pos2.left - pos1.left
  495. ,2
  496. )
  497. +
  498. Math.pow(
  499. pos2.top - pos1.top
  500. ,2
  501. )
  502. );
  503. // get the rotation
  504. a = 180 / 3.14 * Math.acos((pos2.top - pos1.top) / l);
  505. if(pos2.left > pos1.left)
  506. a *= -1;
  507. // console.log("a = "+a);
  508. this.lines[i].$line.css({
  509. 'height':l,
  510. transform:"rotate3d(0,0,1,"+a+"deg)"
  511. });
  512. };
  513. };
  514. // _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____
  515. // | | _ | __| | | | | | | _ | _ |_ _| __| __ |
  516. // | | | __| __| | | | | --| | | __| | | | __| -|
  517. // |_____|__| |_____|_|___| |_____|__|__|__|__|__| |_| |_____|__|__|
  518. Chapter.prototype.loadNode = function(e){
  519. // console.log("Chapter :: open : nid", this.nid);
  520. $.getJSON(
  521. '/jee/chapter/'+this.nid,
  522. {},
  523. this.nodeLoaded.bind(this)
  524. );
  525. _$body.addClass('chapter-displayed');
  526. };
  527. Chapter.prototype.nodeLoaded = function(json, textstatus){
  528. console.log('Chapter :: nodeLoaded '+this.nid+' : json', json);
  529. // remove previous loaded nodes
  530. _$chapter_wrapper.find('.node').remove();
  531. // insert ajax loaded into dom
  532. _$chapter_wrapper.append(json.node);
  533. // record some usefull data
  534. this.$n = $('.node-chapitre', _$chapter_wrapper);
  535. this.$blocks = $('.field-type-text-long', this.$n);
  536. this.$vids_container = $('.field-name-field-partie', this.$n);
  537. this.$vids = $('iframe', this.$vids_container);
  538. // record the current loaded chapter
  539. // this will stop first interface to run
  540. _loaded_chapter = this;
  541. // wait to build correct display of chapter
  542. setTimeout(this.displayNode.bind(this), 100);
  543. };
  544. Chapter.prototype.displayNode = function(){
  545. console.log('Chapter :: displayNode '+this.nid);
  546. // place text blocks
  547. this.texts_pos = shuffleArray([1,2,3]);
  548. this.$blocks
  549. .each(this.placeText.bind(this))
  550. .pep({
  551. allowDragEventPropagation:false,
  552. disableSelect:true,
  553. velocityMultiplier:1
  554. });
  555. // build video player
  556. this.buildVideos();
  557. // show the whole thing
  558. _$chapter_wrapper.addClass('visible');
  559. // this.$vids.eq(this.cur_vid_playing).vimeo('play');
  560. };
  561. Chapter.prototype.placeText = function(i, e){
  562. // console.log("Chapter :: placeText", e);
  563. switch(this.texts_pos[i]){
  564. case 1: // top right
  565. $(e)
  566. .css({
  567. top:randB(_container.h*0.05-$(e).height(),_container.h*0.15-$(e).height()),
  568. left:randB(_container.w*0.8-$(e).width(),_container.w*0.9-$(e).width())
  569. })
  570. // .pep({debug:true, startPos:{bottom:randB(80,90),right:randB(80,90)}})
  571. .find('.field-label')
  572. .appendTo(e);
  573. break;
  574. case 2: // bottom left
  575. $(e).css({
  576. top:randB(_container.h*0.8,_container.h*0.9),
  577. left:randB(_container.w*0.1,_container.w*0.2)
  578. });
  579. // $(e).pep({debug:true, startPos:{top:randB(80,90),left:randB(10,30)}});
  580. break;
  581. case 3: // bottom right
  582. $(e).css({
  583. top:randB(_container.h*0.8,_container.h*0.9),
  584. left:randB(_container.w*0.7,_container.w*0.9-$(e).width())
  585. });
  586. // $(e).pep({debug:true, startPos:{top:randB(80,90),right:randB(10,30)}});
  587. break;
  588. }
  589. };
  590. Chapter.prototype.buildVideos = function(){
  591. console.log('Chapter :: buildVideos');
  592. this.dimvideo.h = this.$vids_container.height();
  593. // redim each iframe to fit
  594. // add a mask on top of each iframe to avoid bad interaction with vimeo
  595. this.$vids
  596. .after('<div class="mask"></div>')
  597. .each(this.redimVideo.bind(this));
  598. this.$vids_container.css({
  599. width:this.dimvideo.w*1.2,
  600. height:this.dimvideo.h,
  601. marginLeft:(_container.w-this.dimvideo.w*1.2)/2
  602. });
  603. // create the slider with peppermint
  604. this.$slider = $('.field-items', this.$vids_container).Peppermint({
  605. onSlideChange:this.onSlideChange.bind(this)
  606. });
  607. };
  608. Chapter.prototype.redimVideo = function(i,e){
  609. // compute proportional video width ragarding the parent height
  610. this.dimvideo.w = (this.dimvideo.h * parseInt($(e).attr("width")))/parseInt($(e).attr("height"));
  611. // apply thees sizes
  612. $(e)
  613. .css({ width:this.dimvideo.w, height:this.dimvideo.h })
  614. .attr({ width:this.dimvideo.w, height:this.dimvideo.h })
  615. // add some paading to parent for slider display
  616. .parent()
  617. .css({
  618. paddingLeft:this.dimvideo.w*0.15,
  619. paddingright:this.dimvideo.w*0.15
  620. })
  621. .on("click", this.onClickVid.bind(this));
  622. };
  623. Chapter.prototype.onClickVid = function(e){
  624. e.stopPropagation();
  625. e.preventDefault();
  626. console.log('Chapter :: onClickVid '+this.nid, e);
  627. var $vid = $('iframe', e.currentTarget);
  628. $vid.vimeo('paused', function(data){
  629. console.log('paused : ', data);
  630. if(data){
  631. $vid.vimeo('play');
  632. }else{
  633. $vid.vimeo('pause');
  634. }
  635. });
  636. return false;
  637. };
  638. Chapter.prototype.onSlideChange = function(){
  639. console.log('onSlideChange '+this.nid, this.$slider.data('Peppermint').getCurrentPos());
  640. //stop current video playing
  641. this.$vids.eq(this.cur_vid_playing).vimeo('pause');
  642. // start new current video
  643. this.cur_vid_playing = this.$slider.data('Peppermint').getCurrentPos();
  644. this.$vids.eq(this.cur_vid_playing).vimeo('play');
  645. };
  646. Node.initialized = true;
  647. };
  648. this.init();
  649. };//Chapter
  650. /*
  651. __ __________ ____ __________ _____
  652. / / / / ____/ / / __ \/ ____/ __ \/ ___/
  653. / /_/ / __/ / / / /_/ / __/ / /_/ /\__ \
  654. / __ / /___/ /___/ ____/ /___/ _, _/___/ /
  655. /_/ /_/_____/_____/_/ /_____/_/ |_|/____/
  656. */
  657. function randB(min, max){
  658. return Math.random() * (max - min) + min;
  659. };
  660. //+ Jonas Raoni Soares Silva
  661. //@ http://jsfromhell.com/array/shuffle [v1.0]
  662. function shuffleArray(o){ //v1.0
  663. for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
  664. return o;
  665. };
  666. if (!Date.now) {
  667. Date.now = function now() {
  668. return new Date().getTime();
  669. };
  670. }
  671. function translate3d(x, y, z){
  672. // return
  673. };
  674. /*
  675. _ _ __
  676. (_)___ (_) /_
  677. / / __ \/ / __/
  678. / / / / / / /_
  679. /_/_/ /_/_/\__/
  680. */
  681. init();
  682. });
  683. /*
  684. ____ __________ __ ___________________ ___ _ ________ ______ ______________ _ __ __________ ___ __ _________
  685. / __ \/ ____/ __ \/ / / / ____/ ___/_ __/ / | / | / / _/ |/ / |/_ __/ _/ __ \/ | / / / ____/ __ \/ | / |/ / ____/
  686. / /_/ / __/ / / / / / / / __/ \__ \ / / / /| | / |/ // // /|_/ / /| | / / / // / / / |/ / / /_ / /_/ / /| | / /|_/ / __/
  687. / _, _/ /___/ /_/ / /_/ / /___ ___/ // / / ___ |/ /| // // / / / ___ |/ / _/ // /_/ / /| / / __/ / _, _/ ___ |/ / / / /___
  688. /_/ |_/_____/\___\_\____/_____//____//_/ /_/ |_/_/ |_/___/_/ /_/_/ |_/_/ /___/\____/_/ |_/ /_/ /_/ |_/_/ |_/_/ /_/_____/
  689. */
  690. (function() {
  691. var lastTime = 0;
  692. var vendors = ['ms', 'moz', 'webkit', 'o'];
  693. for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
  694. window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
  695. window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
  696. || window[vendors[x]+'CancelRequestAnimationFrame'];
  697. }
  698. if (!window.requestAnimationFrame)
  699. window.requestAnimationFrame = function(callback, element) {
  700. var currTime = new Date().getTime();
  701. var timeToCall = Math.max(0, 16 - (currTime - lastTime));
  702. var id = window.setTimeout(function() { callback(currTime + timeToCall); },
  703. timeToCall);
  704. lastTime = currTime + timeToCall;
  705. return id;
  706. };
  707. if (!window.cancelAnimationFrame)
  708. window.cancelAnimationFrame = function(id) {
  709. clearTimeout(id);
  710. };
  711. }());
  712. /*
  713. ____ ____
  714. / __/_ __/ / / __________________ ___ ____
  715. / /_/ / / / / / / ___/ ___/ ___/ _ \/ _ \/ __ \
  716. / __/ /_/ / / / (__ ) /__/ / / __/ __/ / / /
  717. /_/ \__,_/_/_/ /____/\___/_/ \___/\___/_/ /_/
  718. */
  719. // http://davidwalsh.name/fullscreen
  720. // http://www.sitepoint.com/html5-full-screen-api/
  721. // Find the right method, call on correct element
  722. function launchIntoFullscreen(element) {
  723. if(element.requestFullscreen) {
  724. element.requestFullscreen();
  725. } else if(element.mozRequestFullScreen) {
  726. element.mozRequestFullScreen();
  727. } else if(element.webkitRequestFullscreen) {
  728. element.webkitRequestFullscreen();
  729. } else if(element.msRequestFullscreen) {
  730. element.msRequestFullscreen();
  731. }
  732. }
  733. /*
  734. ____ __ __ _____________ _______
  735. / __ \/ / / / / / ____/ _/ | / / ___/
  736. / /_/ / / / / / / / __ / // |/ /\__ \
  737. / ____/ /___/ /_/ / /_/ // // /| /___/ /
  738. /_/ /_____/\____/\____/___/_/ |_//____/
  739. */
  740. // https://css-tricks.com/snippets/jquery/draggable-without-jquery-ui/
  741. // (function($) {
  742. // $.fn.drags = function(opt) {
  743. // opt = $.extend({handle:"",cursor:"move"}, opt);
  744. // if(opt.handle === "") {
  745. // var $el = this;
  746. // } else {
  747. // var $el = this.find(opt.handle);
  748. // }
  749. // return $el.css('cursor', opt.cursor).on("mousedown", function(e) {
  750. // if(opt.handle === "") {
  751. // var $drag = $(this).addClass('draggable');
  752. // } else {
  753. // var $drag = $(this).addClass('active-handle').parent().addClass('draggable');
  754. // }
  755. // var z_idx = $drag.css('z-index'),
  756. // drg_h = $drag.outerHeight(),
  757. // drg_w = $drag.outerWidth(),
  758. // pos_y = $drag.offset().top + drg_h - e.pageY,
  759. // pos_x = $drag.offset().left + drg_w - e.pageX;
  760. // $drag.css('z-index', 1000).parents().on("mousemove", function(e) {
  761. // $('.draggable').offset({
  762. // top:e.pageY + pos_y - drg_h,
  763. // left:e.pageX + pos_x - drg_w
  764. // }).on("mouseup", function() {
  765. // $(this).removeClass('draggable').css('z-index', z_idx);
  766. // });
  767. // });
  768. // e.preventDefault(); // disable selection
  769. // }).on("mouseup", function() {
  770. // if(opt.handle === "") {
  771. // $(this).removeClass('draggable');
  772. // } else {
  773. // $(this).removeClass('active-handle').parent().removeClass('draggable');
  774. // }
  775. // });
  776. // }
  777. // })(jQuery);
  778. // remove navbar
  779. // $(document).ready(function() {
  780. // if (navigator.userAgent.match(/Android/i)) {
  781. // window.scrollTo(0,0); // reset in case prev not scrolled
  782. // var nPageH = $(document).height();
  783. // var nViewH = window.outerHeight;
  784. // if (nViewH > nPageH) {
  785. // nViewH -= 250;
  786. // $('BODY').css('height',nViewH + 'px');
  787. // }
  788. // window.scrollTo(0,1);
  789. // }
  790. // });
  791. // OR
  792. // function hideAddressBar(){
  793. // if(document.documentElement.scrollHeight<window.outerHeight/window.devicePixelRatio)
  794. // document.documentElement.style.height=(window.outerHeight/window.devicePixelRatio)+'px';
  795. // setTimeout(window.scrollTo(1,1),0);
  796. // }
  797. // window.addEventListener("load",function(){hideAddressBar();});
  798. // window.addEventListener("orientationchange",function(){hideAddressBar();});
  799. // OR
  800. // function hideAddressBar() {
  801. // if(!window.location.hash) {
  802. // if(document.height < window.outerHeight)
  803. // document.body.style.height = (window.outerHeight + 50) + 'px';
  804. // setTimeout( function(){
  805. // window.scrollTo(0, 1);
  806. // document.body.style.height = 'auto';
  807. // }, 50 );
  808. // }
  809. // }
  810. // window.addEventListener("load",function(){hideAddressBar();});
  811. // window.addEventListener("orientationchange",function(){hideAddressBar();});
  812. // Drupal.behaviors.init_theme = function (context) {
  813. // // Growl-style system messages
  814. // $('#messages-and-help > div.messages:not(.processed)')
  815. // .addClass('processed')
  816. // .each(function() {
  817. // // If a message meets these criteria, we don't autoclose
  818. // // - contains a link
  819. // // - is an error or warning
  820. // // - contains a lenghthy amount of text
  821. // if ($('a', this).size() || $(this).is('.error') || $(this).is('.warning') || $(this).text().length > 100) {
  822. // $(this).prepend("<span class='close'>X</span>");
  823. // $('span.close', this).click(function() {
  824. // $(this).parent().slideUp('fast');
  825. // });
  826. // }
  827. // else {
  828. // // This essentially adds a 3 second pause before hiding the message.
  829. // $(this).animate({opacity:1}, 5000, 'linear', function() {
  830. // $(this).slideUp('fast');
  831. // });
  832. // }
  833. // });
  834. // };