script.js 55 KB

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