X-Git-Url: http://git.cyclocoop.org/?p=velocampus%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fextensions%2Fporte_plume%2Fjavascript%2Fjquery.previsu_spip.js;fp=www%2Fextensions%2Fporte_plume%2Fjavascript%2Fjquery.previsu_spip.js;h=88d4fe79bb4f9c314bdaf46ed6fa928c239ac134;hp=0000000000000000000000000000000000000000;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c diff --git a/www/extensions/porte_plume/javascript/jquery.previsu_spip.js b/www/extensions/porte_plume/javascript/jquery.previsu_spip.js new file mode 100644 index 0000000..88d4fe7 --- /dev/null +++ b/www/extensions/porte_plume/javascript/jquery.previsu_spip.js @@ -0,0 +1,86 @@ +;(function($) { + $.fn.previsu_spip = function(settings) { + var options; + + options = { + previewParserPath: '' , + previewParserVar: 'data', + textEditer: 'Editer', + textVoir: 'Voir' + }; + $.extend(options, settings); + + return this.each(function() { + var $$, textarea, tabs, preview; + $$ = $(this); + textarea = this; + + // init and build previsu buttons + function init() { + $$.addClass("pp_previsualisation"); + tabs = $('
').prependTo($$.parent()); + $(tabs).append( + '' + options.textVoir + '' + + '' + options.textEditer + '' + ); + + preview = $('
').insertAfter(tabs); + preview.hide(); + + $('.previsuVoir').click(function(){ + mark = $(this).parent().parent(); + objet = mark.parents('.formulaire_spip')[0].className.match(/formulaire_editer_(\w+)/); + champ = mark.parents('li')[0].className.match(/editer_(\w+)/); + $(mark).find('.markItUpPreview').height( + $(mark).find('.markItUpHeader').height() + + $(mark).find('.markItUpEditor').height() + + $(mark).find('.markItUpFooter').height() + ); + $(mark).find('.markItUpHeader').hide(); + $(mark).find('.markItUpEditor').hide(); + $(mark).find('.markItUpFooter').hide(); + $(this).addClass('on').next().removeClass('on'); + $(mark).find('.markItUpPreview').show() + .addClass('ajaxLoad') + .html(renderPreview( + $(mark).find('textarea.pp_previsualisation').val(), + champ[1].toUpperCase(), + objet[1]) + ) + .removeClass('ajaxLoad'); + return false; + }); + $('.previsuEditer').click(function(){ + mark = $(this).parent().parent(); + $(mark).find('.markItUpPreview').hide(); + $(mark).find('.markItUpHeader').show(); + $(mark).find('.markItUpEditor').show(); + $(mark).find('.markItUpFooter').show(); + $(this).addClass('on').prev().removeClass('on'); + return false; + }); + } + + + function renderPreview(val, champ, objet) { + var phtml; + if (options.previewParserPath !== '') { + $.ajax( { + type: 'POST', + async: false, + url: options.previewParserPath, + data: 'champ='+champ + +'&objet='+objet + +'&' + options.previewParserVar+'='+encodeURIComponent(val), + success: function(data) { + phtml = data; + } + } ); + } + return phtml; + } + + init(); + }); + }; +})(jQuery);