Difference between revisions of "MediaWiki:Edittools"
Jump to navigation
Jump to search
(Created page with "// <source lang="javascript"> /* EditTools support: add a selector, change into true buttons, enable for all text input fields If enabled in preferences, the script puts t...") |
|||
| (52 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
<!--//<div id="mw-edittools-charinsert" class="mw-charinsert-buttons" title="Click on the wanted special character."> |
|||
// <source lang="javascript"> |
|||
<p class="mw-edittools-section" data-section-title="Wiki-Syntax" style="display: none;"> --> |
|||
/* |
|||
EditTools support: add a selector, change into true buttons, enable for all text input fields |
|||
<div id="mw-edittools-charinsert" class="mw-charinsert-buttons" title="Click on the wanted special character."> |
|||
If enabled in preferences, the script puts the buttons into the WikiEditor Toolbar |
|||
<div class="mw-edittools-section" data-section-title="Category"> |
|||
The special characters to insert are defined at [[MediaWiki:Edittools]]. |
|||
Functions: <charinsert>[[Category:Economic]]+</charinsert> |
|||
*/ |
|||
<charinsert>[[Category:Mobility]]+</charinsert> |
|||
<charinsert>[[Category:Safety]]+</charinsert> |
|||
/*jshint curly:false */ |
|||
<charinsert>[[Category:Social]]+</charinsert> |
|||
/*global importStylesheetURI:false, jQuery:false, mediaWiki:false */ |
|||
Issues: <charinsert>[[Category:Ethical]]+</charinsert> |
|||
(function($, mw) { |
|||
<charinsert>[[Category:Legal]]+</charinsert> |
|||
"use strict"; |
|||
var EditTools, insertTags; |
|||
Measures: <charinsert>[[Category:Measure]]+</charinsert> |
|||
importStylesheetURI('//commons.wikimedia.org/?title=MediaWiki:Edittools.css&action=raw&ctype=text/css'); |
|||
Threats: <charinsert>[[Category:Threat]]+</charinsert> |
|||
window.insertTags = insertTags = function(tagOpen, tagClose, sampleText) { |
|||
var $txtarea = EditTools.getTextArea(); |
|||
Objects: <charinsert>[[Category:<nowiki>Urban environment</nowiki>]]+</charinsert> |
|||
if ($txtarea.length !== 1) return; |
|||
<charinsert>[[Category:<nowiki>Urban object</nowiki>]]+</charinsert> |
|||
</div> |
|||
/* Usability initiative compatibility */ |
|||
if (typeof $.fn.textSelection !== 'undefined') { |
|||
<div class="mw-edittools-section" data-section-title="Relation" style="display: none;"> |
|||
$txtarea.textSelection('encapsulateSelection', { |
|||
Equality: <charinsert>[[<nowiki>is synonymous to</nowiki>::+]]</charinsert> |
|||
'pre': tagOpen, |
|||
<charinsert>[[<nowiki>is the opposite of</nowiki>::+]]</charinsert> |
|||
'peri': sampleText, |
|||
'post': tagClose |
|||
Logical part of: <charinsert>[[<nowiki>comprises</nowiki>::+]]</charinsert> |
|||
}); |
|||
<charinsert>[[<nowiki>belongs to</nowiki>::+]]</charinsert> |
|||
return; |
|||
} |
|||
Physical part of: <charinsert>[[<nowiki>is part of</nowiki>::+]]</charinsert> |
|||
}; |
|||
<charinsert>[[<nowiki>contains</nowiki>::+]]</charinsert> |
|||
window.EditTools = EditTools = { |
|||
createSelector: function() { |
|||
Way to do: <charinsert>[[<nowiki>is a way to</nowiki>::+]]</charinsert> |
|||
var $spec = $('#specialchars'); |
|||
<charinsert>[[<nowiki>can be done by</nowiki>::+]]</charinsert> |
|||
var $sb = $('#specialchars p.specialbasic'); |
|||
Cause: <charinsert>[[<nowiki>causes</nowiki>::+]]</charinsert> |
|||
// Only care if there is more than one |
|||
<charinsert>[[<nowiki>is caused by</nowiki>::+]]</charinsert> |
|||
if (!$spec.length || $sb.length <= 1) return; |
|||
Related reactions: <charinsert>[[<nowiki>correlates to</nowiki>::+]]</charinsert> |
|||
var $sel = $('<select>'); |
|||
Wants to: <charinsert>[[<nowiki>strives towards</nowiki>::+]]</charinsert> |
|||
$sel.change(function() { |
|||
<charinsert>[[<nowiki>is goal for</nowiki>::+]]</charinsert> |
|||
EditTools.chooseCharSubset(); |
|||
}); |
|||
Sub /superconcept: <charinsert>[[<nowiki>is an attribute of</nowiki>::+]]</charinsert> |
|||
<charinsert>[[<nowiki>has attribute</nowiki>::+]]</charinsert> |
|||
$sb.each(function(i) { |
|||
</div> |
|||
var id = $(this).attr('id').replace(/.([0-9A-F][0-9A-F])/g, '%$1').replace(/_/g, ' '); |
|||
</div> |
|||
$sel.append('<option value=' + i + '>' + decodeURIComponent(id) + '</option>'); |
|||
}); |
|||
$spec.prepend($sel); |
|||
this.chooseCharSubset(); |
|||
}, |
|||
chooseCharSubset: function() { |
|||
var $sb = $('#specialchars p.specialbasic'); |
|||
var id = $('#specialchars select').val(); |
|||
var $wanted = $sb.eq(id); |
|||
this.makeButtons($wanted); |
|||
$sb.hide(); |
|||
$wanted.css('display', 'inline'); |
|||
}, |
|||
bindOnClick: function($button, _this) { |
|||
var onclick = _this.getAttribute("onclick"); |
|||
// if onclick is not a function, it's not IE7, so use setAttribute |
|||
if ('function' !== typeof onclick) { |
|||
$button[0].setAttribute('onclick', onclick); // for FF,IE8,Chrome |
|||
// if onclick is a function, use the IE7 method and call onclick() in the anonymous function |
|||
} else { |
|||
$button[0].onclick = function() { |
|||
onclick(); |
|||
}; // for IE7 |
|||
} |
|||
}, |
|||
makeButtons: function($wanted) { |
|||
var $links = $wanted.find('a'); |
|||
var _this = this; |
|||
$links.each(function() { |
|||
var $button = $('<button type="button">'); |
|||
$button.text($(this).text()); |
|||
_this.bindOnClick($button, this); |
|||
$(this).replaceWith($button); |
|||
$(this).blur(); |
|||
}); |
|||
$wanted.contents().not('button').remove(); |
|||
}, |
|||
makeToolbarButtons: function() { |
|||
var _this = this; |
|||
// Add Edittool section |
|||
$('#wpTextbox1').wikiEditor('addToToolbar', { |
|||
'sections': { |
|||
'Edittools': { |
|||
'type': 'booklet', |
|||
'label': 'Edittools', |
|||
'pages': { |
|||
'Edittools1': { |
|||
'layout': 'characters', |
|||
'label': 'Edittools2' |
|||
} |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
var $section = $('.page-Edittools1 div'); |
|||
var $links = $('#specialchars p.specialbasic').eq(0).find('a'); |
|||
$links.each(function() { |
|||
var $button = $('<span>'); |
|||
$button.text($(this).text()); |
|||
_this.bindOnClick($button, this); |
|||
$section.append($button); |
|||
}); |
|||
$('.mw-editTools').remove(); |
|||
}, |
|||
last_active_textfield: null, |
|||
enableForAllFields: function() { |
|||
$('textarea, input').focus(function() { |
|||
EditTools.last_active_textfield = this.id; |
|||
}); |
|||
}, |
|||
getTextArea: function() { |
|||
var $txtarea = {}; |
|||
if (EditTools.last_active_textfield !== null) $txtarea = $('#' + EditTools.last_active_textfield).eq(0); |
|||
if ($txtarea.length !== 1) { |
|||
$txtarea = $('#bodyContent textarea').eq(0); |
|||
} |
|||
return $txtarea; |
|||
}, |
|||
registerTextField: function(evt) { |
|||
var e = evt || window.event; |
|||
var node = e.target || e.srcElement; |
|||
if (!node) return; |
|||
EditTools.last_active_textfield = node.id; |
|||
return true; |
|||
}, |
|||
setup: function() { |
|||
//Decide whether to use the toolbar or the bottom div |
|||
if (window.oldEdittools || "1" === mw.user.options.get('gadget-OldEdittools') || $('#wpUploadDescription').length || !$.wikiEditor || !$.wikiEditor.isSupported()) { |
|||
EditTools.createSelector(); |
|||
EditTools.enableForAllFields(); |
|||
} else { |
|||
EditTools.makeToolbarButtons(); |
|||
EditTools.enableForAllFields(); |
|||
} |
|||
} |
|||
}; |
|||
$(document).ready(function() { |
|||
// Don't do anything if no edittools present. |
|||
if ($('#specialchars').length !== 1) return; |
|||
mw.loader.using('mediawiki.user', function() { |
|||
// Check user preferences |
|||
if (1 === mw.user.options.get('usebetatoolbar') && "1" !== mw.user.options.get('gadget-OldEdittools')) { |
|||
mw.loader.using(['ext.wikiEditor.toolbar', 'jquery.wikiEditor.toolbar'], EditTools.setup); |
|||
} else { |
|||
EditTools.setup(); |
|||
} |
|||
}); |
|||
}); |
|||
// </source> |
|||
}(jQuery, mediaWiki)); |
|||
Latest revision as of 11:46, 23 July 2012
Functions: <charinsert>+</charinsert> <charinsert>+</charinsert> <charinsert>+</charinsert> <charinsert>+</charinsert>
Issues: <charinsert>+</charinsert> <charinsert>+</charinsert>
Measures: <charinsert>+</charinsert>
Threats: <charinsert>+</charinsert>
Objects: <charinsert>[[Category:Urban environment]]+</charinsert> <charinsert>[[Category:Urban object]]+</charinsert>