script.js.orig 50 KB

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