var wikiEditor; var inEdition = false; //CHARGEMENT DE LA PAGE function init_plugin_wiki(){ if($('#sideMenu').length) { $('#sideMenu').panelResize({ minWidth : 300 }); } wiki_category_search(function(){ var page = $.urlParam('page'); var category = $.urlParam('category'); if(page && page!=''){ wiki_page_open(category,page); } else if(category && category!=''){ wiki_category_open(category); } else{ wiki_page_home(); } $('#wiki-categories #categories').sortable({ cursorAt: { top:15 }, distance: 10, axis: "y", containment: "parent", update: function( event, ui ) { var sort = []; //tri d'une page au sein d'une catégorie $('#wiki-categories .category:visible').each(function(i,element){ sort.push($(element).attr('data-id')); }); $.action({ action : 'wiki_category_sort', sort : sort }); } }); }); window.onbeforeunload = function(){ if(inEdition) return "Êtes-vous sûr de vouloir quitter la page sans sauvegarder ?"; } //Champ recherche $('.wiki_search_item input').blur(function(){ $('.wiki_search_item span').removeClass('hidden').animate({opacity: '1'}, 150); $(this).animate({opacity: '0'}, 150).addClass('hidden'); }).keyup(function(e){ if(e.keyCode != 13) return; wiki_search_item($(this)); }); //Smooth scrolling pour sommaire var editor = $('.module-wiki #editor'); $('#wiki-summary').on('click', 'a[href^="#"]',function(e) { e.preventDefault(); var href = $.attr(this, 'href'); editor.animate({ scrollTop: $(href).offset().top }, 500, function () { window.location.hash = href; }); }); //Night mode if($('#night-mode-check').prop('checked') == true) $('html.module-wiki').addClass('night-mode'); wiki_document_upload(); //Récuperation des images en presse papier et upload window.addEventListener("paste", function(event){ var clipboardData = event.clipboardData || window.clipboardData; if(clipboardData.getData('Text').length) return; 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){ if(inEdition && !confirm('Êtes vous sûr de vouloir quitter la page sans sauvegarder ?')) return; 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('