jee.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. Drupal.behaviors.init_theme = function (context) {
  2. // Growl-style system messages
  3. $('#messages-and-help > div.messages:not(.processed)')
  4. .addClass('processed')
  5. .each(function() {
  6. // If a message meets these criteria, we don't autoclose
  7. // - contains a link
  8. // - is an error or warning
  9. // - contains a lenghthy amount of text
  10. if ($('a', this).size() || $(this).is('.error') || $(this).is('.warning') || $(this).text().length > 100) {
  11. $(this).prepend("<span class='close'>X</span>");
  12. $('span.close', this).click(function() {
  13. $(this).parent().slideUp('fast');
  14. });
  15. }
  16. else {
  17. // This essentially adds a 3 second pause before hiding the message.
  18. $(this).animate({opacity:1}, 5000, 'linear', function() {
  19. $(this).slideUp('fast');
  20. });
  21. }
  22. });
  23. };
  24. jQuery(document).ready(function($) {
  25. console.log('Hello Jee');
  26. var _$header = $("#header"),
  27. _$chapitres = $('.node-chapitre', '#main'),
  28. _chapitres_len = _$chapitres.length,
  29. _chapters = [],
  30. _$container = $('#main'),
  31. _container = {
  32. w:_$container.width(),
  33. h:_$container.height()
  34. },
  35. _center = {x:_container.w/2,y:_container.h/2},
  36. _nav_pos = {x:0, y:0},
  37. _nav_timer;
  38. function init(){
  39. initChapters();
  40. launchNav();
  41. };
  42. function initChapters(){
  43. // Place each chapters on the ellipse contained on the screen
  44. var angle, a = Math.random() *360;
  45. _$chapitres.each(function(i, e) {
  46. // distribute elements arround the center
  47. angle = (360/_chapitres_len*i+a)*Math.PI/180;
  48. // Lets create the chapter object and place him self
  49. _chapters.push(new Chapter($(e), angle));
  50. });
  51. };
  52. function launchNav(){
  53. var last_clientX,
  54. last_clientY,
  55. td;
  56. $(document)
  57. // DESKTOP EVENTS
  58. .bind('mousedown', function(e){
  59. last_clientX = e.clientX;
  60. last_clientY = e.clientY;
  61. _$chapitres.each(function(i, e) {
  62. td = randB(0.1, 0.3);//Math.random() * (0.3 - 0.1) + 0.1;
  63. $(e).css({"transitionDuration":td+"s"});
  64. });
  65. _nav_timer = setInterval(moveNav, 1000/24);
  66. $(this).bind('mousemove', function(e){
  67. _nav_pos.x += e.clientX - last_clientX;
  68. _nav_pos.y += e.clientY - last_clientY;
  69. last_clientX = e.clientX;
  70. last_clientY = e.clientY;
  71. });
  72. })
  73. .bind('mouseup', function(e){
  74. clearInterval(_nav_timer);
  75. $(this).unbind('mousemove');
  76. })
  77. //
  78. // TOUCH EVENTS - - - - - - - - - - - - - -
  79. //
  80. .bind('touchstart', function(e){
  81. // console.log('touchstart', e);
  82. last_clientX = e.originalEvent.touches[0].clientX;
  83. last_clientY = e.originalEvent.touches[0].clientY;
  84. _$chapitres.each(function(i, e) {
  85. td = randB(0.1, 0.3); //Math.random() * (0.3 - 0.1) + 0.1;
  86. $(e).css({"transitionDuration":td+"s"});
  87. });
  88. _nav_timer = setInterval(moveNav, 1000/12);
  89. })
  90. .bind('touchmove', function(e){
  91. // console.log('touchmove', e);
  92. _nav_pos.x += e.originalEvent.touches[0].clientX - last_clientX;
  93. _nav_pos.y += e.originalEvent.touches[0].clientY - last_clientY;
  94. last_clientX = e.originalEvent.touches[0].clientX;
  95. last_clientY = e.originalEvent.touches[0].clientY;
  96. })
  97. .bind('touchend', function(e){
  98. // console.log("touchend", e);
  99. clearInterval(_nav_timer);
  100. });
  101. // click to preview chapter
  102. $('h2.node-title, .field-name-field-partie:first>.field-name-field-vignette', _$chapitres).bind('click', previewChapter);
  103. $('.links a', _$chapitres).on('click', openChapter);
  104. };
  105. function moveNav(){
  106. // console.log("moveNav");
  107. _$chapitres.each(function(i, e){
  108. $(e).stop(true, false).css({
  109. translate:[_nav_pos.x, _nav_pos.y]
  110. });
  111. // $(e).transition({translate:[_nav_pos.x, _nav_pos.y]}, 200, 'out');
  112. });
  113. _$header.stop(true, false).css({
  114. translate:[_nav_pos.x*0.2, _nav_pos.y*0.2]
  115. // WebkitTransform:'translate('+_nav_pos.x*0.2+', '+_nav_pos.y*0.2+')'
  116. });
  117. };
  118. var $chapt, $parties, px, py;
  119. function previewChapter(e){
  120. e.preventDefault();
  121. // console.log('hello', this);
  122. $chapt = $(this).parents('.node-chapitre');
  123. closePreview($chapt);
  124. $parties = $('.field-name-field-partie', $chapt);
  125. $parties.each(function(i, e) {
  126. switch(i){
  127. case 0:
  128. px=randB(-40, 40); py=randB(40, 60);
  129. break;
  130. case 1:
  131. px=randB(100, 200); py=randB(120,220);
  132. break;
  133. case 2:
  134. px=randB(-200, -100); py=randB(250,320);
  135. break;
  136. case 3:
  137. px=randB(-100, 100); py=randB(320,350)+100;
  138. break;
  139. }
  140. setTimeout(
  141. (function($chapt, $part, px, py){
  142. $part
  143. .css({
  144. translate:[px, py],
  145. // opacity:1
  146. });
  147. // console.log('part', $part);
  148. // console.log('part left', $part.height());
  149. })($chapt, $(e), px, py),10);
  150. }); // each $parties
  151. $chapt.addClass('previewed');
  152. return false;
  153. }; // previewChapter
  154. function closePreview($active){
  155. _$chapitres
  156. .filter('.previewed').not($active)
  157. .removeClass('previewed')
  158. .find('.field-name-field-partie')
  159. .css({transform:"none"});
  160. }; // closePreview
  161. var nid;
  162. function openChapter(e){
  163. e.preventDefault();
  164. nid = $(this).attr("href").match(/^\/node\/(\d+)/);
  165. console.log(nid);
  166. $.getJSON(
  167. '/jee/chapter/'+nid[1],
  168. {},
  169. displayChapter
  170. );
  171. return false;
  172. }; // openChapter
  173. var $chapterwrapper;
  174. function displayChapter(json, textStatus) {
  175. $chapterwrapper = $('<div>').addClass('chapter-wrapper').append(json.node).appendTo(_$container);
  176. // $chapterwrapper.append(json.node);
  177. console.log('displayChapter :: json', json);
  178. console.log('displayChapter :: chapterwrapper', $chapterwrapper);
  179. }; //displayChapter
  180. /*
  181. * Chapter
  182. *
  183. */
  184. function Chapter($e, angle){
  185. this.$e = $e;
  186. this.geom = {
  187. a:angle,
  188. r:0
  189. }
  190. this.pos = {x:0,y:0};
  191. this.translation = {x:0, y:0};
  192. // prototypes
  193. if (typeof Chapter.initialized == "undefined") {
  194. Chapter.prototype.setInitPos = function(){
  195. // console.log("Chapter :: setInitPos", this.$e);
  196. this.geom.c = Math.cos(this.geom.a);
  197. this.geom.s = Math.sin(this.geom.a);
  198. this.geom.abs_c = Math.abs(this.geom.c);
  199. this.geom.abs_s = Math.abs(this.geom.s);
  200. if (this.geom.abs_c * _container.h > this.geom.abs_s * _container.w) {
  201. // It crosses left or right side
  202. this.geom.r = ((_container.w/2) / this.geom.abs_c)*0.5;
  203. }else {
  204. // Top or bottom side
  205. this.geom.r = ((_container.h/2) / this.geom.abs_s)*0.5;
  206. }
  207. // change randomly radius
  208. this.geom.r = randB(this.geom.r, this.geom.r*2);
  209. this.pos.x = Math.round(_center.x+this.geom.r * this.geom.c) - this.$e.outerWidth(true)/2;
  210. this.pos.y = Math.round(_center.y+this.geom.r * -this.geom.s) - this.$e.outerHeight(true)/2;
  211. console.log('this', this);
  212. this.$e.css({
  213. left:this.pos.x,
  214. top:this.pos.y
  215. });
  216. };// setIniPos()
  217. Chapter.prototype.move = function(){
  218. };
  219. Chapter.prototype.preview = function(){
  220. };
  221. Chapter.prototype.closePreview = function(){
  222. };
  223. Chapter.prototype.open = function(){
  224. };
  225. Node.initialized = true;
  226. }
  227. this.setInitPos();
  228. };//Chapter
  229. /* HELPERS */
  230. function randB(min, max){
  231. return Math.random() * (max - min) + min;
  232. }
  233. init();
  234. });