var wikiEditor; //CHARGEMENT DE LA PAGE function init_plugin_wiki(){ wiki_category_search(function(){ var page = $.urlParam('page'); var category = $.urlParam('category'); if(page && page!=''){ wiki_category_open(category,true,function(){ wiki_page_open(category,page); }); } else if(category && category!=''){ wiki_category_open(category); } else{ wiki_page_home(); } }); $(document).ready(function(e){ //Champ recherche $('.wiki_search_item input').blur(function(){ $('.wiki_search_item span').show().animate({opacity: '1'}, 150); $(this).animate({opacity: '0'}, 150).hide(); }).keyup(function(e){ if(e.keyCode != 13) return; wiki_search_item($(this)); }); //Smooth scrolling pour sommaire var docRoot = $('html, body'); $('#wiki-summary').on('click', 'a[href^="#"]',function(e) { var href = $.attr(this, 'href'); docRoot.animate({ scrollTop: $(href).offset().top }, 500, function () { window.location.hash = href; }); return false; }); //Night mode if($('#night-mode-check').attr('checked') && $('#night-mode-check').attr('checked').length) $('html.module-wiki').addClass('night-mode'); }); wiki_document_upload(); //Récuperation des images en presse papier et upload window.addEventListener("paste", function(event){ var items = event.clipboardData.items; if(event.clipboardData == false || event.clipboardData.items == undefined) return; var items = event.clipboardData.items; if( items.length == 0) return; var ajaxData = new FormData(); for (var i = 0; i < items.length; i++) { if (items[i].type.indexOf("image") == -1) continue; var file = items[i].getAsFile(); ajaxData.append('file', file); } $.ajax({ url: 'action.php?action=wiki_file_upload', type: 'POST', data: ajaxData, dataType: 'json', cache: false, contentType: false, processData: false, complete: function (data) {}, success: function (response) { if(response.error) return $.message('error',response.error,0); var value = wikiEditor.value(); for(var k in response.rows){ var file = response.rows[k]; value += "\n"+file.tag; } wikiEditor.value(value); }, error: function (data) { $.message('error',data); } }); }, false); } function toggle_night_mode(element){ var wikiPage = $('html.module-wiki'); var data = {action: 'wiki_night_mode'}; if(element.checked){ data.nightmode = true; wikiPage.addClass('night-mode'); } else { wikiPage.removeClass('night-mode'); } $.action(data, function(r){}); } function wiki_search_item(input){ var input = $(input); // if(!input.val().length) return $('.search-title').length ? $('.category-recent').html('') : $('#editor').html(''); $('.wiki-preloader').addClass('show'); $.action({ action : 'wiki_page_search', term : input.val(), },function(r){ $('.wiki-preloader').removeClass('show'); $('#editor').html(r.content); }); } //Suppression d'un tag liée à la recherche en cours function wiki_tag_delete(element){ var tag = $(element).closest('span.tag-item'); // tag.remove(); var searchInput = $('.wiki_search_item input'); var tagKeyword = tag.text().trim(); var keywords = searchInput.val(); searchInput.val(keywords.replace(tagKeyword, '').trim()); wiki_search_item(searchInput); } function wiki_change_url(category,page){ var url = window.location.pathname+'?module=wiki'; if(category) { url +='&category='+category; $('#wiki-categories .category').removeClass('category-open'); $('#wiki-categories .category[data-category="'+category+'"]').addClass('category-open'); } if(page){ url += '&page='+page; $('#wiki-categories .page').removeClass('page-open'); $('#wiki-categories .page[data-page="'+page+'"]').addClass('page-open'); } url+= window.location.hash; window.history.replaceState(null, null, url); } //Enregistrement des configurations function wiki_setting_save(){ var data = {} data.action = 'wiki_setting_save'; data.fields = $('#wiki-setting-form').toJson(); data.logo = $('#wiki_logo')[0].files[0]; $.action(data,function(r){ $.message('success','Enregistré'); }); } //Suppression image générale application function wiki_logo_delete(element){ if(!confirm('Êtes-vous sûr de vouloir supprimer l\'image ?')) return; var imageComposer = $(element).parent().find("input[data-type='image']"); $.action({ action: 'wiki_logo_delete' }, function(r){ imageComposer.wrap('