script.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607
  1. // @koala-prepend "gui_ck_fw/gui.js"
  2. // @codekit-prepend "gui.js"
  3. (function($) {
  4. Drupal.behaviors.init_theme = {};
  5. Drupal.behaviors.init_theme.attach = function (context) {
  6. // Growl-style system messages
  7. $('#messages-and-help > div.messages:not(.processed)')
  8. .addClass('processed')
  9. .each(function() {
  10. // If a message meets these criteria, we don't autoclose
  11. // - contains a link
  12. // - is an error or warning
  13. // - contains a lenghthy amount of text
  14. if ($('a', this).size() || $(this).is('.error') || $(this).is('.warning') || $(this).text().length > 100) {
  15. $(this).prepend("<span class='close'>X</span>");
  16. $('span.close', this).click(function() {
  17. $(this).parent().slideUp('fast');
  18. });
  19. }
  20. else {
  21. // This essentially adds a 3 second pause before hiding the message.
  22. $(this).animate({opacity:1}, 5000, 'linear', function() {
  23. $(this).slideUp('fast');
  24. });
  25. }
  26. });
  27. };
  28. Drupal.behaviors.materio = {};
  29. Drupal.behaviors.materio.attach = function(context) {};
  30. MaterioBaseTheme = function(){
  31. var _settings = Drupal.settings,
  32. _themeSettings = _settings.materiobasetheme,
  33. _strings = _themeSettings.strings,
  34. _History = window.History,
  35. _this = this,
  36. _$body = $('body'),
  37. _$content = $('#content'),
  38. _jsp,
  39. _$tooltip = $('<div id="tooltip" class="op-hidden">').appendTo('body'),
  40. _$homeUtilities, _$homeBlockDidactique, _hoverHomeDidactique = false, _homeTimeInterval,
  41. _touch = $('html').is('.touch'),
  42. _statePushed = false,
  43. // touch scroll
  44. position = {x:null,y:null},
  45. translate3d_content = 0,
  46. _isLoggedIn = !$('body').is('.not-logged-in'),
  47. _isFrontNotLogged = $('body').is('.front.not-logged-in'),
  48. _isFrontHomeV2 = _$body.is('.home-v2'),
  49. _skrollr,
  50. _isMembershipForm = $('body').is('.page-node-11186'), //$('body').is('.page-node-11187') || ,
  51. // _isBreveMateriauNodePage = $('body').is('.node-type-breve') || $('body').is('.node-type-materiau');
  52. _isBreveMateriauNodePage = _themeSettings.page_callback == 'node_page_view' && (_themeSettings.node_type == 'materiau' || _themeSettings.node_type == 'breve'),
  53. _resizeTimer,
  54. _max_480 = function(){ return (viewport().width < 479); },
  55. _480_768 = function(){ return ( !_max_480() && _max_768() ); },
  56. _max_768 = function(){ return (viewport().width < 767); },
  57. _768_980 = function(){ return ( !_max_768() && _max_980() ); },
  58. _max_980 = function(){ return (viewport().width < 979); },
  59. _980_1200 = function(){ return ( !_max_980() && _max_1200() ); },
  60. _max_1200 = function(){ return (viewport().width < 1199); },
  61. _previewIsOpen = false,
  62. _viewmodes = {
  63. bookmark : 50,
  64. cardsmall : 100,
  65. cardmedium : 210,
  66. cardbig : 425,
  67. cardfull : 850
  68. };
  69. // DEV
  70. var v1, v2, v3, v4, v5; // generic variable used in many cases to avoid to create new memory block with new vars
  71. function init(){
  72. trace('init MaterioBaseTheme');
  73. checkIE();
  74. initHistoryNav();
  75. if(_isFrontNotLogged)
  76. initHome();
  77. if(_isFrontHomeV2)
  78. initHomeV2();
  79. if(_isMembershipForm)
  80. initMembershipForm();
  81. initForms();
  82. initLayout();
  83. initInfinitScroller();
  84. initEvents();
  85. initKeyboardShortcuts();
  86. initViewmodes();
  87. if(_isBreveMateriauNodePage)
  88. $.event.trigger({ type : 'resultschanged', container : '#content>.inner-content'});
  89. setTimeout(function(){
  90. $.event.trigger({ type : 'theme-ready' });
  91. },100);
  92. };
  93. /**
  94. * checkIE
  95. *
  96. */
  97. function checkIE(){
  98. // alert('check ie');
  99. if($('.oldie body').size() && !readCookie('oldie_checked')){
  100. setTimeout(function(){
  101. createCookie('oldie_checked', 1);
  102. alert('Afin de profiter pleinement des fonctionalités de materio.com, nous vous invitons a mettre a jour votre navigateur dans ça denière version. Celui ci n\'étant pas compatible avec les technologie employer par materio.com, vous risquer de rencontrer des difficulter de navigation.');
  103. }, 4000);
  104. }
  105. };
  106. /**
  107. * history navigation
  108. */
  109. function initHistoryNav(){
  110. trace("initHistoryNav _History", _History);
  111. var state = _History.getState();
  112. // _History.log('initial:', state.data, state.title, state.url);
  113. _History.Adapter.bind(window,'statechange',onHistoryStateChange);
  114. $(document).bind('new-history-page', onNewHistoryPage);
  115. };
  116. function onNewHistoryPage(event){
  117. trace('theme :: onNewHistoryPage', event);
  118. var title = event.title.replace(/<(?:.|\n)*?>/gm, '') + ' | ' + _strings.site_name;
  119. // trace('MaterioBaseTheme :: onNewHistoryPage : title', title);
  120. _statePushed = true;
  121. _History.pushState({content:event.content, pagetitle:event.title}, title, event.path);
  122. };
  123. function onHistoryStateChange(event){
  124. trace('theme :: onHistoryStateChange', event);
  125. var state = _History.getState();
  126. _History.log('statechange:', state.data, state.title, state.url);
  127. // google analytics
  128. $.event.trigger({
  129. type : 'record-stat',
  130. path : state.url
  131. });
  132. // TODO: History : empty content if we go back to the homepage
  133. // change the current url for feedbacks
  134. $('input[name=location]','#feedback-form').attr('value', state.url);
  135. $.event.trigger({
  136. type:'materio-page-title-refresh-block',
  137. title : state.data.pagetitle
  138. });
  139. // this condition is to avoid retriggering probleme when a module pushState and then is retriggered by state-changed
  140. if(!_statePushed){
  141. _statePushed = false;
  142. $('.inner-content',_$content).html(state.data.content);
  143. $.event.trigger('history-state-change');
  144. }
  145. };
  146. /**
  147. * home
  148. */
  149. function initHome(){
  150. $('img.lazy', '#block-materio-didactique-materio-didactique-home').each(function(){
  151. var $img = $(this);
  152. $img.attr('src', $img.attr('data-original'));
  153. });
  154. if(_max_768()){
  155. initHomeDidactiqueMobile();
  156. }else{
  157. initHomeDidactiqueDesktop();
  158. }
  159. };
  160. function initHomeDidactiqueMobile(){
  161. // trace('initHomeDidactiqueMobile');
  162. _$homeBlockDidactique = $('#block-materio-didactique-materio-didactique-home');
  163. $('.node-didactique', _$homeBlockDidactique)
  164. .find('.field-name-title-field')
  165. .bind('click', clickOnHomeDidactiqueTitle);
  166. };
  167. function clickOnHomeDidactiqueTitle(e){
  168. // trace('clickOnHomeDidactiqueTitle');
  169. var $node = $(this).parent('.node-didactique');
  170. if($node.is('.opened')){
  171. $node.removeClass('opened');//.slideUp();
  172. }else{
  173. $('.node-didactique', _$homeBlockDidactique).removeClass('opened');//.slideUp();
  174. $node.addClass('opened');//.slideDown();
  175. $('html,body').animate({scrollTop: $node.offset().top - $('#header').h()});
  176. }
  177. };
  178. function initHomeDidactiqueDesktop(){
  179. // trace("initHomeDidactiqueDesktop");
  180. _$homeUtilities = $('#utilities');
  181. _$homeBlockDidactique = $('#block-materio-didactique-materio-didactique-home')
  182. .append('<div class="slides"/>')
  183. .append('<div class="tabs"/>')
  184. // .append('<i class="icon-circle-arrow-up"/><i class="icon-circle-arrow-down"/>')
  185. .bind('mouseenter', function(event) { _hoverHomeDidactique = true; })
  186. .bind('mouseleave', function(event) { _hoverHomeDidactique = false; });
  187. $('.node-didactique',_$homeBlockDidactique).each(function(index) {
  188. if(index){
  189. $(this).addClass('op-hidden');
  190. }else{
  191. $(this).addClass('op-visible');
  192. }
  193. $('.field-name-title-field', this)
  194. .clone()
  195. .addClass(index ? '' : 'active')
  196. .click(function(event){
  197. $(this).addClass('active').siblings().removeClass('active');
  198. _$homeBlockDidactique.find('.node-didactique').removeClass('op-visible').addClass('op-hidden').eq(index).removeClass('op-hidden').addClass('op-visible');
  199. })
  200. .appendTo($('.tabs', _$homeBlockDidactique));
  201. }).appendTo($('.slides', _$homeBlockDidactique));
  202. if(!_touch){
  203. $(document).bind('scroll', function(event){
  204. if($(window).scrollTop() == 0) {
  205. if(_$homeUtilities.is('.closed')){
  206. _$homeUtilities.removeClass('closed');//.removeClass('scroll-closed');
  207. launchHomeDidactiqueInterval();
  208. initLayout();
  209. }
  210. }else{
  211. if(!_$homeUtilities.is('.closed')){
  212. _$homeUtilities.addClass('closed');//.addClass('scroll-closed');
  213. clearInterval(_homeTimeInterval);
  214. initLayout();
  215. }
  216. }
  217. });
  218. }
  219. // launchHomeDidactiqueInterval();
  220. $(document)
  221. .bind('cbox_complete', function(){ clearInterval(_homeTimeInterval); })
  222. .bind('cbox_closed', function(){ launchHomeDidactiqueInterval(); });
  223. $('.side.oops a').click(function(event) {
  224. event.preventDefault();
  225. // $(document).scrollTop(0);
  226. // $('#edit-mail', "#block-materio-user-user-register").focus();
  227. window.location.href = $(this).attr('href');
  228. return false;
  229. });
  230. };
  231. function launchHomeDidactiqueInterval(){
  232. _homeTimeInterval = setInterval(function(){
  233. if(!_hoverHomeDidactique){
  234. var $next = $('.tabs .active', _$homeBlockDidactique).next();
  235. if(!$next.length)
  236. $next = $('.tabs .active', _$homeBlockDidactique).siblings().eq(0);
  237. $next.trigger('click');
  238. }
  239. }, 15000);
  240. };
  241. /**
  242. * home v2
  243. */
  244. function initHomeV2(){
  245. console.log('initHomeV2');
  246. $('.panel-pane.showroom .group-content', '#home-v2')
  247. .attr('data-0', 'transform:translateX(-40em);')
  248. .attr('data-500', 'transform:translateX(0);');
  249. $('.panel-pane.database .group-content', '#home-v2')
  250. .attr('data-550', 'transform:translateX(40em);')
  251. .attr('data-900', 'transform:translateX(0em);');
  252. _skrollr = skrollr.init();
  253. };
  254. /**
  255. * layout
  256. */
  257. function initLayout(){
  258. if(!_max_768() && !$('body').is('.home-v2')){
  259. var height = $('#header').h() + $('#tasks').h();
  260. if(!_max_480() && !_touch ){
  261. height += $('#utilities').h()+15;
  262. }
  263. //$('#main').css('margin-top', height+15);
  264. // $('#container').css('padding-top', height+15);
  265. if(!$('html').is(".ie8")){
  266. $('#container').animate({'padding-top':height}, 300);
  267. }
  268. }
  269. };
  270. /**
  271. * infinit scroll
  272. */
  273. function initInfinitScroller(){
  274. // trace("initInfinitScroller");
  275. $.event.trigger({
  276. type : 'init-scroller-pager',
  277. pager : $('ul.pager', '#content')
  278. });
  279. $(document).bind('scroll', function(event){
  280. // trace('scroll event binded');
  281. checkInfinitScroller();
  282. });
  283. };
  284. function checkInfinitScroller(){
  285. // trace('checkInfinitScroller');
  286. // if(!_touch){
  287. // }else{
  288. if($(window).scrollTop() + $(window).height() > getDocHeight() - 200) {
  289. infinitScrollPager();
  290. }
  291. // }
  292. };
  293. function infinitScrollPager(){
  294. // trace('MaterioBaseTheme :: infinitScrollPager');
  295. if($('ul.pager', '#content').length){
  296. var $nextpage = $('ul.pager .pager-current', '#content').next(),
  297. href = $('a', $nextpage).attr('href');
  298. if(href){
  299. $.event.trigger({ type : 'record-stat', path : href }); // google analytics
  300. $.event.trigger({ type : 'load-scroller-pager', href : href });
  301. }
  302. }
  303. };
  304. /**
  305. * events
  306. */
  307. function initEvents(){
  308. //trace('MaterioBaseTheme :: initEvents');
  309. $(document)
  310. .bind('init-layout', initLayout)
  311. .bind('loading-content', onLoadingContent)
  312. .bind('loaded-content', onLoadedContent)
  313. .bind('resultschanged', onResultsChanged)
  314. .bind('resultscompleted', onResultsCompleted)
  315. .bind('mybookmarks-block-updated', onMybookmarksBlockUpdate)
  316. .bind('mylists-block-builded', onMyListsBlockBuilded)
  317. .bind('mylists-block-updated', onMyListsBlockUpdate)
  318. .bind('flagGlobalAfterLinkUpdate', onAfterFlaging)
  319. .bind('record-stat', onRecordStat)
  320. .bind('view-mode-changed', onViewModeChanged)
  321. .bind('ajax-register-block-loaded', onAjaxRegisterBlockLoaded);
  322. $(window)
  323. .bind('resize', onResizeWindow);
  324. initFlagsEvent();
  325. $('#block-user-login h2, #block-menu-menu-top-menu h2').bind('click', function(event) {
  326. event.preventDefault();
  327. $(this).parent('.block').toggleClass('hovered');
  328. $('.hovered').not($(this).parent('.block')).removeClass('hovered');
  329. return false;
  330. });
  331. $('#block-materio-search-api-materio-search-api-viewmode .viewmode-link').bind('vm-clicked-active', function(event) {
  332. $(this).parents('.block').toggleClass('hovered');
  333. $('.hovered').not($(this).parents('.block')).removeClass('hovered');
  334. });
  335. $('#block-materio-search-api-materio-search-api-viewmode .viewmode-link').bind('vm-clicked', function(event) {
  336. $(this).parents('.block').removeClass('hovered');
  337. $('.hovered').not($(this).parents('.block')).removeClass('hovered');
  338. });
  339. };
  340. function onLoadingContent(event){
  341. _$content.addClass('faded');
  342. $('#materio-search-api-search-form').addClass('loading');
  343. };
  344. function onLoadedContent(event){
  345. // trace('MaterioBaseTheme :: onLoadedContent',event);
  346. _$content.removeClass('faded');
  347. $('#materio-search-api-search-form').removeClass('loading');
  348. };
  349. function onResultsChanged(event){
  350. // trace('MaterioBaseTheme :: onResultsChanged',event);
  351. $(document).scrollTop(0);
  352. focusCard($('#content .search-results, #content .actuality-items').children('.node:first-child'));
  353. onResultsCompleted(event);
  354. };
  355. function onResultsCompleted(event){
  356. // trace('theme :: onResultsCompleted', event);
  357. checkInfinitScroller();
  358. if(event.container != undefined){
  359. // trace('theme :: container is ok : '+event.container)
  360. setTimeout(function(){ // why this time out ?
  361. initCards(event.container);
  362. setUpGrid(event.container);
  363. }, 100);
  364. }
  365. };
  366. function initCards(container){
  367. //TODO : refactore this function, to much features in there
  368. //trace('theme :: initCards', container);
  369. var $container = $(container);
  370. $container.children('.node:not(.listened)')
  371. .bind('mouseenter focused mousemove click mouseleave', onCardEventDispatcher)
  372. .each(function(i){
  373. protectFigures(this);
  374. if(_isLoggedIn){
  375. if(!$container.is('.modal-content')){
  376. // do not add preview btn if we are already on a preview
  377. initPreview(this);
  378. }else{
  379. // if we are on preview mode add a close btn (only for associated materials)
  380. if(!$(this).is(":first-child")){
  381. var $closebtn = $('<section><i class="icon-remove"></i></section>');
  382. $closebtn.bind('click', function(){
  383. $(this).parents('.node-materiau').remove();
  384. });
  385. $('nav.nav', this).append($closebtn);
  386. }
  387. }
  388. }
  389. })
  390. .addClass('listened');
  391. };
  392. function setUpGrid(container){
  393. var $card, top, old_top, col = 0, line = 0;
  394. $(container).children('.node')
  395. .each(function(i){
  396. $card = $(this);
  397. top = $card.offset().top;
  398. if(old_top != top){
  399. line ++;
  400. old_top = top;
  401. col = 0;
  402. }
  403. col ++;
  404. $card.attr('column', col).attr('line', line);
  405. });
  406. };
  407. function onViewModeChanged(event){
  408. if(_isBreveMateriauNodePage){
  409. // if(!_isloadingresults){
  410. $.event.trigger('loading-content');
  411. var url = _settings.basePath+_settings.pathPrefix+'materio_search_api_ajax/node/'+_themeSettings.node_nid;
  412. $.getJSON(url,
  413. function(json){
  414. //trace('json', json);
  415. $.event.trigger('loaded-content');
  416. $('#content>.inner-content').html(json.node);
  417. $.event.trigger({ type : 'resultschanged', container : '#content>.inner-content'});
  418. });
  419. // }
  420. }
  421. };
  422. /**
  423. * CARDS
  424. */
  425. function onCardEventDispatcher(event){
  426. // trace('onCardEvent', event);
  427. var vmode = event.currentTarget.className.match(/vm-([a-z|A-Z]+)/);
  428. var cf = 'on_'+event.type+'_card';
  429. var f = 'on_'+event.type+'_'+vmode[1];
  430. if(typeof _this[cf] == 'function')
  431. _this[cf].call(this, event);
  432. if(typeof _this[f] == 'function')
  433. _this[f].call(this, event);
  434. };
  435. // function initLayoutCardDispatcher($card){
  436. // // trace('$card', $card);
  437. // var vmode = $card.attr('class').match(/vm-([a-z|A-Z]+)/);
  438. // var f = 'init_layout_'+vmode[1];
  439. // if(typeof _this[f] == 'function')
  440. // _this[f].call(this, $card);
  441. // };
  442. /**
  443. * commons Cards
  444. */
  445. // MaterioBaseTheme.prototype.init_layout_card = function($card){
  446. // trace('initLayoutCardBig');
  447. // };
  448. // MaterioBaseTheme.prototype.on_mouseenter_card = function(event){
  449. // //trace('MaterioBaseTheme :: on_mouseenter_card', event);
  450. // };
  451. MaterioBaseTheme.prototype.on_mousemove_card = function(event){
  452. //trace('on_mousemove_Card', event);
  453. focusCard($(this));
  454. };
  455. // MaterioBaseTheme.prototype.on_click_card = function(event){
  456. // trace('on_click_card', event);
  457. // };
  458. // MaterioBaseTheme.prototype.on_mouseleave_card = function(event){
  459. // // trace('on_mouseleave_Card', event);
  460. // };
  461. /**
  462. * cards small
  463. */
  464. // MaterioBaseTheme.prototype.init_layout_cardsmall = function($card){
  465. // trace('initLayoutCardBig');
  466. // };
  467. MaterioBaseTheme.prototype.on_mouseenter_cardsmall = function(event){
  468. //trace('MaterioBaseTheme :: on_mouseenter_cardsmall', event);
  469. showLazyLoadedImages(event.currentTarget);
  470. };
  471. MaterioBaseTheme.prototype.on_focused_cardsmall = function(event){
  472. // trace('theme :: on_focused_cardsmall',event);
  473. v1 = $(this);
  474. v2 = v1.offset();
  475. _$tooltip
  476. .html($('.group-header', this).clone().addClass('smallcard'))
  477. .css({
  478. top:v2.top,//- event.layerY,
  479. left:v2.left + 5 + ($(this).w())// - event.layerX
  480. })
  481. .removeClass('op-hidden').addClass('op-visible');
  482. };
  483. MaterioBaseTheme.prototype.on_mousemove_cardsmall = function(event){
  484. // trace('on_mousemove_Card', event);
  485. horiHoverImagesSwitcher(event);
  486. _$tooltip
  487. .css({
  488. top:event.pageY - _$tooltip.h() -5,// - event.layerY,
  489. left:event.pageX + 5 + ($(this).w() - event.layerX)
  490. });
  491. };
  492. // MaterioBaseTheme.prototype.on_click_cardsmall = function(event){
  493. // trace('on_click_cardsmall', event);
  494. // };
  495. MaterioBaseTheme.prototype.on_mouseleave_cardsmall = function(event){
  496. // trace('on_mouseleave_Card', event);
  497. $('.images img.op-visible', this)
  498. .removeClass('op-visible').addClass('op-hidden')
  499. .eq(0)
  500. .removeClass('op-hidden').addClass('op-visible');
  501. if($(this).is('.focused'))
  502. _$tooltip.removeClass('op-visible').addClass('op-hidden');
  503. };
  504. /**
  505. * cards medium
  506. */
  507. // MaterioBaseTheme.prototype.init_layout_cardmedium = function($card){
  508. // trace('initLayoutCardMedium');
  509. // var ch = $card.h() - $('.group-header', $card).h() -30;
  510. // columnsPage($('.field-name-field-description, .field-name-body', $card), 210, ch);
  511. // };
  512. MaterioBaseTheme.prototype.on_mouseenter_cardmedium = function(event){
  513. // trace('on_mouseenter_cardmedium');
  514. // show lazy images
  515. showLazyLoadedImages(event.currentTarget);
  516. // columnize texts
  517. $card = $(event.currentTarget);
  518. if(!$('.columnized', $card).size() && !$('body').is('.role-7', 'role-2') ){
  519. var ch = $card.h() - $('.group-header', $card).h() -30;
  520. columnsPage($('.field-name-field-description, .field-name-body', $card), 210, ch);
  521. $('.group-side-4', $card).wrapInner('<div class="column-wrapper">').find('.field-item').addClass('dontsplit');
  522. columnsPage($('.group-side-4 .column-wrapper', $card), 210, ch);
  523. }
  524. // add associated materials links
  525. prepareAssociatedMaterials(event.currentTarget);
  526. };
  527. MaterioBaseTheme.prototype.on_mousemove_cardmedium = function(event){
  528. //trace('on_mousemove_cardmedium');
  529. horiHoverImagesSwitcher(event);
  530. };
  531. MaterioBaseTheme.prototype.on_click_cardmedium = function(event){
  532. // trace('on_click_cardmedium', event);
  533. if(!$(event.target).is('.flag') && !$(event.target).parent().is('.flag'))
  534. sideSwitcher(event);
  535. };
  536. MaterioBaseTheme.prototype.on_mouseleave_cardmedium = function(event){
  537. v1 = $('.side.op-visible');
  538. if(v1.is('.oops','.upgrade') || $('.upgrade', v1).size()){
  539. sideSwitcher(event, 0);
  540. }
  541. };
  542. /**
  543. * cards Big
  544. */
  545. // MaterioBaseTheme.prototype.init_layout_cardbig = function($card){
  546. //trace('initLayoutCardBig');
  547. // columnsPage($('.field-name-field-description, .field-name-body', $card), 425, 270);
  548. // };
  549. MaterioBaseTheme.prototype.on_mouseenter_cardbig = function(event){
  550. // trace('on_mouseenter_cardbig');
  551. showLazyLoadedImages(event.currentTarget);
  552. if(!$('.columnized', event.currentTarget).size()){
  553. columnsPage($('.field-name-field-description, .field-name-body', event.currentTarget), 425, 270);
  554. $('.group-4', event.currentTarget).wrapInner('<div class="column-wrapper">').find('.field-item').addClass('dontsplit');
  555. columnsPage($('.group-4 .column-wrapper', event.currentTarget), 425, 270);
  556. }
  557. // add associated materials links
  558. prepareAssociatedMaterials(event.currentTarget);
  559. };
  560. MaterioBaseTheme.prototype.on_mousemove_cardbig = function(event){
  561. // trace('on_mousemove_cardbig');
  562. horiHoverImagesSwitcher(event);
  563. };
  564. MaterioBaseTheme.prototype.on_click_cardbig = function(event){
  565. //trace('on_click_cardbig');
  566. sideSwitcher(event);
  567. };
  568. MaterioBaseTheme.prototype.on_mouseleave_cardbig = function(event){
  569. if($('.side.op-visible').is('.oops') || $('.side.op-visible').is('.upgrade')){
  570. sideSwitcher(event, 0);
  571. }
  572. };
  573. /**
  574. * cards Full
  575. */
  576. // MaterioBaseTheme.prototype.init_layout_cardfull = function($card){
  577. // trace('initLayoutCardFull');
  578. // };
  579. MaterioBaseTheme.prototype.on_mouseenter_cardfull = function(event){
  580. // trace('on_mouseenter_cardfull');
  581. showLazyLoadedImages(event.currentTarget);
  582. // add associated materials links
  583. prepareAssociatedMaterials(event.currentTarget);
  584. };
  585. MaterioBaseTheme.prototype.on_mousemove_cardfull = function(event){
  586. // trace('on_mousemove_cardfull');
  587. horiHoverImagesSwitcher(event);
  588. };
  589. // MaterioBaseTheme.prototype.on_click_cardfull = function(event){
  590. // trace('on_click_cardfull');
  591. // };
  592. // MaterioBaseTheme.prototype.on_mouseleave_cardfull = function(event){
  593. // trace('on_mouseleave_cardfull');
  594. // };
  595. /**
  596. * horiHoverImagesSwitcher
  597. */
  598. function horiHoverImagesSwitcher(event){
  599. // trace('horiHoverImagesSwitcher', event);
  600. var $curtar = $(event.currentTarget);
  601. // TODO : event.layerX doesn't exists in IE8 so we have to calculate the mouse position from offsetX, pageY, etc
  602. // var layerX = event.layerX ? event.layerX : event.clientX - event.currentTarget.offsetLeft;
  603. var layerX = event.clientX - event.currentTarget.offsetLeft;
  604. // trace("layerX", layerX);
  605. if(layerX && $curtar.is('.image-ready') ){ // && !$curtar.is('.image-buged')
  606. var $imgs = $('.group-images figure', event.currentTarget);
  607. if($(event.target).parents('.group-images').length){
  608. var imgw = $imgs.eq(0).w(),
  609. rapport = imgw/$imgs.length,
  610. mx = layerX > imgw ? imgw-1 : layerX,
  611. rapport_pos = Math.floor(mx / rapport);
  612. // trace('rapport_pos = '+rapport_pos+' | event.layerX = '+event.layerX);
  613. rapport_pos = rapport_pos < 0 ? 0 : ( rapport_pos > ($imgs.length - 1) ? $imgs.length - 1 : rapport_pos);
  614. if(!$imgs.eq(rapport_pos).is('.op-visible')){
  615. // google analytics
  616. $.event.trigger({
  617. type : 'record-stat',
  618. categorie : 'Card event',
  619. action : 'image slide switch',
  620. label : rapport_pos
  621. });
  622. $imgs
  623. .removeClass('op-visible').addClass('op-hidden')
  624. .eq(rapport_pos)
  625. .removeClass('op-hidden').addClass('op-visible');
  626. }
  627. }else{
  628. // $curtar.addClass('image-buged');
  629. $imgs.removeClass('op-visible').addClass('op-hidden');
  630. $imgs.eq(0).removeClass('op-hidden').addClass('op-visible');
  631. }
  632. }
  633. };
  634. /**
  635. * protectImages
  636. */
  637. function protectFigures(context){
  638. // trace('protectFigures');
  639. context = context == null ? 'body' : context;
  640. $('figure:not(.protected)', context)
  641. .append('<img class="blank" src="'+_settings.basePath+_themeSettings.themePath+'/img/blank.gif" />')
  642. .addClass('protected')
  643. .bind("contextmenu", function(e){
  644. alert("Cette image est soumise au droit d'auteur.");
  645. return false;
  646. });
  647. };
  648. /**
  649. * initPreview
  650. */
  651. function initPreview(node){
  652. $('nav.nav', node).append($('<section class="preview"><i class="fi-eye"></i></section>').bind('click', onClickPreviewCardBtn));
  653. };
  654. function onClickPreviewCardBtn(event){
  655. // trace('theme :: onClickPreviewCardBtn', event);
  656. event.preventDefault();
  657. //trace('Theme :: previewCard', event);
  658. previewCard($(this).parents('.node'));
  659. return false;
  660. };
  661. function previewCard($card){
  662. // trace('theme :: previewCard',$card);
  663. // get the nid from card class
  664. var matches = $card.attr('class').match(/\bnode-(\d+)\b/);
  665. // select viewmode regarding the window size
  666. var viewmode = false;
  667. var cur_vm = getCurrentViewmode();
  668. for(var vm in _viewmodes)
  669. if(vm != cur_vm && _viewmodes[vm] > _viewmodes[cur_vm] && _viewmodes[vm] < $(window).width())
  670. viewmode = vm;
  671. // ajax load card's node
  672. if(typeof matches[1] !== undefined && viewmode){
  673. $.event.trigger('loading-content');
  674. $.getJSON(_settings.basePath+_settings.pathPrefix+'materio_search_api_ajax/node/'+matches[1],
  675. {viewmode:viewmode},
  676. function(json){
  677. //trace('json', json);
  678. $.event.trigger('loaded-content');
  679. previewLoaded(json);
  680. });
  681. }
  682. };
  683. function previewLoaded(json){
  684. var $modal = $('<div>').addClass('modal-content').append(json.node);
  685. var $modal_wrapper = $('.modal-wrapper');
  686. if(!$modal_wrapper.size())
  687. $modal_wrapper = $('<div>').addClass('modal-wrapper').append($('<div>').addClass('modal-bg')).appendTo('body');
  688. $modal_wrapper
  689. .append($modal)
  690. .bind('click', function(event) {
  691. _previewIsOpen = false;
  692. $(this).remove();
  693. });
  694. $modal.bind('click', function(event) {
  695. event.stopPropagation();
  696. });
  697. _previewIsOpen = true;
  698. initCards('.modal-content');
  699. $.event.trigger({ type : 'previewloaded', container : '.modal-content'});
  700. };
  701. /**
  702. * GRID
  703. */
  704. function moveGridFocus(event, side){
  705. var $old_focused = $('#content .search-results, #content .actuality-items')
  706. .children('.node.focused').first();
  707. var $new_focused;
  708. switch(side){
  709. case 'r':
  710. $new_focused = $old_focused.next();
  711. break;
  712. case 'l':
  713. $new_focused = $old_focused.prev();
  714. break;
  715. case 'u':
  716. case 'd':
  717. var dir = side == "d" ? 1 : -1;
  718. var column = $old_focused.attr('column');
  719. while( ($new_focused == undefined || !$new_focused.size()) && column > 0){
  720. $new_focused = $('.node[column='+column+'][line='+(parseInt($old_focused.attr('line'))+dir)+']');
  721. column --;
  722. }
  723. break;
  724. }
  725. focusCard($new_focused);
  726. docScrollTo($new_focused);
  727. };
  728. function focusCard($card){
  729. // trace('theme :: focusCard', $card);
  730. if(!$card.size() || $card.is('.focused') || $card.parents('.modal-content').size())
  731. return;
  732. $('#content .search-results, #content .actuality-items')
  733. .children('.node.focused')
  734. .removeClass('focused');
  735. $card.addClass('focused');
  736. if(_previewIsOpen){
  737. previewCard($card);
  738. }
  739. $card.trigger('focused');
  740. };
  741. /**
  742. * lazyloadimages
  743. */
  744. // function initLazyLoad(context){
  745. // $('figure:first-child img.lazy', context).lazyload();//{
  746. // container:'#content'
  747. // });
  748. // TODO: propage this event to the card near it to anticipate the mouseenter
  749. // $(context).bind('mousemove', showLazyLoadedImages);
  750. // };
  751. function showLazyLoadedImages(context){
  752. //trace('MaterioBaseTheme :: initLazyLoad : mouseenter', this);
  753. var $this = $(context);
  754. if( !$this.is('.lazy-processed') ){
  755. $this
  756. .addClass('lazy-processed')
  757. // .find('figure img.lazy')
  758. .find('img.lazy')
  759. .each(function(index){
  760. var $img = $(this);
  761. $img.attr('src', $img.attr('data-original')).removeAttr('data-original');
  762. });
  763. setTimeout(function(){
  764. $this.addClass('image-ready');
  765. }, 300);
  766. }
  767. };
  768. /**
  769. * prepareAssociatedMaterials
  770. */
  771. function prepareAssociatedMaterials(card){
  772. // trace('prepareAssociatedMaterials', card);
  773. $('.field-name-field-materiau-ref a:not(.prepared)', card).addClass("prepared").bind('click', onClickAssociatedMaterial);
  774. };
  775. /**
  776. * onClickAssociatedMaterial
  777. */
  778. function onClickAssociatedMaterial(event){
  779. // trace("onClickAssociatedMaterial");
  780. event.preventDefault();
  781. var $this = $(this);
  782. // trace('href', $(this).attr('href'));
  783. var nid = $this.attr('href').match(/^\/(fr|en)\/node\/(\d+)$/)[2];
  784. // trace("nid", nid);
  785. var $prt = $this.parents('.node-materiau');
  786. if($prt.parent().is('.modal-content')){
  787. // if we are on preview mode
  788. // remove already loaded associated
  789. $prt.parent().find('.node-'+nid+'.associated').remove();
  790. loadAssociatedNode($prt, nid);
  791. }else{
  792. // if we are on normal grid mode
  793. var $n = $prt.nextUntil('.node-materiau:not(.associated)').filter('.node-'+nid);
  794. // trace('n', $n);
  795. if($n.size()){
  796. // trace('focus', nid);
  797. // focus on already loaded node
  798. focusCard($n);
  799. // docScrollTo($isnodeexisting);
  800. }else{
  801. // trace('load associated', nid);
  802. loadAssociatedNode($prt, nid);
  803. }
  804. }
  805. return false;
  806. };
  807. function loadAssociatedNode($prt, nid){
  808. // console.log('loadAssociatedNode | nid = '+nid);
  809. var viewmode = $prt.attr('class').match(/vm-([^\s]+)/);
  810. // trace('viewmode match', viewmode);
  811. // if(!_isloadingresults){
  812. $.event.trigger('loading-content');
  813. var url = _settings.basePath+_settings.pathPrefix+'materio_search_api_ajax/node/'+nid;
  814. $.getJSON(url,
  815. {viewmode:viewmode[1]},
  816. function(json){
  817. //trace('json', json);
  818. $.event.trigger('loaded-content');
  819. displayAssociated($prt, $(json.node));
  820. $.event.trigger({
  821. type : 'resultscompleted',
  822. container : '#content .actuality-items, #content .search-results'
  823. });
  824. });
  825. // }
  826. };
  827. function displayAssociated($prt, $n){
  828. $n.addClass('associated').addClass('just-added');
  829. $prt.after($n);
  830. initCards($prt.parent());
  831. (function($n){
  832. setTimeout(function(){
  833. $n.removeClass('just-added');
  834. focusCard($n);
  835. }, 100);
  836. }($n));
  837. };
  838. /**
  839. * sideSwitcher
  840. */
  841. function sideSwitcher(event, delta){
  842. var $sides = $('.side', event.currentTarget);
  843. if($sides.length > 1){
  844. if( typeof delta == 'undefined'){
  845. var delta = 0;
  846. $sides.each(function(i) {
  847. if($(this).is('.op-visible')){
  848. delta = i+1;
  849. return false;
  850. }
  851. });
  852. delta = delta == 0 ? 1 : (delta == $sides.length ? 0 : delta);
  853. }
  854. // google analytics
  855. $.event.trigger({
  856. type : 'record-stat',
  857. categorie : 'Card event',
  858. action : 'side switch',
  859. label : delta
  860. });
  861. $sides.addClass('op-hidden').removeClass('op-visible')
  862. .eq(delta).removeClass('op-hidden').addClass('op-visible');
  863. }
  864. };
  865. /**
  866. * columnsPage
  867. */
  868. function columnsPage($elmt, cw, ch){
  869. // trace('columnsPage');
  870. var cls = Math.ceil($elmt.h()/ch);
  871. $elmt
  872. .addClass('columnized')
  873. .width(cw*cls)
  874. .columnize({
  875. width:cw,
  876. height:ch,
  877. lastNeverTallest:true
  878. });
  879. if(cls > 1){
  880. $elmt.find('.column').each(function(index) {
  881. var $this = $(this);
  882. if(!$this.find('*').length){
  883. $this.prev().addClass('last');
  884. $this.remove();
  885. return true;
  886. }
  887. });
  888. $elmt.find('.column').each(function(index) {
  889. var $this = $(this);
  890. if(!$this.is('.first'))
  891. $this.children('*:first-child').prepend('<span cw="'+cw+'" col="'+(index-1)+'" class="column-switcher prev-column">‹</span> ...');
  892. if(!$this.is('.last'))
  893. $this.children('*:last-child').append('... <span cw="'+cw+'" col="'+(index+1)+'" class="column-switcher next-column">›</span>');
  894. });
  895. $('.column-switcher', $elmt).bind('click', onColumnSwitcherClick);
  896. }
  897. };
  898. function onColumnSwitcherClick(event){
  899. event.preventDefault();
  900. //trace('onColumnSwitcherClick', event);
  901. var $this = $(event.currentTarget),
  902. $columnized = $this.parents('.columnized');
  903. // google analytics
  904. $.event.trigger({
  905. type : 'record-stat',
  906. categorie : 'Card event',
  907. action : 'column switch',
  908. label : $this.attr('col')
  909. });
  910. $columnized.css({
  911. marginLeft : -1 * $this.attr('cw') * $this.attr('col') +'px'
  912. });
  913. return false;
  914. }
  915. /**
  916. * initViewmodes
  917. */
  918. function initViewmodes(){
  919. checkViewmodesResponsive();
  920. };
  921. function checkViewmodesResponsive(){
  922. if(_480_768()){
  923. if($('.viewmode-link.active').is('.viewmode-cardfull')){
  924. $('.viewmode-cardbig').trigger('click');
  925. }
  926. }else if(_max_480()){
  927. if($('.viewmode-link.active').is('.viewmode-cardbig, .viewmode-cardfull')){
  928. $('.viewmode-cardmedium').trigger('click');
  929. }
  930. }
  931. };
  932. function getCurrentViewmode(){
  933. for(var vm in _viewmodes)
  934. if($('.viewmode-link.active.viewmode-'+vm).size())
  935. return vm;
  936. };
  937. /**
  938. * FLAGS
  939. */
  940. function initFlagsEvent(){
  941. $('.bookmarks, .mylists .flaged').children('.node:not(.listened)')
  942. .bind('mouseenter mousemove click mouseleave', onCardEventDispatcher)
  943. // .each(function(event){ initLayoutCardDispatcher($(this)); })
  944. .addClass('listened');
  945. };
  946. function onAfterFlaging(event){
  947. //trace('MaterioBaseTheme :: onAfterFlaging', event);
  948. // WARNING to use event variables i had to hack flag.js from flag module (change the event declaration)
  949. var $target = $(event.link).parents('article.node');
  950. if(event.flagStatus == 'flag'){
  951. $target.addClass('flaged');
  952. }else if(event.flagStatus == 'unflag'){
  953. if($('.flag-lists-entity-links a.unflag-action', $target).length == 0)
  954. $target.removeClass('flaged');
  955. }
  956. };
  957. function onMybookmarksBlockUpdate(event){
  958. initFlagsEvent();
  959. initLayout();
  960. };
  961. function onClickList(event){
  962. //trace('onClickList', event);
  963. var $link = $(event.currentTarget).addClass('active'),
  964. name = $link.attr('name'),
  965. $block = $link.parents('.block'),
  966. $flaged = $('.flaged.'+name, $block).addClass('active');
  967. $link.siblings().removeClass('active');
  968. $flaged.siblings().removeClass('active');
  969. createCookie('materiomyflaglistsopened', name, 1);
  970. $flaged.parents('.mylists').height($flaged.h());
  971. initLayout();
  972. };
  973. function onMyListsBlockUpdate(event){
  974. //trace('MaterioBaseTheme :: onMyListsBlockUpdate', event);
  975. initFlagsEvent();
  976. // initLazyLoad(this);
  977. // TODO: refresh contents (search results) to see new flaglist links.
  978. initLayout();
  979. };
  980. function onMyListsBlockBuilded(event){
  981. //trace('MaterioBaseTheme :: onMyListsBlockBuilded', event);
  982. // initLazyLoad(event.block);
  983. showLazyLoadedImages(event.block);
  984. };
  985. /**
  986. * cards bookmark
  987. */
  988. // MaterioBaseTheme.prototype.init_layout_bookmark = function($card){
  989. // trace('initLayoutCardBig');
  990. // };
  991. MaterioBaseTheme.prototype.on_mouseenter_bookmark = function(event){
  992. //trace('on_mouseenter_bookmark', event);
  993. _$tooltip
  994. .html($('.group-header', this).clone())
  995. .css({
  996. top:event.pageY - _$tooltip.h() -5,//- event.layerY,
  997. left:event.pageX + 5 + ($(this).w() - event.layerX)
  998. })
  999. .removeClass('op-hidden').addClass('op-visible');
  1000. };
  1001. MaterioBaseTheme.prototype.on_mousemove_bookmark = function(event){
  1002. // trace('on_mousemove_Card', event);
  1003. // if(event.layerX)
  1004. // horiHoverImagesSwitcher(event);
  1005. _$tooltip
  1006. .css({
  1007. top:event.pageY - _$tooltip.h() -5,// - event.layerY,
  1008. left:event.pageX + 5 + ($(this).w() - event.layerX)
  1009. });
  1010. };
  1011. // MaterioBaseTheme.prototype.on_click_bookmark = function(event){
  1012. // trace('on_click_bookmark', event);
  1013. // };
  1014. MaterioBaseTheme.prototype.on_mouseleave_bookmark = function(event){
  1015. // trace('on_mouseleave_Card', event);
  1016. $('.images img.op-visible', this)
  1017. .removeClass('op-visible').addClass('op-hidden')
  1018. .eq(0)
  1019. .removeClass('op-hidden').addClass('op-visible');
  1020. _$tooltip.removeClass('op-visible').addClass('op-hidden');
  1021. };
  1022. /**
  1023. * keyboradshortcuts
  1024. */
  1025. function initKeyboardShortcuts(){
  1026. $(document)
  1027. .bind('keydown', 'Shift+:',shortcut_focusSearchField)
  1028. .bind('keydown', '/',shortcut_focusSearchField)
  1029. .bind('keydown', 'Alt+1',shortcut_viewmodeSmall)
  1030. .bind('keydown', 'Alt+2',shortcut_viewmodeMedium)
  1031. .bind('keydown', 'Alt+3',shortcut_viewmodeBig)
  1032. .bind('keydown', 'Alt+4',shortcut_viewmodeFull)
  1033. .bind('keydown', 'space',shortcut_togglePreview)
  1034. .bind('keydown', 'esc',shortcut_closeModaleContent)
  1035. .bind('keydown', 'up',shortcut_onUpArrow)
  1036. .bind('keydown', 'right',shortcut_onRightArrow)
  1037. .bind('keydown', 'down',shortcut_onDownArrow)
  1038. .bind('keydown', 'left',shortcut_onLeftArrow);
  1039. };
  1040. function shortcut_focusSearchField(e){
  1041. // trace("focusSearchField");
  1042. if($('#edit-searchfield').size()){
  1043. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1044. stat_event.action = 'slash';
  1045. stat_event.label = 'Focus on search text field';
  1046. $.event.trigger(stat_event);
  1047. $('#edit-searchfield').focus();
  1048. e.stopPropagation();
  1049. e.preventDefault();
  1050. return false;
  1051. }
  1052. };
  1053. function shortcut_viewmodeSmall(e){
  1054. if($('a.viewmode-link.viewmode-cardsmall').size()){
  1055. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1056. stat_event.action = 'Alt+1';
  1057. stat_event.label = 'Change view mode : card small';
  1058. $.event.trigger(stat_event);
  1059. $('a.viewmode-link.viewmode-cardsmall').click();
  1060. return false;
  1061. }
  1062. };
  1063. function shortcut_viewmodeMedium(e){
  1064. if($('a.viewmode-link.viewmode-cardmedium').size()){
  1065. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1066. stat_event.action = 'Alt+2';
  1067. stat_event.label = 'Change view mode : card medium';
  1068. $.event.trigger(stat_event);
  1069. $('a.viewmode-link.viewmode-cardmedium').click();
  1070. return false;
  1071. }
  1072. };
  1073. function shortcut_viewmodeBig(e){
  1074. if($('a.viewmode-link.viewmode-cardbig').size()){
  1075. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1076. stat_event.action = 'Alt+3';
  1077. stat_event.label = 'Change view mode : card big';
  1078. $.event.trigger(stat_event);
  1079. $('a.viewmode-link.viewmode-cardbig').click();
  1080. return false;
  1081. }
  1082. };
  1083. function shortcut_viewmodeFull(e){
  1084. if($('a.viewmode-link.viewmode-cardfull').size()){
  1085. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1086. stat_event.action = 'Alt+4';
  1087. stat_event.label = 'Change view mode : card full';
  1088. $.event.trigger(stat_event);
  1089. $('a.viewmode-link.viewmode-cardfull').click();
  1090. return false;
  1091. }
  1092. };
  1093. function shortcut_togglePreview(e){
  1094. // trace('theme :: shortcut_togglePreview', e);
  1095. $.event.trigger({
  1096. type : 'record-stat',
  1097. categorie : 'Shortcuts',
  1098. action : 'Space',
  1099. label : 'Space toggle preview'
  1100. });
  1101. if(_previewIsOpen){
  1102. if($('body>.modal-wrapper').size()){
  1103. $('body>.modal-wrapper').click();
  1104. _previewIsOpen = false;
  1105. return false;
  1106. }
  1107. }else{
  1108. previewCard($('#content .search-results, #content .actuality-items').children('.node.focused:first'));
  1109. }
  1110. };
  1111. function shortcut_closeModaleContent(e){
  1112. if($('body>.modal-wrapper').size()){
  1113. $.event.trigger({
  1114. type : 'record-stat',
  1115. categorie : 'Shortcuts',
  1116. action : 'Esc',
  1117. label : 'Esc from modal content'
  1118. });
  1119. $('body>.modal-wrapper').click();
  1120. _previewIsOpen = false;
  1121. return false;
  1122. }
  1123. };
  1124. function shortcut_onUpArrow(e){
  1125. // trace('theme :: shortcut_onTopArrow', e);
  1126. moveGridFocus(e, 'u');
  1127. };
  1128. function shortcut_onRightArrow(e){
  1129. // trace('theme :: shortcut_onRightArrow', e);
  1130. moveGridFocus(e, 'r');
  1131. };
  1132. function shortcut_onDownArrow(e){
  1133. // trace('theme :: shortcut_onDownArrow', e);
  1134. moveGridFocus(e, 'd');
  1135. };
  1136. function shortcut_onLeftArrow(e){
  1137. // trace('theme :: shortcut_onLeftArrow', e);
  1138. moveGridFocus(e, "l");
  1139. };
  1140. /**
  1141. * Misc
  1142. */
  1143. function onResizeWindow(e){
  1144. clearInterval(_resizeTimer);
  1145. _resizeTimer = setTimeout(function(){
  1146. initLayout();
  1147. checkViewmodesResponsive();
  1148. setUpGrid("#content .actuality-items, #content .search-results");
  1149. }, 200);
  1150. };
  1151. /**
  1152. * Statics
  1153. */
  1154. function initMembershipForm() {
  1155. switch(window.location.hash){
  1156. case '#flocon':
  1157. $('#edit-submitted-column-left-membership-options-1').attr('checked', 'checked');
  1158. // $options.trigger('change');
  1159. break;
  1160. case '#etoile':
  1161. $('#edit-submitted-column-left-membership-options-2').attr('checked', 'checked');
  1162. break;
  1163. case '#4etoiles':
  1164. $('#edit-submitted-column-left-membership-options-3').attr('checked', 'checked');
  1165. break;
  1166. // default:
  1167. // switchMembershipShipFormFields($options);
  1168. // break
  1169. }
  1170. $('#webform-component-column-left--membership-options')
  1171. .change(function(event){
  1172. //trace('changed');
  1173. if( $('input[type="radio"]:checked', this).is('#edit-submitted-column-left-membership-options-3') ){
  1174. $('#webform-component-column-right--collaborators').show();
  1175. }else{
  1176. $('#webform-component-column-right--collaborators').hide();
  1177. }
  1178. $('div.form-item.selected', this).removeClass('selected');
  1179. $('input[type="radio"]:checked', this).parents('div.form-item').addClass('selected');
  1180. })
  1181. .trigger('change');
  1182. // $('#webform-component-column-left--membership-options input[checked="checked"]').parents('div.form-item').addClass('selected');
  1183. };
  1184. /** helpers */
  1185. $.fn.h = function(){
  1186. if(this.css('height') == undefined)
  1187. return 0;
  1188. return parseInt(this.css('height')) + parseInt(this.css('padding-top')) + parseInt(this.css('padding-bottom'));
  1189. };
  1190. $.fn.w = function(){
  1191. if(this.css('width') == undefined)
  1192. return 0;
  1193. return parseInt(this.css('width')) + parseInt(this.css('padding-left')) + parseInt(this.css('padding-right'));
  1194. };
  1195. function getDocHeight() {
  1196. var D = document;
  1197. return Math.max(
  1198. Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
  1199. Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
  1200. Math.max(D.body.clientHeight, D.documentElement.clientHeight)
  1201. );
  1202. };
  1203. // http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
  1204. function viewport() {
  1205. var e = window, a = 'inner';
  1206. if (!('innerWidth' in window )) {
  1207. a = 'client';
  1208. e = document.documentElement || document.body;
  1209. }
  1210. return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
  1211. };
  1212. /**
  1213. * Forms
  1214. */
  1215. function initForms(){
  1216. $('#edit-searchfield:not(.processed)')
  1217. .bind('focus', function(event) {
  1218. var $this = $(this);
  1219. //$this.attr('value', 'test');
  1220. // trace('value', $this.val());
  1221. // trace('default', $this.attr('default'));
  1222. if($this.val() == $this.attr('default'))
  1223. $this.val('');
  1224. })
  1225. .bind('focusout', function(event) {
  1226. var $this = $(this);
  1227. if($this.val() == "")
  1228. $this.val($this.attr('default'));
  1229. })
  1230. .addClass('processed');
  1231. hideLabelsFromRegisterForm();
  1232. };
  1233. function hideLabelsFromRegisterForm () {
  1234. var $this, id,label, description;
  1235. $('input.form-text', '#block-user-login, #block-materio-user-user-register, , #block-materio-user-user-createaccount').each(function(i) {
  1236. $this = $(this);
  1237. id = $this.attr('id');
  1238. label = $('label[for='+id+']').hide().text();
  1239. description = $this.parent().find('.description').hide().text();
  1240. if($this.attr('placeholder') == '')
  1241. $this.attr('placeholder',label);
  1242. $this.attr('title',description);
  1243. });
  1244. };
  1245. function onAjaxRegisterBlockLoaded (event) {
  1246. // console.log('onAjaxRegisterBlockLoaded');
  1247. hideLabelsFromRegisterForm();
  1248. };
  1249. /**
  1250. * cookies
  1251. */
  1252. function createCookie(name,value,days) {
  1253. if (days) {
  1254. var date = new Date();
  1255. date.setTime(date.getTime()+(days*24*60*60*1000));
  1256. var expires = "; expires="+date.toGMTString();
  1257. }
  1258. else var expires = "";
  1259. document.cookie = name+"="+value+expires+"; path=/";
  1260. };
  1261. function readCookie(name) {
  1262. var nameEQ = name + "=";
  1263. var ca = document.cookie.split(';');
  1264. for(var i=0;i < ca.length;i++) {
  1265. var c = ca[i];
  1266. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  1267. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  1268. }
  1269. return null;
  1270. };
  1271. function eraseCookie(name) {
  1272. createCookie(name,"",-1);
  1273. };
  1274. /**
  1275. * google analytics
  1276. */
  1277. function onRecordStat(event){
  1278. //trace('onRecordStat', event);
  1279. // path, category, action, opt_label, opt_value
  1280. if(typeof _gaq !== 'undefined'){
  1281. if(event.path){
  1282. _gaq.push(['_trackPageview', event.path]);
  1283. }else{
  1284. _gaq.push(['_trackEvent', event.categorie, event.action, event.label, event.value]);
  1285. }
  1286. }
  1287. };
  1288. /**
  1289. * docScrollTo
  1290. */
  1291. function docScrollTo($e){
  1292. // $(document).scrollTop($e.offset().top);
  1293. if($e.size())
  1294. $('html,body').animate({
  1295. scrollTop: $e.offset().top - $(window).height()*0.5 + $e.height()*0.5
  1296. }, 500);
  1297. };
  1298. init();
  1299. };
  1300. $(document).ready(function() {
  1301. var materiobasetheme = new MaterioBaseTheme();
  1302. });
  1303. /**
  1304. * Attach collapse behavior to the feedback form block.
  1305. */
  1306. Drupal.behaviors.feedbackForm = {
  1307. attach: function (context) {
  1308. $('#block-feedback-form', context).once('feedback', function () {
  1309. var $block = $(this);
  1310. $block.find('span.feedback-link')
  1311. .prepend('<span id="feedback-form-toggle">feedback</span> ')
  1312. .css('cursor', 'pointer')
  1313. .toggle(function () {
  1314. Drupal.feedbackFormToggle($block, false);
  1315. },
  1316. function() {
  1317. Drupal.feedbackFormToggle($block, true);
  1318. }
  1319. );
  1320. $block.find('form').hide();
  1321. $block.show();
  1322. });
  1323. }
  1324. };
  1325. /**
  1326. * Collapse or uncollapse the feedback form block.
  1327. */
  1328. Drupal.feedbackFormToggle = function ($block, enable) {
  1329. $block.find('form').slideToggle('medium');
  1330. if (enable) {
  1331. $('#feedback-form-toggle', $block).html('feedback');
  1332. }
  1333. else {
  1334. $('#feedback-form-toggle', $block).html('feedback (close)');
  1335. }
  1336. };
  1337. //HOME
  1338. //Click Menu and scroll to part of the page
  1339. $(".bdd").addClass('database');
  1340. $('.pane-menu-menu-home-v2 .menu li a').each(function(){
  1341. var link = $(this).attr("href");
  1342. var part = link.replace("/fr/", "");
  1343. $(this).attr('href', '#' +part);
  1344. $(this).click(function(){
  1345. var scrollTo = $('.' + part).offset().top -200;
  1346. $("body").animate({scrollTop: scrollTo}, 2000 );
  1347. })
  1348. });
  1349. })(jQuery);