script.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  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-100-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-100-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. /*
  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. if(!_max_768()){
  360. var height = $('#header').h() + $('#tasks').h();
  361. if(!_max_480() && !_touch ){
  362. height += $('#utilities').h()+15;
  363. }
  364. //$('#main').css('margin-top', height+15);
  365. // $('#container').css('padding-top', height+15);
  366. if(!$('html').is(".ie8")){
  367. $('#container').animate({'padding-top':height}, 300);
  368. }
  369. }
  370. };
  371. /**
  372. * infinit scroll
  373. */
  374. function initInfinitScroller(){
  375. // trace("initInfinitScroller");
  376. $.event.trigger({
  377. type : 'init-scroller-pager',
  378. pager : $('ul.pager', '#content')
  379. });
  380. $(document).bind('scroll', function(event){
  381. // trace('scroll event binded');
  382. checkInfinitScroller();
  383. });
  384. };
  385. function checkInfinitScroller(){
  386. // trace('checkInfinitScroller');
  387. // if(!_touch){
  388. // }else{
  389. if($(window).scrollTop() + $(window).height() > getDocHeight() - 200) {
  390. infinitScrollPager();
  391. }
  392. // }
  393. };
  394. function infinitScrollPager(){
  395. // trace('MaterioBaseTheme :: infinitScrollPager');
  396. if($('ul.pager', '#content').length){
  397. var $nextpage = $('ul.pager .pager-current', '#content').next(),
  398. href = $('a', $nextpage).attr('href');
  399. if(href){
  400. $.event.trigger({ type : 'record-stat', path : href }); // google analytics
  401. $.event.trigger({ type : 'load-scroller-pager', href : href });
  402. }
  403. }
  404. };
  405. /**
  406. * events
  407. */
  408. function initEvents(){
  409. //trace('MaterioBaseTheme :: initEvents');
  410. $(document)
  411. .bind('init-layout', initLayout)
  412. .bind('loading-content', onLoadingContent)
  413. .bind('loaded-content', onLoadedContent)
  414. .bind('resultschanged', onResultsChanged)
  415. .bind('resultscompleted', onResultsCompleted)
  416. .bind('mybookmarks-block-updated', onMybookmarksBlockUpdate)
  417. .bind('mylists-block-builded', onMyListsBlockBuilded)
  418. .bind('mylists-block-updated', onMyListsBlockUpdate)
  419. .bind('flagGlobalAfterLinkUpdate', onAfterFlaging)
  420. .bind('record-stat', onRecordStat)
  421. .bind('view-mode-changed', onViewModeChanged)
  422. .bind('ajax-register-block-loaded', onAjaxRegisterBlockLoaded);
  423. $(window)
  424. .bind('resize', onResizeWindow);
  425. initFlagsEvent();
  426. $('#block-user-login h2, #block-menu-menu-top-menu h2').bind('click', function(event) {
  427. event.preventDefault();
  428. $(this).parent('.block').toggleClass('hovered');
  429. $('.hovered').not($(this).parent('.block')).removeClass('hovered');
  430. return false;
  431. });
  432. $('#block-materio-search-api-materio-search-api-viewmode .viewmode-link').bind('vm-clicked-active', function(event) {
  433. $(this).parents('.block').toggleClass('hovered');
  434. $('.hovered').not($(this).parents('.block')).removeClass('hovered');
  435. });
  436. $('#block-materio-search-api-materio-search-api-viewmode .viewmode-link').bind('vm-clicked', function(event) {
  437. $(this).parents('.block').removeClass('hovered');
  438. $('.hovered').not($(this).parents('.block')).removeClass('hovered');
  439. });
  440. };
  441. function onLoadingContent(event){
  442. _$content.addClass('faded');
  443. $('#materio-search-api-search-form').addClass('loading');
  444. };
  445. function onLoadedContent(event){
  446. // trace('MaterioBaseTheme :: onLoadedContent',event);
  447. _$content.removeClass('faded');
  448. $('#materio-search-api-search-form').removeClass('loading');
  449. };
  450. function onResultsChanged(event){
  451. // trace('MaterioBaseTheme :: onResultsChanged',event);
  452. $(document).scrollTop(0);
  453. focusCard($('#content .search-results, #content .actuality-items').children('.node:first-child'));
  454. onResultsCompleted(event);
  455. };
  456. function onResultsCompleted(event){
  457. // trace('theme :: onResultsCompleted', event);
  458. checkInfinitScroller();
  459. if(event.container != undefined){
  460. // trace('theme :: container is ok : '+event.container)
  461. setTimeout(function(){ // why this time out ?
  462. initCards(event.container);
  463. setUpGrid(event.container);
  464. }, 100);
  465. }
  466. };
  467. function initCards(container){
  468. trace('theme :: initCards', container);
  469. var $container = $(container);
  470. $container.children('.node:not(.listened)')
  471. .bind('mouseenter focused mousemove click mouseleave', onCardEventDispatcher)
  472. .each(function(i){
  473. protectFigures(this);
  474. if(_isLoggedIn){
  475. if(!$container.is('.modal-content')){
  476. // do not add preview btn if we are already on a preview
  477. initPreview(this);
  478. }else{
  479. // if we are on preview mode add a close btn (only for associated materials)
  480. if(!$(this).is(":first-child")){
  481. var $closebtn = $('<section><i class="icon-remove"></i></section>');
  482. $closebtn.bind('click', function(){
  483. $(this).parents('.node-materiau').remove();
  484. });
  485. $('nav.nav', this).append($closebtn);
  486. }
  487. }
  488. }
  489. })
  490. .addClass('listened');
  491. };
  492. function setUpGrid(container){
  493. var $card, top, old_top, col = 0, line = 0;
  494. $(container).children('.node')
  495. .each(function(i){
  496. $card = $(this);
  497. top = $card.offset().top;
  498. if(old_top != top){
  499. line ++;
  500. old_top = top;
  501. col = 0;
  502. }
  503. col ++;
  504. $card.attr('column', col).attr('line', line);
  505. });
  506. };
  507. function onViewModeChanged(event){
  508. if(_isBreveMateriauNodePage){
  509. // if(!_isloadingresults){
  510. $.event.trigger('loading-content');
  511. var url = _settings.basePath+_settings.pathPrefix+'materio_search_api_ajax/node/'+_themeSettings.node_nid;
  512. $.getJSON(url,
  513. function(json){
  514. //trace('json', json);
  515. $.event.trigger('loaded-content');
  516. $('#content>.inner-content').html(json.node);
  517. $.event.trigger({ type : 'resultschanged', container : '#content>.inner-content'});
  518. });
  519. // }
  520. }
  521. };
  522. /**
  523. * CARDS
  524. */
  525. function onCardEventDispatcher(event){
  526. // trace('onCardEvent', event);
  527. var vmode = event.currentTarget.className.match(/vm-([a-z|A-Z]+)/);
  528. var cf = 'on_'+event.type+'_card';
  529. var f = 'on_'+event.type+'_'+vmode[1];
  530. if(typeof _this[cf] == 'function')
  531. _this[cf].call(this, event);
  532. if(typeof _this[f] == 'function')
  533. _this[f].call(this, event);
  534. };
  535. // function initLayoutCardDispatcher($card){
  536. // // trace('$card', $card);
  537. // var vmode = $card.attr('class').match(/vm-([a-z|A-Z]+)/);
  538. // var f = 'init_layout_'+vmode[1];
  539. // if(typeof _this[f] == 'function')
  540. // _this[f].call(this, $card);
  541. // };
  542. /**
  543. * commons Cards
  544. */
  545. // MaterioBaseTheme.prototype.init_layout_card = function($card){
  546. // trace('initLayoutCardBig');
  547. // };
  548. // MaterioBaseTheme.prototype.on_mouseenter_card = function(event){
  549. // //trace('MaterioBaseTheme :: on_mouseenter_card', event);
  550. // };
  551. MaterioBaseTheme.prototype.on_mousemove_card = function(event){
  552. //trace('on_mousemove_Card', event);
  553. focusCard($(this));
  554. };
  555. // MaterioBaseTheme.prototype.on_click_card = function(event){
  556. // trace('on_click_card', event);
  557. // };
  558. // MaterioBaseTheme.prototype.on_mouseleave_card = function(event){
  559. // // trace('on_mouseleave_Card', event);
  560. // };
  561. /**
  562. * cards small
  563. */
  564. // MaterioBaseTheme.prototype.init_layout_cardsmall = function($card){
  565. // trace('initLayoutCardBig');
  566. // };
  567. MaterioBaseTheme.prototype.on_mouseenter_cardsmall = function(event){
  568. //trace('MaterioBaseTheme :: on_mouseenter_cardsmall', event);
  569. showLazyLoadedImages(event.currentTarget);
  570. };
  571. MaterioBaseTheme.prototype.on_focused_cardsmall = function(event){
  572. // trace('theme :: on_focused_cardsmall',event);
  573. v1 = $(this);
  574. v2 = v1.offset();
  575. _$tooltip
  576. .html($('.group-header', this).clone().addClass('smallcard'))
  577. .css({
  578. top:v2.top,//- event.layerY,
  579. left:v2.left + 5 + ($(this).w())// - event.layerX
  580. })
  581. .removeClass('op-hidden').addClass('op-visible');
  582. };
  583. MaterioBaseTheme.prototype.on_mousemove_cardsmall = function(event){
  584. // trace('on_mousemove_Card', event);
  585. horiHoverImagesSwitcher(event);
  586. _$tooltip
  587. .css({
  588. top:event.pageY - _$tooltip.h() -5,// - event.layerY,
  589. left:event.pageX + 5 + ($(this).w() - event.layerX)
  590. });
  591. };
  592. // MaterioBaseTheme.prototype.on_click_cardsmall = function(event){
  593. // trace('on_click_cardsmall', event);
  594. // };
  595. MaterioBaseTheme.prototype.on_mouseleave_cardsmall = function(event){
  596. // trace('on_mouseleave_Card', event);
  597. $('.images img.op-visible', this)
  598. .removeClass('op-visible').addClass('op-hidden')
  599. .eq(0)
  600. .removeClass('op-hidden').addClass('op-visible');
  601. if($(this).is('.focused'))
  602. _$tooltip.removeClass('op-visible').addClass('op-hidden');
  603. };
  604. /**
  605. * cards medium
  606. */
  607. // MaterioBaseTheme.prototype.init_layout_cardmedium = function($card){
  608. // trace('initLayoutCardMedium');
  609. // var ch = $card.h() - $('.group-header', $card).h() -30;
  610. // columnsPage($('.field-name-field-description, .field-name-body', $card), 210, ch);
  611. // };
  612. MaterioBaseTheme.prototype.on_mouseenter_cardmedium = function(event){
  613. // trace('on_mouseenter_cardmedium');
  614. // show lazy images
  615. showLazyLoadedImages(event.currentTarget);
  616. // columnize texts
  617. $card = $(event.currentTarget);
  618. if(!$('.columnized', $card).size() && !$('body').is('.role-7', 'role-2') ){
  619. var ch = $card.h() - $('.group-header', $card).h() -30;
  620. columnsPage($('.field-name-field-description, .field-name-body', $card), 210, ch);
  621. $('.group-side-4', $card).wrapInner('<div class="column-wrapper">').find('.field-item').addClass('dontsplit');
  622. columnsPage($('.group-side-4 .column-wrapper', $card), 210, ch);
  623. }
  624. // add associated materials links
  625. prepareAssociatedMaterials(event.currentTarget);
  626. };
  627. MaterioBaseTheme.prototype.on_mousemove_cardmedium = function(event){
  628. //trace('on_mousemove_cardmedium');
  629. horiHoverImagesSwitcher(event);
  630. };
  631. MaterioBaseTheme.prototype.on_click_cardmedium = function(event){
  632. // trace('on_click_cardmedium', event);
  633. if(!$(event.target).is('.flag') && !$(event.target).parent().is('.flag'))
  634. sideSwitcher(event);
  635. };
  636. MaterioBaseTheme.prototype.on_mouseleave_cardmedium = function(event){
  637. v1 = $('.side.op-visible');
  638. if(v1.is('.oops','.upgrade') || $('.upgrade', v1).size()){
  639. sideSwitcher(event, 0);
  640. }
  641. };
  642. /**
  643. * cards Big
  644. */
  645. // MaterioBaseTheme.prototype.init_layout_cardbig = function($card){
  646. //trace('initLayoutCardBig');
  647. // columnsPage($('.field-name-field-description, .field-name-body', $card), 425, 270);
  648. // };
  649. MaterioBaseTheme.prototype.on_mouseenter_cardbig = function(event){
  650. // trace('on_mouseenter_cardbig');
  651. showLazyLoadedImages(event.currentTarget);
  652. if(!$('.columnized', event.currentTarget).size()){
  653. columnsPage($('.field-name-field-description, .field-name-body', event.currentTarget), 425, 270);
  654. $('.group-4', event.currentTarget).wrapInner('<div class="column-wrapper">').find('.field-item').addClass('dontsplit');
  655. columnsPage($('.group-4 .column-wrapper', event.currentTarget), 425, 270);
  656. }
  657. // add associated materials links
  658. prepareAssociatedMaterials(event.currentTarget);
  659. };
  660. MaterioBaseTheme.prototype.on_mousemove_cardbig = function(event){
  661. // trace('on_mousemove_cardbig');
  662. horiHoverImagesSwitcher(event);
  663. };
  664. MaterioBaseTheme.prototype.on_click_cardbig = function(event){
  665. //trace('on_click_cardbig');
  666. sideSwitcher(event);
  667. };
  668. MaterioBaseTheme.prototype.on_mouseleave_cardbig = function(event){
  669. if($('.side.op-visible').is('.oops') || $('.side.op-visible').is('.upgrade')){
  670. sideSwitcher(event, 0);
  671. }
  672. };
  673. /**
  674. * cards Full
  675. */
  676. // MaterioBaseTheme.prototype.init_layout_cardfull = function($card){
  677. // trace('initLayoutCardFull');
  678. // };
  679. MaterioBaseTheme.prototype.on_mouseenter_cardfull = function(event){
  680. // trace('on_mouseenter_cardfull');
  681. showLazyLoadedImages(event.currentTarget);
  682. // add associated materials links
  683. prepareAssociatedMaterials(event.currentTarget);
  684. };
  685. MaterioBaseTheme.prototype.on_mousemove_cardfull = function(event){
  686. // trace('on_mousemove_cardfull');
  687. horiHoverImagesSwitcher(event);
  688. };
  689. // MaterioBaseTheme.prototype.on_click_cardfull = function(event){
  690. // trace('on_click_cardfull');
  691. // };
  692. // MaterioBaseTheme.prototype.on_mouseleave_cardfull = function(event){
  693. // trace('on_mouseleave_cardfull');
  694. // };
  695. /**
  696. * horiHoverImagesSwitcher
  697. */
  698. function horiHoverImagesSwitcher(event){
  699. // trace('horiHoverImagesSwitcher', event);
  700. var $curtar = $(event.currentTarget);
  701. var layerX = (event.offsetX || event.pageX - $(event.target).offset().left);
  702. // trace("layerX", layerX);
  703. if(layerX && $curtar.is('.image-ready') ){ // && !$curtar.is('.image-buged')
  704. var $imgs = $('.group-images figure', event.currentTarget);
  705. if($(event.target).parents('.group-images').length){
  706. var imgw = $imgs.eq(0).w(),
  707. rapport = imgw/$imgs.length,
  708. mx = layerX > imgw ? imgw-1 : layerX,
  709. rapport_pos = Math.floor(mx / rapport);
  710. // trace('imgw = '+imgw+' | rapport_pos = '+rapport_pos+' | layerX = '+layerX);
  711. rapport_pos = rapport_pos < 0 ? 0 : ( rapport_pos > ($imgs.length - 1) ? $imgs.length - 1 : rapport_pos);
  712. // trace('rapport_pos', rapport_pos);
  713. if(!$imgs.eq(rapport_pos).is('.op-visible')){
  714. // google analytics
  715. $.event.trigger({
  716. type : 'record-stat',
  717. categorie : 'Card event',
  718. action : 'image slide switch',
  719. label : rapport_pos
  720. });
  721. $imgs
  722. .removeClass('op-visible').addClass('op-hidden')
  723. .eq(rapport_pos)
  724. .removeClass('op-hidden').addClass('op-visible');
  725. }
  726. }else{
  727. // $curtar.addClass('image-buged');
  728. $imgs.removeClass('op-visible').addClass('op-hidden');
  729. $imgs.eq(0).removeClass('op-hidden').addClass('op-visible');
  730. }
  731. }
  732. };
  733. /**
  734. * protectImages
  735. */
  736. function protectFigures(context){
  737. // trace('protectFigures');
  738. context = context == null ? 'body' : context;
  739. $('figure:not(.protected)', context)
  740. .append('<img class="blank" src="'+_settings.basePath+_themeSettings.themePath+'/img/blank.gif" />')
  741. .addClass('protected')
  742. .bind("contextmenu", function(e){
  743. alert("Cette image est soumise au droit d'auteur.");
  744. return false;
  745. });
  746. };
  747. /**
  748. * initPreview
  749. */
  750. function initPreview(node){
  751. $('nav.nav', node).append($('<section class="preview"><i class="fi-eye"></i></section>').bind('click', onClickPreviewCardBtn));
  752. };
  753. function onClickPreviewCardBtn(event){
  754. // trace('theme :: onClickPreviewCardBtn', event);
  755. event.preventDefault();
  756. //trace('Theme :: previewCard', event);
  757. previewCard($(this).parents('.node'));
  758. return false;
  759. };
  760. function previewCard($card){
  761. // trace('theme :: previewCard',$card);
  762. // get the nid from card class
  763. var matches = $card.attr('class').match(/\bnode-(\d+)\b/);
  764. // select viewmode regarding the window size
  765. var viewmode = false;
  766. var cur_vm = getCurrentViewmode();
  767. for(var vm in _viewmodes)
  768. if(vm != cur_vm && _viewmodes[vm] > _viewmodes[cur_vm] && _viewmodes[vm] < $(window).width())
  769. viewmode = vm;
  770. // ajax load card's node
  771. if(typeof matches[1] !== undefined && viewmode){
  772. $.event.trigger('loading-content');
  773. $.getJSON(_settings.basePath+_settings.pathPrefix+'materio_search_api_ajax/node/'+matches[1],
  774. {viewmode:viewmode},
  775. function(json){
  776. //trace('json', json);
  777. $.event.trigger('loaded-content');
  778. previewLoaded(json);
  779. });
  780. }
  781. };
  782. function previewLoaded(json){
  783. var $modal = $('<div>').addClass('modal-content').append(json.node);
  784. var $modal_wrapper = $('.modal-wrapper');
  785. if(!$modal_wrapper.size())
  786. $modal_wrapper = $('<div>').addClass('modal-wrapper').append($('<div>').addClass('modal-bg')).appendTo('body');
  787. $modal_wrapper
  788. .append($modal)
  789. .bind('click', function(event) {
  790. _previewIsOpen = false;
  791. $(this).remove();
  792. });
  793. $modal.bind('click', function(event) {
  794. event.stopPropagation();
  795. });
  796. _previewIsOpen = true;
  797. initCards('.modal-content');
  798. $.event.trigger({ type : 'previewloaded', container : '.modal-content'});
  799. };
  800. /**
  801. * GRID
  802. */
  803. function moveGridFocus(event, side){
  804. var $old_focused = $('#content .search-results, #content .actuality-items')
  805. .children('.node.focused').first();
  806. var $new_focused;
  807. switch(side){
  808. case 'r':
  809. $new_focused = $old_focused.next();
  810. break;
  811. case 'l':
  812. $new_focused = $old_focused.prev();
  813. break;
  814. case 'u':
  815. case 'd':
  816. var dir = side == "d" ? 1 : -1;
  817. var column = $old_focused.attr('column');
  818. while( ($new_focused == undefined || !$new_focused.size()) && column > 0){
  819. $new_focused = $('.node[column='+column+'][line='+(parseInt($old_focused.attr('line'))+dir)+']');
  820. column --;
  821. }
  822. break;
  823. }
  824. focusCard($new_focused);
  825. docScrollTo($new_focused);
  826. };
  827. function focusCard($card){
  828. // trace('theme :: focusCard', $card);
  829. if(!$card.size() || $card.is('.focused') || $card.parents('.modal-content').size())
  830. return;
  831. $('#content .search-results, #content .actuality-items')
  832. .children('.node.focused')
  833. .removeClass('focused');
  834. $card.addClass('focused');
  835. if(_previewIsOpen){
  836. previewCard($card);
  837. }
  838. $card.trigger('focused');
  839. };
  840. /**
  841. * lazyloadimages
  842. */
  843. // function initLazyLoad(context){
  844. // $('figure:first-child img.lazy', context).lazyload();//{
  845. // container:'#content'
  846. // });
  847. // TODO: propage this event to the card near it to anticipate the mouseenter
  848. // $(context).bind('mousemove', showLazyLoadedImages);
  849. // };
  850. function showLazyLoadedImages(context){
  851. //trace('MaterioBaseTheme :: initLazyLoad : mouseenter', this);
  852. var $this = $(context);
  853. if( !$this.is('.lazy-processed') ){
  854. $this
  855. .addClass('lazy-processed')
  856. // .find('figure img.lazy')
  857. .find('img.lazy')
  858. .each(function(index){
  859. var $img = $(this);
  860. $img.attr('src', $img.attr('data-original')).removeAttr('data-original');
  861. });
  862. setTimeout(function(){
  863. $this.addClass('image-ready');
  864. }, 300);
  865. }
  866. };
  867. /**
  868. * prepareAssociatedMaterials
  869. */
  870. function prepareAssociatedMaterials(card){
  871. // trace('prepareAssociatedMaterials', card);
  872. $('.field-name-field-materiau-ref a:not(.prepared)', card).addClass("prepared").bind('click', onClickAssociatedMaterial);
  873. };
  874. /**
  875. * onClickAssociatedMaterial
  876. */
  877. function onClickAssociatedMaterial(event){
  878. // trace("onClickAssociatedMaterial");
  879. event.preventDefault();
  880. var $this = $(this);
  881. // trace('href', $(this).attr('href'));
  882. var nid = $this.attr('href').match(/^\/(fr|en)\/node\/(\d+)$/)[2];
  883. // trace("nid", nid);
  884. var $prt = $this.parents('.node-materiau');
  885. if($prt.parent().is('.modal-content')){
  886. // if we are on preview mode
  887. // remove already loaded associated
  888. $prt.parent().find('.node-'+nid+'.associated').remove();
  889. loadAssociatedNode($prt, nid);
  890. }else{
  891. // if we are on normal grid mode
  892. var $n = $prt.nextUntil('.node-materiau:not(.associated)').filter('.node-'+nid);
  893. // trace('n', $n);
  894. if($n.size()){
  895. // trace('focus', nid);
  896. // focus on already loaded node
  897. focusCard($n);
  898. // docScrollTo($isnodeexisting);
  899. }else{
  900. // trace('load associated', nid);
  901. loadAssociatedNode($prt, nid);
  902. }
  903. }
  904. return false;
  905. };
  906. function loadAssociatedNode($prt, nid){
  907. // console.log('loadAssociatedNode | nid = '+nid);
  908. var viewmode = $prt.attr('class').match(/vm-([^\s]+)/);
  909. // trace('viewmode match', viewmode);
  910. // if(!_isloadingresults){
  911. $.event.trigger('loading-content');
  912. var url = _settings.basePath+_settings.pathPrefix+'materio_search_api_ajax/node/'+nid;
  913. $.getJSON(url,
  914. {viewmode:viewmode[1]},
  915. function(json){
  916. //trace('json', json);
  917. $.event.trigger('loaded-content');
  918. displayAssociated($prt, $(json.node));
  919. $.event.trigger({
  920. type : 'resultscompleted',
  921. container : '#content .actuality-items, #content .search-results'
  922. });
  923. });
  924. // }
  925. };
  926. function displayAssociated($prt, $n){
  927. $n.addClass('associated').addClass('just-added');
  928. $prt.after($n);
  929. initCards($prt.parent());
  930. (function($n){
  931. setTimeout(function(){
  932. $n.removeClass('just-added');
  933. focusCard($n);
  934. }, 100);
  935. }($n));
  936. };
  937. /**
  938. * sideSwitcher
  939. */
  940. function sideSwitcher(event, delta){
  941. var $sides = $('.side', event.currentTarget);
  942. if($sides.length > 1){
  943. if( typeof delta == 'undefined'){
  944. var delta = 0;
  945. $sides.each(function(i) {
  946. if($(this).is('.op-visible')){
  947. delta = i+1;
  948. return false;
  949. }
  950. });
  951. delta = delta == 0 ? 1 : (delta == $sides.length ? 0 : delta);
  952. }
  953. // google analytics
  954. $.event.trigger({
  955. type : 'record-stat',
  956. categorie : 'Card event',
  957. action : 'side switch',
  958. label : delta
  959. });
  960. $sides.addClass('op-hidden').removeClass('op-visible')
  961. .eq(delta).removeClass('op-hidden').addClass('op-visible');
  962. }
  963. };
  964. /**
  965. * columnsPage
  966. */
  967. function columnsPage($elmt, cw, ch){
  968. // trace('columnsPage');
  969. var cls = Math.ceil($elmt.h()/ch);
  970. $elmt
  971. .addClass('columnized')
  972. .width(cw*cls)
  973. .columnize({
  974. width:cw,
  975. height:ch,
  976. lastNeverTallest:true
  977. });
  978. if(cls > 1){
  979. $elmt.find('.column').each(function(index) {
  980. var $this = $(this);
  981. if(!$this.find('*').length){
  982. $this.prev().addClass('last');
  983. $this.remove();
  984. return true;
  985. }
  986. });
  987. $elmt.find('.column').each(function(index) {
  988. var $this = $(this);
  989. if(!$this.is('.first'))
  990. $this.children('*:first-child').prepend('<span cw="'+cw+'" col="'+(index-1)+'" class="column-switcher prev-column">‹</span> ...');
  991. if(!$this.is('.last'))
  992. $this.children('*:last-child').append('... <span cw="'+cw+'" col="'+(index+1)+'" class="column-switcher next-column">›</span>');
  993. });
  994. $('.column-switcher', $elmt).bind('click', onColumnSwitcherClick);
  995. }
  996. };
  997. function onColumnSwitcherClick(event){
  998. event.preventDefault();
  999. //trace('onColumnSwitcherClick', event);
  1000. var $this = $(event.currentTarget),
  1001. $columnized = $this.parents('.columnized');
  1002. // google analytics
  1003. $.event.trigger({
  1004. type : 'record-stat',
  1005. categorie : 'Card event',
  1006. action : 'column switch',
  1007. label : $this.attr('col')
  1008. });
  1009. $columnized.css({
  1010. marginLeft : -1 * $this.attr('cw') * $this.attr('col') +'px'
  1011. });
  1012. return false;
  1013. }
  1014. /**
  1015. * initViewmodes
  1016. */
  1017. function initViewmodes(){
  1018. checkViewmodesResponsive();
  1019. };
  1020. function checkViewmodesResponsive(){
  1021. if(_480_768()){
  1022. if($('.viewmode-link.active').is('.viewmode-cardfull')){
  1023. $('.viewmode-cardbig').trigger('click');
  1024. }
  1025. }else if(_max_480()){
  1026. if($('.viewmode-link.active').is('.viewmode-cardbig, .viewmode-cardfull')){
  1027. $('.viewmode-cardmedium').trigger('click');
  1028. }
  1029. }
  1030. };
  1031. function getCurrentViewmode(){
  1032. for(var vm in _viewmodes)
  1033. if($('.viewmode-link.active.viewmode-'+vm).size())
  1034. return vm;
  1035. };
  1036. /**
  1037. * FLAGS
  1038. */
  1039. function initFlagsEvent(){
  1040. $('.bookmarks, .mylists .flaged').children('.node:not(.listened)')
  1041. .bind('mouseenter mousemove click mouseleave', onCardEventDispatcher)
  1042. // .each(function(event){ initLayoutCardDispatcher($(this)); })
  1043. .addClass('listened');
  1044. };
  1045. function onAfterFlaging(event){
  1046. //trace('MaterioBaseTheme :: onAfterFlaging', event);
  1047. // WARNING to use event variables i had to hack flag.js from flag module (change the event declaration)
  1048. var $target = $(event.link).parents('article.node');
  1049. if(event.flagStatus == 'flag'){
  1050. $target.addClass('flaged');
  1051. }else if(event.flagStatus == 'unflag'){
  1052. if($('.flag-lists-entity-links a.unflag-action', $target).length == 0)
  1053. $target.removeClass('flaged');
  1054. }
  1055. };
  1056. function onMybookmarksBlockUpdate(event){
  1057. initFlagsEvent();
  1058. initLayout();
  1059. };
  1060. function onClickList(event){
  1061. //trace('onClickList', event);
  1062. var $link = $(event.currentTarget).addClass('active'),
  1063. name = $link.attr('name'),
  1064. $block = $link.parents('.block'),
  1065. $flaged = $('.flaged.'+name, $block).addClass('active');
  1066. $link.siblings().removeClass('active');
  1067. $flaged.siblings().removeClass('active');
  1068. createCookie('materiomyflaglistsopened', name, 1);
  1069. $flaged.parents('.mylists').height($flaged.h());
  1070. initLayout();
  1071. };
  1072. function onMyListsBlockUpdate(event){
  1073. //trace('MaterioBaseTheme :: onMyListsBlockUpdate', event);
  1074. initFlagsEvent();
  1075. // initLazyLoad(this);
  1076. // TODO: refresh contents (search results) to see new flaglist links.
  1077. initLayout();
  1078. };
  1079. function onMyListsBlockBuilded(event){
  1080. //trace('MaterioBaseTheme :: onMyListsBlockBuilded', event);
  1081. // initLazyLoad(event.block);
  1082. showLazyLoadedImages(event.block);
  1083. };
  1084. /**
  1085. * cards bookmark
  1086. */
  1087. // MaterioBaseTheme.prototype.init_layout_bookmark = function($card){
  1088. // trace('initLayoutCardBig');
  1089. // };
  1090. MaterioBaseTheme.prototype.on_mouseenter_bookmark = function(event){
  1091. //trace('on_mouseenter_bookmark', event);
  1092. _$tooltip
  1093. .html($('.group-header', this).clone())
  1094. .css({
  1095. top:event.pageY - _$tooltip.h() -5,//- event.layerY,
  1096. left:event.pageX + 5 + ($(this).w() - event.layerX)
  1097. })
  1098. .removeClass('op-hidden').addClass('op-visible');
  1099. };
  1100. MaterioBaseTheme.prototype.on_mousemove_bookmark = function(event){
  1101. // trace('on_mousemove_Card', event);
  1102. // if(event.layerX)
  1103. // horiHoverImagesSwitcher(event);
  1104. _$tooltip
  1105. .css({
  1106. top:event.pageY - _$tooltip.h() -5,// - event.layerY,
  1107. left:event.pageX + 5 + ($(this).w() - event.layerX)
  1108. });
  1109. };
  1110. // MaterioBaseTheme.prototype.on_click_bookmark = function(event){
  1111. // trace('on_click_bookmark', event);
  1112. // };
  1113. MaterioBaseTheme.prototype.on_mouseleave_bookmark = function(event){
  1114. // trace('on_mouseleave_Card', event);
  1115. $('.images img.op-visible', this)
  1116. .removeClass('op-visible').addClass('op-hidden')
  1117. .eq(0)
  1118. .removeClass('op-hidden').addClass('op-visible');
  1119. _$tooltip.removeClass('op-visible').addClass('op-hidden');
  1120. };
  1121. /**
  1122. * keyboradshortcuts
  1123. */
  1124. function initKeyboardShortcuts(){
  1125. $(document)
  1126. .bind('keydown', 'Shift+:',shortcut_focusSearchField)
  1127. .bind('keydown', '/',shortcut_focusSearchField)
  1128. .bind('keydown', 'Alt+1',shortcut_viewmodeSmall)
  1129. .bind('keydown', 'Alt+2',shortcut_viewmodeMedium)
  1130. .bind('keydown', 'Alt+3',shortcut_viewmodeBig)
  1131. .bind('keydown', 'Alt+4',shortcut_viewmodeFull)
  1132. .bind('keydown', 'space',shortcut_togglePreview)
  1133. .bind('keydown', 'esc',shortcut_closeModaleContent)
  1134. .bind('keydown', 'up',shortcut_onUpArrow)
  1135. .bind('keydown', 'right',shortcut_onRightArrow)
  1136. .bind('keydown', 'down',shortcut_onDownArrow)
  1137. .bind('keydown', 'left',shortcut_onLeftArrow);
  1138. };
  1139. function shortcut_focusSearchField(e){
  1140. // trace("focusSearchField");
  1141. if($('#edit-searchfield').size()){
  1142. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1143. stat_event.action = 'slash';
  1144. stat_event.label = 'Focus on search text field';
  1145. $.event.trigger(stat_event);
  1146. $('#edit-searchfield').focus();
  1147. e.stopPropagation();
  1148. e.preventDefault();
  1149. return false;
  1150. }
  1151. };
  1152. function shortcut_viewmodeSmall(e){
  1153. if($('a.viewmode-link.viewmode-cardsmall').size()){
  1154. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1155. stat_event.action = 'Alt+1';
  1156. stat_event.label = 'Change view mode : card small';
  1157. $.event.trigger(stat_event);
  1158. $('a.viewmode-link.viewmode-cardsmall').click();
  1159. return false;
  1160. }
  1161. };
  1162. function shortcut_viewmodeMedium(e){
  1163. if($('a.viewmode-link.viewmode-cardmedium').size()){
  1164. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1165. stat_event.action = 'Alt+2';
  1166. stat_event.label = 'Change view mode : card medium';
  1167. $.event.trigger(stat_event);
  1168. $('a.viewmode-link.viewmode-cardmedium').click();
  1169. return false;
  1170. }
  1171. };
  1172. function shortcut_viewmodeBig(e){
  1173. if($('a.viewmode-link.viewmode-cardbig').size()){
  1174. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1175. stat_event.action = 'Alt+3';
  1176. stat_event.label = 'Change view mode : card big';
  1177. $.event.trigger(stat_event);
  1178. $('a.viewmode-link.viewmode-cardbig').click();
  1179. return false;
  1180. }
  1181. };
  1182. function shortcut_viewmodeFull(e){
  1183. if($('a.viewmode-link.viewmode-cardfull').size()){
  1184. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1185. stat_event.action = 'Alt+4';
  1186. stat_event.label = 'Change view mode : card full';
  1187. $.event.trigger(stat_event);
  1188. $('a.viewmode-link.viewmode-cardfull').click();
  1189. return false;
  1190. }
  1191. };
  1192. function shortcut_togglePreview(e){
  1193. // trace('theme :: shortcut_togglePreview', e);
  1194. $.event.trigger({
  1195. type : 'record-stat',
  1196. categorie : 'Shortcuts',
  1197. action : 'Space',
  1198. label : 'Space toggle preview'
  1199. });
  1200. if(_previewIsOpen){
  1201. if($('body>.modal-wrapper').size()){
  1202. $('body>.modal-wrapper').click();
  1203. _previewIsOpen = false;
  1204. return false;
  1205. }
  1206. }else{
  1207. previewCard($('#content .search-results, #content .actuality-items').children('.node.focused:first'));
  1208. }
  1209. };
  1210. function shortcut_closeModaleContent(e){
  1211. if($('body>.modal-wrapper').size()){
  1212. $.event.trigger({
  1213. type : 'record-stat',
  1214. categorie : 'Shortcuts',
  1215. action : 'Esc',
  1216. label : 'Esc from modal content'
  1217. });
  1218. $('body>.modal-wrapper').click();
  1219. _previewIsOpen = false;
  1220. return false;
  1221. }
  1222. };
  1223. function shortcut_onUpArrow(e){
  1224. // trace('theme :: shortcut_onTopArrow', e);
  1225. moveGridFocus(e, 'u');
  1226. };
  1227. function shortcut_onRightArrow(e){
  1228. // trace('theme :: shortcut_onRightArrow', e);
  1229. moveGridFocus(e, 'r');
  1230. };
  1231. function shortcut_onDownArrow(e){
  1232. // trace('theme :: shortcut_onDownArrow', e);
  1233. moveGridFocus(e, 'd');
  1234. };
  1235. function shortcut_onLeftArrow(e){
  1236. // trace('theme :: shortcut_onLeftArrow', e);
  1237. moveGridFocus(e, "l");
  1238. };
  1239. /**
  1240. * Misc
  1241. */
  1242. function onResizeWindow(e){
  1243. clearInterval(_resizeTimer);
  1244. _resizeTimer = setTimeout(function(){
  1245. initLayout();
  1246. checkViewmodesResponsive();
  1247. setUpGrid("#content .actuality-items, #content .search-results");
  1248. }, 200);
  1249. };
  1250. /**
  1251. * Statics
  1252. */
  1253. function initMembershipForm() {
  1254. switch(window.location.hash){
  1255. case '#1':
  1256. $('#edit-submitted-column-left-membership-options-1').attr('checked', 'checked');
  1257. // $options.trigger('change');
  1258. break;
  1259. case '#2':
  1260. $('#edit-submitted-column-left-membership-options-2').attr('checked', 'checked');
  1261. break;
  1262. case '#3':
  1263. $('#edit-submitted-column-left-membership-options-3').attr('checked', 'checked');
  1264. break;
  1265. // default:
  1266. // switchMembershipShipFormFields($options);
  1267. // break
  1268. }
  1269. $('#webform-component-column-left--membership-options')
  1270. .change(function(event){
  1271. //trace('changed');
  1272. if( $('input[type="radio"]:checked', this).is('#edit-submitted-column-left-membership-options-3') ){
  1273. $('#webform-component-column-right--collaborators').show();
  1274. }else{
  1275. $('#webform-component-column-right--collaborators').hide();
  1276. }
  1277. $('div.form-item.selected', this).removeClass('selected');
  1278. $('input[type="radio"]:checked', this).parents('div.form-item').addClass('selected');
  1279. })
  1280. .trigger('change');
  1281. // $('#webform-component-column-left--membership-options input[checked="checked"]').parents('div.form-item').addClass('selected');
  1282. };
  1283. /** helpers */
  1284. $.fn.h = function(){
  1285. if(this.css('height') == undefined)
  1286. return 0;
  1287. return parseInt(this.css('height')) + parseInt(this.css('padding-top')) + parseInt(this.css('padding-bottom'));
  1288. };
  1289. $.fn.w = function(){
  1290. if(this.css('width') == undefined)
  1291. return 0;
  1292. return parseInt(this.css('width')) + parseInt(this.css('padding-left')) + parseInt(this.css('padding-right'));
  1293. };
  1294. function getDocHeight() {
  1295. var D = document;
  1296. return Math.max(
  1297. Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
  1298. Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
  1299. Math.max(D.body.clientHeight, D.documentElement.clientHeight)
  1300. );
  1301. };
  1302. // http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
  1303. function viewport() {
  1304. var e = window, a = 'inner';
  1305. if (!('innerWidth' in window )) {
  1306. a = 'client';
  1307. e = document.documentElement || document.body;
  1308. }
  1309. return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
  1310. };
  1311. /**
  1312. * Forms
  1313. */
  1314. function initForms(){
  1315. $('#edit-searchfield:not(.processed)')
  1316. .bind('focus', function(event) {
  1317. var $this = $(this);
  1318. //$this.attr('value', 'test');
  1319. // trace('value', $this.val());
  1320. // trace('default', $this.attr('default'));
  1321. if($this.val() == $this.attr('default'))
  1322. $this.val('');
  1323. })
  1324. .bind('focusout', function(event) {
  1325. var $this = $(this);
  1326. if($this.val() == "")
  1327. $this.val($this.attr('default'));
  1328. })
  1329. .addClass('processed');
  1330. hideLabelsFromRegisterForm();
  1331. };
  1332. function hideLabelsFromRegisterForm () {
  1333. var $this, id,label, description;
  1334. $('input.form-text', '#block-user-login, #block-materio-user-user-register, .pane-materio-user-user-register, #block-materio-user-user-createaccount').each(function(i) {
  1335. $this = $(this);
  1336. id = $this.attr('id');
  1337. label = $('label[for='+id+']').hide().text();
  1338. description = $this.parent().find('.description').hide().text();
  1339. if($this.attr('placeholder') == '')
  1340. $this.attr('placeholder',label);
  1341. $this.attr('title',description);
  1342. });
  1343. };
  1344. function onAjaxRegisterBlockLoaded (event) {
  1345. // console.log('onAjaxRegisterBlockLoaded');
  1346. hideLabelsFromRegisterForm();
  1347. };
  1348. /**
  1349. * cookies
  1350. */
  1351. function createCookie(name,value,days) {
  1352. if (days) {
  1353. var date = new Date();
  1354. date.setTime(date.getTime()+(days*24*60*60*1000));
  1355. var expires = "; expires="+date.toGMTString();
  1356. }
  1357. else var expires = "";
  1358. document.cookie = name+"="+value+expires+"; path=/";
  1359. };
  1360. function readCookie(name) {
  1361. var nameEQ = name + "=";
  1362. var ca = document.cookie.split(';');
  1363. for(var i=0;i < ca.length;i++) {
  1364. var c = ca[i];
  1365. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  1366. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  1367. }
  1368. return null;
  1369. };
  1370. function eraseCookie(name) {
  1371. createCookie(name,"",-1);
  1372. };
  1373. /**
  1374. * google analytics
  1375. */
  1376. function onRecordStat(event){
  1377. //trace('onRecordStat', event);
  1378. // path, category, action, opt_label, opt_value
  1379. if(typeof _gaq !== 'undefined'){
  1380. if(event.path){
  1381. _gaq.push(['_trackPageview', event.path]);
  1382. }else{
  1383. _gaq.push(['_trackEvent', event.categorie, event.action, event.label, event.value]);
  1384. }
  1385. }
  1386. };
  1387. /**
  1388. * docScrollTo
  1389. */
  1390. function docScrollTo($e){
  1391. // $(document).scrollTop($e.offset().top);
  1392. if($e.size())
  1393. $('html,body').animate({
  1394. scrollTop: $e.offset().top - $(window).height()*0.5 + $e.height()*0.5
  1395. }, 500);
  1396. };
  1397. init();
  1398. };
  1399. $(document).ready(function() {
  1400. var materiobasetheme = new MaterioBaseTheme();
  1401. });
  1402. /**
  1403. * Attach collapse behavior to the feedback form block.
  1404. */
  1405. Drupal.behaviors.feedbackForm = {
  1406. attach: function (context) {
  1407. $('#block-feedback-form', context).once('feedback', function () {
  1408. var $block = $(this);
  1409. $block.find('span.feedback-link')
  1410. .prepend('<span id="feedback-form-toggle">feedback</span> ')
  1411. .css('cursor', 'pointer')
  1412. .toggle(function () {
  1413. Drupal.feedbackFormToggle($block, false);
  1414. },
  1415. function() {
  1416. Drupal.feedbackFormToggle($block, true);
  1417. }
  1418. );
  1419. $block.find('form').hide();
  1420. $block.show();
  1421. });
  1422. }
  1423. };
  1424. /**
  1425. * Collapse or uncollapse the feedback form block.
  1426. */
  1427. Drupal.feedbackFormToggle = function ($block, enable) {
  1428. $block.find('form').slideToggle('medium');
  1429. if (enable) {
  1430. $('#feedback-form-toggle', $block).html('feedback');
  1431. }
  1432. else {
  1433. $('#feedback-form-toggle', $block).html('feedback (close)');
  1434. }
  1435. };
  1436. })(jQuery);