script.js 49 KB

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