123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- (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
- +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');
-
- $.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
- +Drupal.settings.pathPrefix
- +'materio_personalnotes/save'
- +'/'+note_nid;
- $.post(url, {'content':text}, function(data, status){
- trace('MaterioPersonalNotes :: save : status', status);
- });
- };
- init();
- };
- $(document).ready(function() {
- var materioflag = new MaterioPersonalNotes();
- });
- })(jQuery);
|