// @codekit-prepend "gui.js" // @koala-prepend "gui.js" (function($) { MaterioPersonalNotes = function(){ /** * init() */ function init(){ trace('MaterioPersonalNotes :: init'); $(document) .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); }; function onResultsUpdated(event){ trace('MaterioPersonalNotes :: onResultsUpdated', event); ajaxifyLinks(event.container); }; function ajaxifyLinks(container){ trace('MaterioPersonalNotes :: ajaxifyLinks', container); container = ((container != null) ? container : 'body'); // trace('MaterioFlag :: typeof Drupal.flagLink', typeof Drupal.flagLink); // if (typeof Drupal.flagLink != 'undefined') // Drupal.flagLink(container); $('a.personal-note-link:not(.ajax-processed), ', container) .bind('click', onClickLink) .addClass('ajax-processed'); // $('a.personal-note-edit:not(.ajax-processed)', container) // .bind('click', {'action':'edit'}, onClickLink) // .addClass('ajax-processed'); }; /** * onClickCreatLink(event) */ function onClickLink(event){ // trace('MaterioPersonalNotes :: onClickLink | '+action+' | event', 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 +Drupal.settings.pathPrefix +'materio_personalnotes/form/'+action +'/'+src_nid; if(action == 'edit'){ url += '/'+note_nid; } $.getJSON(url, function(json){ trace('MaterioPersonalNotes :: '+action+' : json', json); if(json.new_note_nid){ updateNoteLink($link, json.new_note_nid); } 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'); // google analytics $.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 = $('
') .append($('