script.js 57 KB

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