123456789101112131415161718192021222324252627 |
- (function($){MaterioFlag=function(){var _isLoadingList=false;function init(){buildBlocks();$(document).bind('flagGlobalAfterLinkUpdate',onFlaging).bind('resultscompleted resultschanged previewloaded',onResultsUpdated).bind('init-scroller-pager',onInitScrollerPager).bind('load-scroller-pager',onLoadScrollerPager).bind('view-mode-changed',onViewModeChanged).bind('history-state-change',onHistoryStateChange);if(isList()){setTimeout(function(){triggerContentChanged();},10);}};function onFlaging(event){refreshBlocks();};function onResultsUpdated(event){ajaxifyLinks(event.container);};function buildBlocks(activename){if($('#block-materio-flag-materio-flag-mybookmarks').length){var type='bookmarks';var block='#block-materio-flag-materio-flag-mybookmarks';}else if($('#block-materio-flag-materio-flag-mylists').length){var type='lists';var block='#block-materio-flag-materio-flag-mylists';}
- switch(type){case'bookmarks':var name=type;$('h2 .listname',block).attr('name',name).bind('click',onClickShowPreview);$('<i class="fi-x"></i>').appendTo($('h2',block)).attr('name',name).bind('click',onClickClosePreview);break;case'lists':$('a.open-list:not(.ajax-processed)','#block-materio-flag-materio-flag-mylists-nav').each(function(index){$this=$(this).bind('click',onClickOpenLink).addClass('ajax-processed');var name=$this.attr('class').match(/flag_lists_[^_]+_[0-9]+/);$('<span class="preview"><i class="fi-eye"></i></span>').attr('name',name).insertAfter($this).bind('click',onClickShowPreview);});$('a.edit-list:not(.ajax-processed)','#block-materio-flag-materio-flag-mylists-nav').bind('click',onCLickEditList).addClass('ajax-processed');$('a.flag-lists-create:not(.ajax-processed)','#block-materio-flag-materio-flag-mylists-nav').bind('click',onClickCreatLink).addClass('ajax-processed');$('section.flag-list:not(.ajax-processed)','#block-materio-flag-materio-flag-mylists').each(function(index){var name=$(this).attr('class').match(/flag_lists_[^_]+_[0-9]+/);$('<i class="fi-x"></i>').appendTo($('h2.listname',this)).attr('name',name).bind('click',onClickClosePreview);$('a.open-list',this).bind('click',onClickOpenLink);}).addClass('ajax-processed');break;}
- setTimeout(function(){$.event.trigger({type:'my'+type+'-block-builded',block:block,name:name});},10);if(activename==undefined)
- activename=readCookie('materiomyflaglistsopened');if(activename)
- showPreview(activename,block);};function refreshBlocks(name){if($('#block-materio-flag-materio-flag-mybookmarks').length){var type='bookmarks';}else if($('#block-materio-flag-materio-flag-mylists').length){var type='lists';}
- if(type!=undefined){var id='#block-materio-flag-materio-flag-my'+type;var url=Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/refresh/block/'+type;$.getJSON(url,function(json){$(id).replaceWith(json.block);$('#block-materio-flag-materio-flag-mylists-nav').replaceWith(json.block_nav);buildBlocks(name);$.event.trigger({type:'my'+type+'-block-updated',listname:name});});}};function ajaxifyLinks(container){container=((container!=null)?container:'body');if(typeof Drupal.flagLink!='undefined')
- Drupal.flagLink(container);if(isList()){var fid=$('.materio-flags-list','#content').attr('fid');$('li.unflag-action.fid-'+fid+' a:not(.ajax-processed), li.flag-bookmarks a.unflag-action:not(.ajax-processed)').bind('click',onUnflagList).addClass('ajax-processed');}
- $('a.flag-lists-create:not(.ajax-processed)',container).bind('click',onClickCreatLink).addClass('ajax-processed');};function onClickShowPreview(event){showPreview($(this).attr('name'),$(this).parent('.block').attr('id'));};function showPreview(name,block){$('section.'+name,block).addClass('active').siblings('section').removeClass('active');createCookie('materiomyflaglistsopened',name,1);$.event.trigger('init-layout');};function onClickClosePreview(event){eraseCookie('materiomyflaglistsopened');if($(this).attr('name')=='bookmarks'){$(this).parents('.block').find('section.bookmarks').removeClass('active');}else{$(this).parents('section.flag-list').removeClass('active');}
- $.event.trigger('init-layout');};function onClickOpenLink(event){event.preventDefault();var $link=$(event.currentTarget);var fid=$link.attr('href').match(/lists\/([0-9]+)$/);loadList(fid[1]);return false;};function loadList(fid){var url=Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/ajax/list/'+fid;$.event.trigger('loading-content');$.getJSON(url,{'current_path':document.location.href},function(json){if(json.redirect){window.location=json.redirect;}else{changeContent(json);}});};function changeContent(json){if(json.rendered){$('.inner-content','#content').html(json.rendered);$.event.trigger('loaded-content');var path=Drupal.settings.basePath+Drupal.settings.pathPrefix+json.path;$.event.trigger({type:'new-history-page',path:path,title:json.title,content:json.rendered});triggerContentChanged();}else{}};function triggerContentChanged(){$.event.trigger({type:'resultschanged',container:'#content .flaglist-items'});};function onClickCreatLink(event){event.preventDefault();var $link=$(event.currentTarget);var type=$link.attr('href').match(/[^\/]*$/);var url=Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/createlist/form/'+type[0];$.getJSON(url,function(json){showCreateListForm(json,$link);});return false;};function showCreateListForm(json,$link){$.event.trigger({type:"record-stat",categorie:"flagLists",action:'show create form'});var $modal=$('<div id="modal" class="modal"/>').appendTo('body');$modal.css({position:'absolute',top:'40%',left:'50%',marginLeft:'-150px',width:'300px',zIndex:"99999"}).append(json.rendered_form).find('input[type="submit"]','#materio-flag-create-list-form').bind('click',function(event){event.preventDefault();switch($(this).attr('name')){case'cancel':$(this).parents('#modal').remove();$.event.trigger({type:"record-stat",categorie:"flagLists",action:'cancel create form'});break;case'op':trace('MaterioFlag :: create',event);var name=$(this).parents('form').find('input[name*="title"]').val();var type=$(this).parents('form').find('input[name*="type"]').val();var token=$(this).parents('form').find('input[name*="form_token"]').val();$.event.trigger({type:"record-stat",categorie:"flagLists",action:"submit create form",label:'title : '+name});createList($modal,type,name,token,$link);break;}
- return false;}).parents('form').find('input[type="text"]').focus();};function createList($modal,type,name,token,$link){$('.flag-lists-create').addClass('loading');var url=Drupal.settings.basePath+Drupal.settings.pathPrefix+'flag-lists/add/'+type+'/js';$.getJSON(url,{form_token:token,name:name},function(data){if(data.error){trace("MaterioFlag :: created list : data.error",data.error);}
- else{if($link.attr('nid')&&$link.attr('token')){flagEntityWithList(data.flag.name,$link.attr('nid'),$link.attr('token'));}else{refreshBlocks(data.flag.name);refreshNodeLinks();}
- $modal.remove();}});};function flagEntityWithList(name,nid,token){$.ajax({type:'POST',url:Drupal.settings.basePath+Drupal.settings.pathPrefix+'flag-lists/flag/'+name+'/'+nid,data:{js:true,token:token},dataType:'json',success:function(data2){if(data2.status){$.event.trigger({type:"record-stat",categorie:'FlagLists',action:'node flaged',label:'nid : '+nid+' | flag : '+name});refreshBlocks(name);refreshNodeLinks();}else{alert(data2.errorMessage);}},error:function(xmlhttp){alert('An HTTP error '+xmlhttp.status+' occurred.\n'+element.href);}});};function refreshNodeLinks(){var nids=new Array();$('.flag-lists-entity-links').parents('.node').each(function(index){nids.push($(this).attr('class').match(/node-([0-9]+)/)[1]);});var url=Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/nodelinks';$.getJSON(url,{nids:nids.join(";")},function(data){for(nid in data.links){$('.node-'+nid+' .flag-lists-entity-links').replaceWith(data.links[nid]);ajaxifyLinks('.node-'+nid+' .flag-lists-entity-links');}});$.event.trigger({type:'materioflag-nodelinks-updated',nids:nids});};function onCLickEditList(event){event.preventDefault();var $link=$(event.currentTarget);var lid=$link.attr('href').match(/[^\/]*$/);var type='materiau';var url=Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/editlistform/'+type+'/'+lid[0];$.getJSON(url,function(json){showEditListForm(json,$link);});return false;};function showEditListForm(json,$link){$.event.trigger({type:"record-stat",categorie:"flagLists",action:'show edit form'});var $modal=$('<div id="modal" class="modal"/>').appendTo('body');$modal.css({position:'absolute',top:'40%',left:'50%',marginLeft:'-150px',width:'300px',zIndex:"99999"}).append(json.rendered_form).find('input[type="submit"]','#materio-flag-edit-list-form').bind('click',function(event){event.preventDefault();var $form=$(this).parents('form');var title=$form.find('input[name*="flag-lists-title"]').val();var fid=$form.find('input[name*="fid"]').val();var name=$form.find('input[name*="name"]').val();switch($(this).attr('name')){case'cancel':$(this).parents('#modal').remove();var action='cancel edit form';break;case'save':var action="submit edit form";saveList($modal,fid,name,title);break;case'delete':if(confirm('Do you realy want to delete your '+title+' folder ?')){var action="submit delete form";deleteList($modal,fid);}else{var action="cancel delete form";}
- break;}
- $.event.trigger({type:"record-stat",categorie:"flagLists",action:action});return false;}).parents('form').find('input[type="text"]').focus();};function saveList($modal,fid,name,title){$('.flag-lists-link.fid-'+fid).addClass('loading');var url=Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/editlist/'+fid+'/'+name+'/'+title;$.getJSON(url,function(data){if(data.error){if(data.message)
- alert(data.message);}
- else{$.event.trigger({type:'list-edited',name:data.listname,title:data.title,});refreshBlocks();refreshNodeLinks();$modal.remove();}});};function deleteList($modal,fid){$('.flag-lists-link.fid-'+fid).hide();var url=Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/deletelist/'+fid;$.getJSON(url,function(data){if(data.error){if(data.message)
- alert(data.message);}
- else{trace('MaterioFlag :: deleted list : data',data);refreshBlocks();refreshNodeLinks();$modal.remove();trace("MaterioFlag :: deleted list : document.location.href",document.location.href);if(document.location.href.indexOf("/lists/"+data.fid)!==-1){window.location=Drupal.settings.basePath+Drupal.settings.pathPrefix+"actuality";}}});};function onUnflagList(event){$(this).parents('article.node').addClass('removed');};function onInitScrollerPager(event){if(isList()){event.pager.hide();}};function onLoadScrollerPager(event){if(isList())
- loadNextListPage(event.href);};function loadNextListPage(href){if(!_isLoadingList){var fid=href.match(/lists\/([^\/|\?]+)/);var page=href.match(/\?page=([0-9]+)/);var url=Drupal.settings.basePath+Drupal.settings.pathPrefix+'materioflag/ajax/list/'+fid[1]+'/'+page[1];loadNextPage(url,$('.materio-flags-list','#content'),'.flaglist-items');}};function loadNextPage(url,$container,target){_isLoadingList=true;$container.addClass('loading');$.getJSON(url,function(json){_isLoadingList=false;$container.removeClass('loading');addNextpage(json,target);});};function addNextpage(json,container_class){var $newcontent=$(json.rendered),$newitems=$(container_class,$newcontent).children('article').addClass('just-added'),$newpager=$('ul.pager',$newcontent);$(container_class,'#content').append($newitems);$('ul.pager','#content').replaceWith($newpager.hide());$(container_class,'#content').children('.just-added').each(function(i){var $this=$(this);setTimeout(function(){$this.removeClass('just-added');},150*i);});$.event.trigger({type:'resultscompleted',container:$(container_class,'#content')});};function onViewModeChanged(event){if(isList())
- loadList(getFid());};function onHistoryStateChange(event){if(isList())
- triggerContentChanged();};function getFid(){return $('.materio-flags-list','#content').attr('fid');;};function isList(){return $('.materio-flags-list','#content').length;};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);}
- init();};$(document).ready(function(){var materioflag=new MaterioFlag();});})(jQuery);
|