123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- // @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 = $('<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){
- // trace('text changed', $(this).val());
- 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{
- // var $note = $('<div id="modal" class="modal note-modal"/>').appendTo('body');
- // $note
- // .css({
- // position:'absolute',
- // top:'40%', left:'50%',
- // marginLeft:'-150px', width:'500px',
- // zIndex:"99999"
- // })
- // .append($('<div class="close"></i><div>')
- // .bind('click', function(){
- // trace('close note');
- // $(this).parents('#modal').remove();
- // })
- // );
- // $note
- // .append(json.rendered_form)
- // .find('textarea')
- // .focus()
- // .bind('change keyup paste', function(event){
- // // trace('text changed', $(this).val());
- // 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();
- // // TODO: esc keypressed close the form
- }
- };
- 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);
|