script.js 54 KB

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