script.js 54 KB

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