+// from django/contrib/admin/static/admin/js/urlify.js
+var LATIN_MAP = {
+ 'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE',
+ 'Ç': 'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I',
+ 'Î': 'I', 'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O',
+ 'Õ': 'O', 'Ö': 'O', 'Ő': 'O', 'Ø': 'O', 'Ù': 'U', 'Ú': 'U', 'Û': 'U',
+ 'Ü': 'U', 'Ű': 'U', 'Ý': 'Y', 'Þ': 'TH', 'Ÿ': 'Y', 'ß': 'ss', 'à': 'a',
+ 'á': 'a', 'â': 'a', 'ã': 'a', 'ä': 'a', 'å': 'a', 'æ': 'ae', 'ç': 'c',
+ 'è': 'e', 'é': 'e', 'ê': 'e', 'ë': 'e', 'ì': 'i', 'í': 'i', 'î': 'i',
+ 'ï': 'i', 'ð': 'd', 'ñ': 'n', 'ò': 'o', 'ó': 'o', 'ô': 'o', 'õ': 'o',
+ 'ö': 'o', 'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u',
+ 'ű': 'u', 'ý': 'y', 'þ': 'th', 'ÿ': 'y'
+};
+
+function downcode(string) {
+ return string.toLowerCase().replace(/[^A-Za-z0-9\[\] ]/g,function(a){ return LATIN_MAP[a]||a }).replace(/[^-\w\s]/g, '').replace(/^\s+|\s+$/g, '').replace(/[-\s]+/g, '-');
+};
+
+function remove_auto_anchors() {
+ $('article .wiki-anchor-auto').each(function(idx, anchor) {
+ $(anchor).parent().removeAttr('id');
+ $(anchor).remove();
+ });
+}
+
+function auto_anchors() {
+ $('article div.textcell h1, article div.textcell h2, article div.textcell h3, article div.textcell h4').each(function(idx, elem) {
+ var $elem = $(elem);
+ if ($elem.attr('id')) return;
+ if ($elem.find('.wiki-anchor').length) return;
+ $elem.attr('id', downcode($elem.text()));
+ $('<a class="wiki-anchor wiki-anchor-auto" href="#' + $elem.attr('id') + '">¶</a>').appendTo($elem);
+ });
+}
+
(function(window, document, undefined) {
var Phylly = {
BLOCKS: [
}(window, document));
$(function() {
- Phylly.init(),
- $('div[contenteditable]').each(function(i, elem) {Phylly.bind_events(elem)});
- $('#save').on('click', function() {
- var text = $('div[contenteditable]')[0].innerHTML;
- var csrf = $('[name=csrfmiddlewaretoken]').val();
- $.post('api-save/',
- { text: text, csrfmiddlewaretoken: csrf}
- ).fail(function() {
- $('#save').css('background', 'red');
- });
- return false;
+ $('#quickedit input').on('change', function() {
+ var enable = $(this).is(':checked');
+ if (enable) {
+ remove_auto_anchors();
+ $('div[data-editable]').each(function(i, elem) {
+ $(elem).attr('contenteditable', 'true');
+ var $button = $('<button class="save">Enregistrer</button>');
+ $button[0].div_zone = elem;
+ $button.insertBefore($('#quickedit label'));
+ });
+ Phylly.init(),
+ $('div[data-editable]').each(function(i, elem) {
+ Phylly.bind_events(elem);
+ });
+ $('.save').on('click', function() {
+ var text = $('div[contenteditable]')[0].innerHTML;
+ var csrf = $('[name=csrfmiddlewaretoken]').val();
+ $.post('api-save/',
+ { text: text, csrfmiddlewaretoken: csrf}
+ ).fail(function() {
+ $('.save').addClass('error');
+ }).done(function() {
+ $('.save').removeClass('error');
+ });
+ return false;
+ });
+ } else {
+ auto_anchors();
+ Phylly.off(),
+ $('button.save').remove();
+ $('div[data-editable]').each(function(i, elem) {
+ $(elem).attr('contenteditable', 'false');
+ Phylly.unbind_events(elem);
+ });
+ }
});
+ $('#quickedit input').trigger('change');
});