').addClass('modal-content').append(json.node);
var $modal_wrapper = $('.modal-wrapper');
if(!$modal_wrapper.size())
$modal_wrapper = $('
').addClass('modal-wrapper').append($('
').addClass('modal-bg')).appendTo('body');
$modal_wrapper
.append($modal)
.bind('click', function(event) {
_previewIsOpen = false;
$(this).remove();
});
$modal.bind('click', function(event) {
event.stopPropagation();
});
_previewIsOpen = true;
initCards('.modal-content');
$.event.trigger({ type : 'previewloaded', container : '.modal-content'});
};
/**
* GRID
*/
function moveGridFocus(event, side){
var $old_focused = $('#content .search-results, #content .actuality-items')
.children('.node.focused').first();
var $new_focused;
switch(side){
case 'r':
$new_focused = $old_focused.next();
break;
case 'l':
$new_focused = $old_focused.prev();
break;
case 'u':
case 'd':
var dir = side == "d" ? 1 : -1;
var column = $old_focused.attr('column');
while( ($new_focused == undefined || !$new_focused.size()) && column > 0){
$new_focused = $('.node[column='+column+'][line='+(parseInt($old_focused.attr('line'))+dir)+']');
column --;
}
break;
}
focusCard($new_focused);
docScrollTo($new_focused);
};
function focusCard($card){
// trace('theme :: focusCard', $card);
if(!$card.size() || $card.is('.focused') || $card.parents('.modal-content').size())
return;
$('#content .search-results, #content .actuality-items')
.children('.node.focused')
.removeClass('focused');
$card.addClass('focused');
if(_previewIsOpen){
previewCard($card);
}
$card.trigger('focused');
};
/**
* lazyloadimages
*/
// function initLazyLoad(context){
// $('figure:first-child img.lazy', context).lazyload();//{
// container:'#content'
// });
// TODO: propage this event to the card near it to anticipate the mouseenter
// $(context).bind('mousemove', showLazyLoadedImages);
// };
function showLazyLoadedImages(context){
//trace('MaterioBaseTheme :: initLazyLoad : mouseenter', this);
var $this = $(context);
if( !$this.is('.lazy-processed') ){
$this
.addClass('lazy-processed')
// .find('figure img.lazy')
.find('img.lazy')
.each(function(index){
var $img = $(this);
$img.attr('src', $img.attr('data-original')).removeAttr('data-original');
});
setTimeout(function(){
$this.addClass('image-ready');
}, 300);
}
};
/**
* prepareAssociatedMaterials
*/
function prepareAssociatedMaterials(card){
// trace('prepareAssociatedMaterials', card);
$('.field-name-field-materiau-ref a:not(.prepared)', card).addClass("prepared").bind('click', onClickAssociatedMaterial);
};
/**
* onClickAssociatedMaterial
*/
function onClickAssociatedMaterial(event){
// trace("onClickAssociatedMaterial");
event.preventDefault();
var $this = $(this);
// trace('href', $(this).attr('href'));
var nid = $this.attr('href').match(/^\/(fr|en)\/node\/(\d+)$/)[2];
// trace("nid", nid);
var $prt = $this.parents('.node-materiau');
if($prt.parent().is('.modal-content')){
// if we are on preview mode
// remove already loaded associated
$prt.parent().find('.node-'+nid+'.associated').remove();
loadAssociatedNode($prt, nid);
}else{
// if we are on normal grid mode
var $n = $prt.nextUntil('.node-materiau:not(.associated)').filter('.node-'+nid);
// trace('n', $n);
if($n.size()){
// trace('focus', nid);
// focus on already loaded node
focusCard($n);
// docScrollTo($isnodeexisting);
}else{
// trace('load associated', nid);
loadAssociatedNode($prt, nid);
}
}
return false;
};
function loadAssociatedNode($prt, nid){
// console.log('loadAssociatedNode | nid = '+nid);
var viewmode = $prt.attr('class').match(/vm-([^\s]+)/);
// trace('viewmode match', viewmode);
// if(!_isloadingresults){
$.event.trigger('loading-content');
var url = _settings.basePath+_settings.pathPrefix+'materio_search_api_ajax/node/'+nid;
$.getJSON(url,
{viewmode:viewmode[1]},
function(json){
//trace('json', json);
$.event.trigger('loaded-content');
displayAssociated($prt, $(json.node));
$.event.trigger({
type : 'resultscompleted',
container : '#content .actuality-items, #content .search-results'
});
});
// }
};
function displayAssociated($prt, $n){
$n.addClass('associated').addClass('just-added');
$prt.after($n);
initCards($prt.parent());
(function($n){
setTimeout(function(){
$n.removeClass('just-added');
focusCard($n);
}, 100);
}($n));
};
/**
* sideSwitcher
*/
function sideSwitcher(event, delta){
var $sides = $('.side', event.currentTarget);
if($sides.length > 1){
if( typeof delta == 'undefined'){
var delta = 0;
$sides.each(function(i) {
if($(this).is('.op-visible')){
delta = i+1;
return false;
}
});
delta = delta == 0 ? 1 : (delta == $sides.length ? 0 : delta);
}
// google analytics
$.event.trigger({
type : 'record-stat',
categorie : 'Card event',
action : 'side switch',
label : delta
});
$sides.addClass('op-hidden').removeClass('op-visible')
.eq(delta).removeClass('op-hidden').addClass('op-visible');
}
};
/**
* columnsPage
*/
function columnsPage($elmt, cw, ch){
// trace('columnsPage');
var cls = Math.ceil($elmt.h()/ch);
$elmt
.addClass('columnized')
.width(cw*cls)
.columnize({
width:cw,
height:ch,
lastNeverTallest:true
});
if(cls > 1){
$elmt.find('.column').each(function(index) {
var $this = $(this);
if(!$this.find('*').length){
$this.prev().addClass('last');
$this.remove();
return true;
}
});
$elmt.find('.column').each(function(index) {
var $this = $(this);
if(!$this.is('.first'))
$this.children('*:first-child').prepend('‹ ...');
if(!$this.is('.last'))
$this.children('*:last-child').append('... ›');
});
$('.column-switcher', $elmt).bind('click', onColumnSwitcherClick);
}
};
function onColumnSwitcherClick(event){
event.preventDefault();
//trace('onColumnSwitcherClick', event);
var $this = $(event.currentTarget),
$columnized = $this.parents('.columnized');
// google analytics
$.event.trigger({
type : 'record-stat',
categorie : 'Card event',
action : 'column switch',
label : $this.attr('col')
});
$columnized.css({
marginLeft : -1 * $this.attr('cw') * $this.attr('col') +'px'
});
return false;
}
/**
* initViewmodes
*/
function initViewmodes(){
checkViewmodesResponsive();
};
function checkViewmodesResponsive(){
if(_480_768()){
if($('.viewmode-link.active').is('.viewmode-cardfull')){
$('.viewmode-cardbig').trigger('click');
}
}else if(_max_480()){
if($('.viewmode-link.active').is('.viewmode-cardbig, .viewmode-cardfull')){
$('.viewmode-cardmedium').trigger('click');
}
}
};
function getCurrentViewmode(){
for(var vm in _viewmodes)
if($('.viewmode-link.active.viewmode-'+vm).size())
return vm;
};
/**
* FLAGS
*/
function initFlagsEvent(){
$('.bookmarks, .mylists .flaged').children('.node:not(.listened)')
.bind('mouseenter mousemove click mouseleave', onCardEventDispatcher)
// .each(function(event){ initLayoutCardDispatcher($(this)); })
.addClass('listened');
};
function onAfterFlaging(event){
//trace('MaterioBaseTheme :: onAfterFlaging', event);
// WARNING to use event variables i had to hack flag.js from flag module (change the event declaration)
var $target = $(event.link).parents('article.node');
if(event.flagStatus == 'flag'){
$target.addClass('flaged');
}else if(event.flagStatus == 'unflag'){
if($('.flag-lists-entity-links a.unflag-action', $target).length == 0)
$target.removeClass('flaged');
}
};
function onMybookmarksBlockUpdate(event){
initFlagsEvent();
initLayout();
};
function onClickList(event){
//trace('onClickList', event);
var $link = $(event.currentTarget).addClass('active'),
name = $link.attr('name'),
$block = $link.parents('.block'),
$flaged = $('.flaged.'+name, $block).addClass('active');
$link.siblings().removeClass('active');
$flaged.siblings().removeClass('active');
createCookie('materiomyflaglistsopened', name, 1);
$flaged.parents('.mylists').height($flaged.h());
initLayout();
};
function onMyListsBlockUpdate(event){
//trace('MaterioBaseTheme :: onMyListsBlockUpdate', event);
initFlagsEvent();
// initLazyLoad(this);
// TODO: refresh contents (search results) to see new flaglist links.
initLayout();
};
function onMyListsBlockBuilded(event){
//trace('MaterioBaseTheme :: onMyListsBlockBuilded', event);
// initLazyLoad(event.block);
showLazyLoadedImages(event.block);
};
/**
* cards bookmark
*/
// MaterioBaseTheme.prototype.init_layout_bookmark = function($card){
// trace('initLayoutCardBig');
// };
MaterioBaseTheme.prototype.on_mouseenter_bookmark = function(event){
//trace('on_mouseenter_bookmark', event);
_$tooltip
.html($('.group-header', this).clone())
.css({
top:event.pageY - _$tooltip.h() -5,//- event.layerY,
left:event.pageX + 5 + ($(this).w() - event.layerX)
})
.removeClass('op-hidden').addClass('op-visible');
};
MaterioBaseTheme.prototype.on_mousemove_bookmark = function(event){
// trace('on_mousemove_Card', event);
// if(event.layerX)
// horiHoverImagesSwitcher(event);
_$tooltip
.css({
top:event.pageY - _$tooltip.h() -5,// - event.layerY,
left:event.pageX + 5 + ($(this).w() - event.layerX)
});
};
// MaterioBaseTheme.prototype.on_click_bookmark = function(event){
// trace('on_click_bookmark', event);
// };
MaterioBaseTheme.prototype.on_mouseleave_bookmark = function(event){
// trace('on_mouseleave_Card', event);
$('.images img.op-visible', this)
.removeClass('op-visible').addClass('op-hidden')
.eq(0)
.removeClass('op-hidden').addClass('op-visible');
_$tooltip.removeClass('op-visible').addClass('op-hidden');
};
/**
* keyboradshortcuts
*/
function initKeyboardShortcuts(){
$(document)
.bind('keydown', 'Shift+:',shortcut_focusSearchField)
.bind('keydown', '/',shortcut_focusSearchField)
.bind('keydown', 'Alt+1',shortcut_viewmodeSmall)
.bind('keydown', 'Alt+2',shortcut_viewmodeMedium)
.bind('keydown', 'Alt+3',shortcut_viewmodeBig)
.bind('keydown', 'Alt+4',shortcut_viewmodeFull)
.bind('keydown', 'space',shortcut_togglePreview)
.bind('keydown', 'esc',shortcut_closeModaleContent)
.bind('keydown', 'up',shortcut_onUpArrow)
.bind('keydown', 'right',shortcut_onRightArrow)
.bind('keydown', 'down',shortcut_onDownArrow)
.bind('keydown', 'left',shortcut_onLeftArrow);
};
function shortcut_focusSearchField(e){
// trace("focusSearchField");
if($('#edit-searchfield').size()){
var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
stat_event.action = 'slash';
stat_event.label = 'Focus on search text field';
$.event.trigger(stat_event);
$('#edit-searchfield').focus();
e.stopPropagation();
e.preventDefault();
return false;
}
};
function shortcut_viewmodeSmall(e){
if($('a.viewmode-link.viewmode-cardsmall').size()){
var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
stat_event.action = 'Alt+1';
stat_event.label = 'Change view mode : card small';
$.event.trigger(stat_event);
$('a.viewmode-link.viewmode-cardsmall').click();
return false;
}
};
function shortcut_viewmodeMedium(e){
if($('a.viewmode-link.viewmode-cardmedium').size()){
var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
stat_event.action = 'Alt+2';
stat_event.label = 'Change view mode : card medium';
$.event.trigger(stat_event);
$('a.viewmode-link.viewmode-cardmedium').click();
return false;
}
};
function shortcut_viewmodeBig(e){
if($('a.viewmode-link.viewmode-cardbig').size()){
var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
stat_event.action = 'Alt+3';
stat_event.label = 'Change view mode : card big';
$.event.trigger(stat_event);
$('a.viewmode-link.viewmode-cardbig').click();
return false;
}
};
function shortcut_viewmodeFull(e){
if($('a.viewmode-link.viewmode-cardfull').size()){
var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
stat_event.action = 'Alt+4';
stat_event.label = 'Change view mode : card full';
$.event.trigger(stat_event);
$('a.viewmode-link.viewmode-cardfull').click();
return false;
}
};
function shortcut_togglePreview(e){
// trace('theme :: shortcut_togglePreview', e);
$.event.trigger({
type : 'record-stat',
categorie : 'Shortcuts',
action : 'Space',
label : 'Space toggle preview'
});
if(_previewIsOpen){
if($('body>.modal-wrapper').size()){
$('body>.modal-wrapper').click();
_previewIsOpen = false;
return false;
}
}else{
previewCard($('#content .search-results, #content .actuality-items').children('.node.focused:first'));
}
};
function shortcut_closeModaleContent(e){
if($('body>.modal-wrapper').size()){
$.event.trigger({
type : 'record-stat',
categorie : 'Shortcuts',
action : 'Esc',
label : 'Esc from modal content'
});
$('body>.modal-wrapper').click();
_previewIsOpen = false;
return false;
}
};
function shortcut_onUpArrow(e){
// trace('theme :: shortcut_onTopArrow', e);
moveGridFocus(e, 'u');
};
function shortcut_onRightArrow(e){
// trace('theme :: shortcut_onRightArrow', e);
moveGridFocus(e, 'r');
};
function shortcut_onDownArrow(e){
// trace('theme :: shortcut_onDownArrow', e);
moveGridFocus(e, 'd');
};
function shortcut_onLeftArrow(e){
// trace('theme :: shortcut_onLeftArrow', e);
moveGridFocus(e, "l");
};
/**
* Misc
*/
function onResizeWindow(e){
clearInterval(_resizeTimer);
_resizeTimer = setTimeout(function(){
initLayout();
checkViewmodesResponsive();
setUpGrid("#content .actuality-items, #content .search-results");
}, 200);
};
/**
* Statics
*/
function initMembershipForm() {
switch(window.location.hash){
case '#flocon':
$('#edit-submitted-column-left-membership-options-1').attr('checked', 'checked');
// $options.trigger('change');
break;
case '#etoile':
$('#edit-submitted-column-left-membership-options-2').attr('checked', 'checked');
break;
case '#4etoiles':
$('#edit-submitted-column-left-membership-options-3').attr('checked', 'checked');
break;
// default:
// switchMembershipShipFormFields($options);
// break
}
$('#webform-component-column-left--membership-options')
.change(function(event){
//trace('changed');
if( $('input[type="radio"]:checked', this).is('#edit-submitted-column-left-membership-options-3') ){
$('#webform-component-column-right--collaborators').show();
}else{
$('#webform-component-column-right--collaborators').hide();
}
$('div.form-item.selected', this).removeClass('selected');
$('input[type="radio"]:checked', this).parents('div.form-item').addClass('selected');
})
.trigger('change');
// $('#webform-component-column-left--membership-options input[checked="checked"]').parents('div.form-item').addClass('selected');
};
/** helpers */
$.fn.h = function(){
if(this.css('height') == undefined)
return 0;
return parseInt(this.css('height')) + parseInt(this.css('padding-top')) + parseInt(this.css('padding-bottom'));
};
$.fn.w = function(){
if(this.css('width') == undefined)
return 0;
return parseInt(this.css('width')) + parseInt(this.css('padding-left')) + parseInt(this.css('padding-right'));
};
function getDocHeight() {
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
};
// http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
function viewport() {
var e = window, a = 'inner';
if (!('innerWidth' in window )) {
a = 'client';
e = document.documentElement || document.body;
}
return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
};
/**
* Forms
*/
function initForms(){
$('#edit-searchfield:not(.processed)')
.bind('focus', function(event) {
var $this = $(this);
//$this.attr('value', 'test');
// trace('value', $this.val());
// trace('default', $this.attr('default'));
if($this.val() == $this.attr('default'))
$this.val('');
})
.bind('focusout', function(event) {
var $this = $(this);
if($this.val() == "")
$this.val($this.attr('default'));
})
.addClass('processed');
hideLabelsFromRegisterForm();
};
function hideLabelsFromRegisterForm () {
var $this, id,label, description;
$('input.form-text', '#block-user-login, #block-materio-user-user-register, , #block-materio-user-user-createaccount').each(function(i) {
$this = $(this);
id = $this.attr('id');
label = $('label[for='+id+']').hide().text();
description = $this.parent().find('.description').hide().text();
if($this.attr('placeholder') == '')
$this.attr('placeholder',label);
$this.attr('title',description);
});
};
function onAjaxRegisterBlockLoaded (event) {
// console.log('onAjaxRegisterBlockLoaded');
hideLabelsFromRegisterForm();
};
/**
* cookies
*/
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
};
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
};
function eraseCookie(name) {
createCookie(name,"",-1);
};
/**
* google analytics
*/
function onRecordStat(event){
//trace('onRecordStat', event);
// path, category, action, opt_label, opt_value
if(typeof _gaq !== 'undefined'){
if(event.path){
_gaq.push(['_trackPageview', event.path]);
}else{
_gaq.push(['_trackEvent', event.categorie, event.action, event.label, event.value]);
}
}
};
/**
* docScrollTo
*/
function docScrollTo($e){
// $(document).scrollTop($e.offset().top);
if($e.size())
$('html,body').animate({
scrollTop: $e.offset().top - $(window).height()*0.5 + $e.height()*0.5
}, 500);
};
init();
};
$(document).ready(function() {
var materiobasetheme = new MaterioBaseTheme();
});
/**
* Attach collapse behavior to the feedback form block.
*/
Drupal.behaviors.feedbackForm = {
attach: function (context) {
$('#block-feedback-form', context).once('feedback', function () {
var $block = $(this);
$block.find('span.feedback-link')
.prepend('feedback ')
.css('cursor', 'pointer')
.toggle(function () {
Drupal.feedbackFormToggle($block, false);
},
function() {
Drupal.feedbackFormToggle($block, true);
}
);
$block.find('form').hide();
$block.show();
});
}
};
/**
* Collapse or uncollapse the feedback form block.
*/
Drupal.feedbackFormToggle = function ($block, enable) {
$block.find('form').slideToggle('medium');
if (enable) {
$('#feedback-form-toggle', $block).html('feedback');
}
else {
$('#feedback-form-toggle', $block).html('feedback (close)');
}
};
})(jQuery);