script.js 49 KB

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