script.js 54 KB

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