materio_personalnotes.min.js 2.7 KB

12345678910
  1. (function($){MaterioPersonalNotes=function(){function init(){trace('MaterioPersonalNotes :: init');$(document).bind('resultscompleted resultschanged previewloaded',onResultsUpdated);};function onResultsUpdated(event){trace('MaterioPersonalNotes :: onResultsUpdated',event);ajaxifyLinks(event.container);};function ajaxifyLinks(container){trace('MaterioPersonalNotes :: ajaxifyLinks',container);container=((container!=null)?container:'body');$('a.personal-note-link:not(.ajax-processed), ',container).bind('click',onClickLink).addClass('ajax-processed');};function onClickLink(event){event.preventDefault();var $link=$(event.currentTarget);var note_nid=$link.attr('note_nid');var action=note_nid?'edit':'create';var src_nid=$link.attr('src_nid');trace('MaterioPersonalNotes :: src_nid',src_nid);trace('MaterioPersonalNotes :: note_nid',note_nid);var url=Drupal.settings.basePath
  2. +Drupal.settings.pathPrefix
  3. +'materio_personalnotes/form/'+action
  4. +'/'+src_nid;if(action=='edit'){url+='/'+note_nid;}
  5. $.getJSON(url,function(json){trace('MaterioPersonalNotes :: '+action+' : json',json);if(json.new_note_nid){updateNoteLink($link,json.new_note_nid);}
  6. showNoteForm($link,json);});return false;};function updateNoteLink($link,new_note_nid){trace('MaterioPersonalNotes :: updateNoteLink : new_note_nid',new_note_nid);$link.attr('note_nid',new_note_nid);$link.attr('href',Drupal.settings.pathPrefix+'node/'+new_note_nid+'/edit');};function showNoteForm($link,json){trace('MaterioPersonalNotes :: showNoteForm');$.event.trigger({type:"record-stat",categorie:"PersonalNotes",action:'show create form'});var $card=$link.parents('.node-materiau');if($card.is('.vm-cardmedium')||$card.is('.vm-cardbig')||$card.is('.vm-cardfull')){var $note=$('<div class="note-wrapper"/>').append($('<div class="close"></i><div>').bind('click',function(){trace('close note');$(this).parents('.node-materiau').removeClass('note-opened');setTimeout((function(that){$(that).parents('.note-wrapper').remove();})(this),300);}));$note.append(json.rendered_form).find('textarea').focus().bind('change keyup paste',function(event){var note_nid=$(this).parents('form').find('input[name="note_nid"]').val();saveNote($(this).val(),note_nid);});$note.find('input[type="submit"], .homepage-textfield').hide();$note.appendTo($card.addClass('note-opened'));$note.find('textarea').focus();}else{}};function saveNote(text,note_nid){trace(text,'MaterioPersonalNotes :: saveNote : text');var url=Drupal.settings.basePath
  7. +Drupal.settings.pathPrefix
  8. +'materio_personalnotes/save'
  9. +'/'+note_nid;$.post(url,{'content':text},function(data,status){trace('MaterioPersonalNotes :: save : status',status);});};init();};$(document).ready(function(){var materioflag=new MaterioPersonalNotes();});})(jQuery);