Uživatel:Miroslav.gajda/common.js: Porovnání verzí
| Řádek 7: | Řádek 7: | ||
} ); | } ); | ||
});*/ | });*/ | ||
| + | |||
| + | mw.loader.using( 'ext.visualEditor.viewPageTarget.init' ).done( function () { | ||
| + | |||
| + | /* | ||
| + | * Localisation messages. | ||
| + | */ | ||
| + | var translations = { | ||
| + | en: { | ||
| + | 'visualeditor-mwsignatureinspector-title': "Your signature" | ||
| + | }, | ||
| + | pl: { | ||
| + | 'visualeditor-mwsignatureinspector-title': "Twój podpis" | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | var userLanguage = mw.config.get( 'wgUserLanguage' ); | ||
| + | mw.messages.set( translations[userLanguage] || translations.en ); | ||
| + | |||
| + | // This configuration method might change without warning in the future if core MediaWiki gets a | ||
| + | // better way to specify which namespaces may have signatures. | ||
| + | var currentNamespace = mw.config.get( 'wgNamespaceNumber' ); | ||
| + | var noSigNamespaces = mw.config.exists( 'wgVisualEditorNoSignatureNamespaces' ) ? | ||
| + | mw.config.get( 'wgVisualEditorNoSignatureNamespaces' ) : | ||
| + | mw.config.get( 'wgContentNamespaces' ); | ||
| + | |||
| + | // Most of all, never enable this in content namespaces (unless configured otherwise). | ||
| + | if ( $.inArray( currentNamespace, noSigNamespaces ) !== -1 ) { | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | // Add signature icon | ||
| + | mw.loader.using( 'mediawiki.util' ).done( function () { | ||
| + | mw.util.addCSS( | ||
| + | '.oo-ui-icon-signature {' + | ||
| + | 'background-image: url(//upload.wikimedia.org/wikipedia/commons/a/a0/WikiFont_signature_icon.svg);' + | ||
| + | '}' | ||
| + | ); | ||
| + | } ); | ||
| + | |||
| + | mw.libs.ve.addPlugin( function () { | ||
| + | return mw.loader.using( ['ext.visualEditor.core', 'ext.visualEditor.mwtransclusion', 'mediawiki.api'] ) | ||
| + | .done( function () { | ||
| + | /* | ||
| + | * Update the timestamp on inserted signatures every minute. | ||
| + | */ | ||
| + | var liveSignatures = []; | ||
| + | setInterval( function () { | ||
| + | var updatedSignatures = []; | ||
| + | for ( var i = 0; i < liveSignatures.length; i++ ) { | ||
| + | var sig = liveSignatures[i]; | ||
| + | try { | ||
| + | sig.forceUpdate(); | ||
| + | updatedSignatures.push( sig ); | ||
| + | } catch ( er ) { | ||
| + | // Do nothing | ||
| + | } | ||
| + | } | ||
| + | liveSignatures = updatedSignatures; | ||
| + | }, 60 * 1000 ); | ||
| + | |||
| + | |||
| + | /** | ||
| + | * ContentEditable MediaWiki signature node. This defines the behavior of the signature node | ||
| + | * inserted into the ContentEditable document. | ||
| + | * | ||
| + | * @class | ||
| + | * @extends ve.ce.MWTransclusionInlineNode | ||
| + | * | ||
| + | * @constructor | ||
| + | * @param {ve.dm.MWSignatureNode} model Model to observe | ||
| + | */ | ||
| + | ve.ce.MWSignatureNode = function VeCeMWSignatureNode( model ) { | ||
| + | // Parent constructor | ||
| + | ve.ce.MWTransclusionInlineNode.call( this, model ); | ||
| + | |||
| + | // DOM changes | ||
| + | this.$element.addClass( 've-ce-mwSignatureNode' ); | ||
| + | |||
| + | // Keep track for magical text updating | ||
| + | liveSignatures.push( this ); | ||
| + | }; | ||
| + | |||
| + | /* Inheritance */ | ||
| + | |||
| + | OO.inheritClass( ve.ce.MWSignatureNode, ve.ce.MWTransclusionInlineNode ); | ||
| + | |||
| + | /* Static Properties */ | ||
| + | |||
| + | ve.ce.MWSignatureNode.static.name = 'mwSignature'; | ||
| + | |||
| + | ve.ce.MWSignatureNode.static.tagName = 'span'; | ||
| + | |||
| + | ve.ce.MWSignatureNode.static.primaryCommandName = 'signature'; | ||
| + | |||
| + | /* Methods */ | ||
| + | |||
| + | ve.ce.MWSignatureNode.prototype.generateContents = function ( config ) { | ||
| + | // Parsoid doesn't support pre-save transforms. PHP parser doesn't support Parsoid's | ||
| + | // meta attributes (that may or may not be required). | ||
| + | |||
| + | // We could try hacking up one (or even both) of these, but just calling the two parsers | ||
| + | // in order seems slightly saner. | ||
| + | |||
| + | var wikitext = '~~' + '~~'; | ||
| + | // We must have only one top-level node, this is the easiest way. | ||
| + | wikitext = '<span>' + wikitext + '</span>'; | ||
| + | var signatureNode = this; | ||
| + | |||
| + | var api = new mw.Api(); | ||
| + | var deferred = $.Deferred(); | ||
| + | var xhr = api.post( { | ||
| + | 'action': 'parse', | ||
| + | 'text': wikitext, | ||
| + | 'contentmodel': 'wikitext', | ||
| + | 'prop': 'text', | ||
| + | 'onlypst': true | ||
| + | } ) | ||
| + | // This code is very wonky… | ||
| + | .done( function ( resp ) { | ||
| + | if ( resp && resp.parse && resp.parse.text && resp.parse.text['*'] ) { | ||
| + | // Call parent method with the wikitext with PST applied. | ||
| + | ve.ce.MWTransclusionInlineNode.prototype.generateContents.call( | ||
| + | signatureNode, | ||
| + | { wikitext: resp.parse.text['*'] } | ||
| + | ).done( function ( nodes ) { | ||
| + | deferred.resolve( nodes ); | ||
| + | } ); | ||
| + | } else { | ||
| + | signatureNode.onParseError( deferred ); | ||
| + | } | ||
| + | } ) | ||
| + | .fail( this.onParseError.bind( this, deferred ) ); | ||
| + | |||
| + | return deferred.promise( { abort: xhr.abort } ); | ||
| + | }; | ||
| + | |||
| + | /* Registration */ | ||
| + | |||
| + | ve.ce.nodeFactory.register( ve.ce.MWSignatureNode ); | ||
| + | |||
| + | |||
| + | /** | ||
| + | * DataModel MediaWiki signature node. This defines the behavior of the data model for the | ||
| + | * signature, especially the fact that it needs to be converted into a wikitext signature on | ||
| + | * save. | ||
| + | * | ||
| + | * @class | ||
| + | * @extends ve.dm.MWTransclusionInlineNode | ||
| + | * | ||
| + | * @constructor | ||
| + | * @param {Object} [element] Reference to element in linear model | ||
| + | */ | ||
| + | ve.dm.MWSignatureNode = function VeDmMWSignatureNode( element ) { | ||
| + | // Parent constructor | ||
| + | ve.dm.MWTransclusionInlineNode.call( this, element ); | ||
| + | }; | ||
| + | |||
| + | /* Inheritance */ | ||
| + | |||
| + | OO.inheritClass( ve.dm.MWSignatureNode, ve.dm.MWTransclusionInlineNode ); | ||
| + | |||
| + | /* Static members */ | ||
| + | |||
| + | ve.dm.MWSignatureNode.static.name = 'mwSignature'; | ||
| + | |||
| + | ve.dm.MWSignatureNode.static.matchTagNames = null; | ||
| + | |||
| + | ve.dm.MWSignatureNode.static.matchRdfaTypes = []; | ||
| + | |||
| + | ve.dm.MWSignatureNode.static.matchFunction = function ( domElement ) { | ||
| + | return false; | ||
| + | }; | ||
| + | |||
| + | ve.dm.MWSignatureNode.static.getHashObject = function ( dataElement ) { | ||
| + | return { | ||
| + | type: dataElement.type | ||
| + | }; | ||
| + | }; | ||
| + | |||
| + | ve.dm.MWSignatureNode.static.toDomElements = function ( dataElement, doc, converter ) { | ||
| + | dataElement = ve.dm.MWSignatureNode.static.toDataElement(); | ||
| + | return ve.dm.MWTransclusionNode.static.toDomElements( dataElement, doc, converter ); | ||
| + | }; | ||
| + | |||
| + | ve.dm.MWSignatureNode.static.toDataElement = function ( domElements, converter ) { | ||
| + | return { | ||
| + | 'type': 'mwTransclusionInline', | ||
| + | 'attributes': { | ||
| + | 'mw': { | ||
| + | 'parts': [ '~~' + '~~' ] | ||
| + | } | ||
| + | } | ||
| + | }; | ||
| + | }; | ||
| + | |||
| + | /* Methods */ | ||
| + | |||
| + | ve.dm.MWSignatureNode.prototype.getPartsList = function () { | ||
| + | return [ { 'content': '~~' + '~~' } ]; | ||
| + | }; | ||
| + | |||
| + | /* Registration */ | ||
| + | |||
| + | ve.dm.modelRegistry.register( ve.dm.MWSignatureNode ); | ||
| + | |||
| + | |||
| + | /** | ||
| + | * MediaWiki UserInterface signature tool. This defines the menu button and its action. | ||
| + | * | ||
| + | * @class | ||
| + | * @extends ve.ui.InspectorTool | ||
| + | * @constructor | ||
| + | * @param {OO.ui.ToolGroup} toolGroup | ||
| + | * @param {Object} [config] Configuration options | ||
| + | */ | ||
| + | ve.ui.MWSignatureTool = function VeUiMWSignatureTool( toolGroup, config ) { | ||
| + | // Parent constructor | ||
| + | ve.ui.MWTransclusionDialogTool.call( this, toolGroup, config ); | ||
| + | }; | ||
| + | OO.inheritClass( ve.ui.MWSignatureTool, ve.ui.MWTransclusionDialogTool ); | ||
| + | |||
| + | ve.ui.MWSignatureTool.static.name = 'signature'; | ||
| + | ve.ui.MWSignatureTool.static.group = 'object'; | ||
| + | ve.ui.MWSignatureTool.static.icon = 'signature'; | ||
| + | ve.ui.MWSignatureTool.static.title = | ||
| + | OO.ui.deferMsg( 'visualeditor-mwsignatureinspector-title' ); | ||
| + | ve.ui.MWSignatureTool.static.modelClasses = [ ve.dm.MWSignatureNode ]; | ||
| + | // Link the tool to the command defined below | ||
| + | ve.ui.MWSignatureTool.static.commandName = 'signature'; | ||
| + | |||
| + | ve.ui.toolFactory.register( ve.ui.MWSignatureTool ); | ||
| + | |||
| + | // Command to insert signature node. | ||
| + | ve.ui.commandRegistry.register( | ||
| + | new ve.ui.Command( 'signature', 'content', 'insert', { args: [ [ | ||
| + | { type: 'mwSignature' }, | ||
| + | { type: '/mwSignature' } | ||
| + | ] ] } ) | ||
| + | ); | ||
| + | |||
| + | } ); | ||
| + | } ); | ||
| + | } ); | ||
Verze z 7. 12. 2014, 14:00
/*mw.loader.using( 'ext.visualEditor.viewPageTarget.init', function(){
// Register plugins to VE. will be loaded once the user opens VE
mw.libs.ve.addPlugin( function() {
return $.getScript("/index.php/MediaWiki:Gadget-CitacePRO1.0.js?action=raw&ctype=text/javascript");
} );
});*/
mw.loader.using( 'ext.visualEditor.viewPageTarget.init' ).done( function () {
/*
* Localisation messages.
*/
var translations = {
en: {
'visualeditor-mwsignatureinspector-title': "Your signature"
},
pl: {
'visualeditor-mwsignatureinspector-title': "Twój podpis"
}
};
var userLanguage = mw.config.get( 'wgUserLanguage' );
mw.messages.set( translations[userLanguage] || translations.en );
// This configuration method might change without warning in the future if core MediaWiki gets a
// better way to specify which namespaces may have signatures.
var currentNamespace = mw.config.get( 'wgNamespaceNumber' );
var noSigNamespaces = mw.config.exists( 'wgVisualEditorNoSignatureNamespaces' ) ?
mw.config.get( 'wgVisualEditorNoSignatureNamespaces' ) :
mw.config.get( 'wgContentNamespaces' );
// Most of all, never enable this in content namespaces (unless configured otherwise).
if ( $.inArray( currentNamespace, noSigNamespaces ) !== -1 ) {
return;
}
// Add signature icon
mw.loader.using( 'mediawiki.util' ).done( function () {
mw.util.addCSS(
'.oo-ui-icon-signature {' +
'background-image: url(//upload.wikimedia.org/wikipedia/commons/a/a0/WikiFont_signature_icon.svg);' +
'}'
);
} );
mw.libs.ve.addPlugin( function () {
return mw.loader.using( ['ext.visualEditor.core', 'ext.visualEditor.mwtransclusion', 'mediawiki.api'] )
.done( function () {
/*
* Update the timestamp on inserted signatures every minute.
*/
var liveSignatures = [];
setInterval( function () {
var updatedSignatures = [];
for ( var i = 0; i < liveSignatures.length; i++ ) {
var sig = liveSignatures[i];
try {
sig.forceUpdate();
updatedSignatures.push( sig );
} catch ( er ) {
// Do nothing
}
}
liveSignatures = updatedSignatures;
}, 60 * 1000 );
/**
* ContentEditable MediaWiki signature node. This defines the behavior of the signature node
* inserted into the ContentEditable document.
*
* @class
* @extends ve.ce.MWTransclusionInlineNode
*
* @constructor
* @param {ve.dm.MWSignatureNode} model Model to observe
*/
ve.ce.MWSignatureNode = function VeCeMWSignatureNode( model ) {
// Parent constructor
ve.ce.MWTransclusionInlineNode.call( this, model );
// DOM changes
this.$element.addClass( 've-ce-mwSignatureNode' );
// Keep track for magical text updating
liveSignatures.push( this );
};
/* Inheritance */
OO.inheritClass( ve.ce.MWSignatureNode, ve.ce.MWTransclusionInlineNode );
/* Static Properties */
ve.ce.MWSignatureNode.static.name = 'mwSignature';
ve.ce.MWSignatureNode.static.tagName = 'span';
ve.ce.MWSignatureNode.static.primaryCommandName = 'signature';
/* Methods */
ve.ce.MWSignatureNode.prototype.generateContents = function ( config ) {
// Parsoid doesn't support pre-save transforms. PHP parser doesn't support Parsoid's
// meta attributes (that may or may not be required).
// We could try hacking up one (or even both) of these, but just calling the two parsers
// in order seems slightly saner.
var wikitext = '~~' + '~~';
// We must have only one top-level node, this is the easiest way.
wikitext = '<span>' + wikitext + '</span>';
var signatureNode = this;
var api = new mw.Api();
var deferred = $.Deferred();
var xhr = api.post( {
'action': 'parse',
'text': wikitext,
'contentmodel': 'wikitext',
'prop': 'text',
'onlypst': true
} )
// This code is very wonky…
.done( function ( resp ) {
if ( resp && resp.parse && resp.parse.text && resp.parse.text['*'] ) {
// Call parent method with the wikitext with PST applied.
ve.ce.MWTransclusionInlineNode.prototype.generateContents.call(
signatureNode,
{ wikitext: resp.parse.text['*'] }
).done( function ( nodes ) {
deferred.resolve( nodes );
} );
} else {
signatureNode.onParseError( deferred );
}
} )
.fail( this.onParseError.bind( this, deferred ) );
return deferred.promise( { abort: xhr.abort } );
};
/* Registration */
ve.ce.nodeFactory.register( ve.ce.MWSignatureNode );
/**
* DataModel MediaWiki signature node. This defines the behavior of the data model for the
* signature, especially the fact that it needs to be converted into a wikitext signature on
* save.
*
* @class
* @extends ve.dm.MWTransclusionInlineNode
*
* @constructor
* @param {Object} [element] Reference to element in linear model
*/
ve.dm.MWSignatureNode = function VeDmMWSignatureNode( element ) {
// Parent constructor
ve.dm.MWTransclusionInlineNode.call( this, element );
};
/* Inheritance */
OO.inheritClass( ve.dm.MWSignatureNode, ve.dm.MWTransclusionInlineNode );
/* Static members */
ve.dm.MWSignatureNode.static.name = 'mwSignature';
ve.dm.MWSignatureNode.static.matchTagNames = null;
ve.dm.MWSignatureNode.static.matchRdfaTypes = [];
ve.dm.MWSignatureNode.static.matchFunction = function ( domElement ) {
return false;
};
ve.dm.MWSignatureNode.static.getHashObject = function ( dataElement ) {
return {
type: dataElement.type
};
};
ve.dm.MWSignatureNode.static.toDomElements = function ( dataElement, doc, converter ) {
dataElement = ve.dm.MWSignatureNode.static.toDataElement();
return ve.dm.MWTransclusionNode.static.toDomElements( dataElement, doc, converter );
};
ve.dm.MWSignatureNode.static.toDataElement = function ( domElements, converter ) {
return {
'type': 'mwTransclusionInline',
'attributes': {
'mw': {
'parts': [ '~~' + '~~' ]
}
}
};
};
/* Methods */
ve.dm.MWSignatureNode.prototype.getPartsList = function () {
return [ { 'content': '~~' + '~~' } ];
};
/* Registration */
ve.dm.modelRegistry.register( ve.dm.MWSignatureNode );
/**
* MediaWiki UserInterface signature tool. This defines the menu button and its action.
*
* @class
* @extends ve.ui.InspectorTool
* @constructor
* @param {OO.ui.ToolGroup} toolGroup
* @param {Object} [config] Configuration options
*/
ve.ui.MWSignatureTool = function VeUiMWSignatureTool( toolGroup, config ) {
// Parent constructor
ve.ui.MWTransclusionDialogTool.call( this, toolGroup, config );
};
OO.inheritClass( ve.ui.MWSignatureTool, ve.ui.MWTransclusionDialogTool );
ve.ui.MWSignatureTool.static.name = 'signature';
ve.ui.MWSignatureTool.static.group = 'object';
ve.ui.MWSignatureTool.static.icon = 'signature';
ve.ui.MWSignatureTool.static.title =
OO.ui.deferMsg( 'visualeditor-mwsignatureinspector-title' );
ve.ui.MWSignatureTool.static.modelClasses = [ ve.dm.MWSignatureNode ];
// Link the tool to the command defined below
ve.ui.MWSignatureTool.static.commandName = 'signature';
ve.ui.toolFactory.register( ve.ui.MWSignatureTool );
// Command to insert signature node.
ve.ui.commandRegistry.register(
new ve.ui.Command( 'signature', 'content', 'insert', { args: [ [
{ type: 'mwSignature' },
{ type: '/mwSignature' }
] ] } )
);
} );
} );
} );
var MediaWikiGadgetCitacePRO = (function() {
var xml;
var server = "//www.citacepro.com/";
var aktualniDialog = "";
var $naseptavac = $('<div id="CitacePRONaseptavac"></div>');
var login = "";
// Prida ikonku CitacePRO do toolbaru a nacte shibboleth identifikator prihlaseneho uzivatele.
var init = function() {
var $tlacitko = $('<a class="ve-ui-widget ve-ui-tool ve-ui-tool-bold" title="Vložit citaci"><span class="ve-ui-iconedElement-icon" style="background-image: url(//www.citacepro.com/citace22.png)"></span></a>');
$tlacitko.click(function () {
vytvoritCitaci();
});
$("div.ve-ui-toolbar-tools div:nth-child(3) div:eq(0)").append($tlacitko);
if (window.mw) {
var unstructuredName = mw.config.get('unstructuredName');
if (unstructuredName != null && unstructuredName.match(/^\d+$/)) {
login = unstructuredName;
}
}
}
// Zobrazi vyhledavaci policko v dialogovem okne.
var vytvoritCitaci = function () {
aktualniDialog = "vytvoritCitaci";
$dialog = $('<form></form>');
var odstavec = $('<p>Zadejte ISBN, DOI, název nebo URL: </p>');
var vyhledavaciPolicko = $('<input type="text" id="CitacePROHledanyText"/>');
vyhledavaciPolicko.keyup(function () {
zobrazitNaseptavac($(this).val());
});
odstavec.append(vyhledavaciPolicko);
$dialog.append(odstavec);
$dialog.dialog({
autoOpen: true, title: 'Vložení citace', width: 700, minHeight: 500, modal: true,
buttons: {
"Dohledat": function (e) {
prehledCitaci($("#CitacePROHledanyText").val());
},
"Nový": function (e) {
pouzitCitaci("Kniha");
}
},
close: function () {
$(this).dialog('destroy').remove();
}
});
$dialog.keypress(function (e) {
if (aktualniDialog == "vytvoritCitaci" && e.keyCode == $.ui.keyCode.ENTER) {
if ($("#CitacePROHledanyText").val() == "") {
pouzitCitaci("Kniha");
} else {
prehledCitaci($("#CitacePROHledanyText").val());
}
}
});
};
// Zobrazi nasepatavac
var zobrazitNaseptavac = function (hledanyText) {
$naseptavac.empty();
$.get(server + "naseptavac-mediawiki/" + login + "?text=" + encodeURIComponent(hledanyText), function (data) {
var i = 0;
xml = data;
$(data).find('dokument').each(function () {
var prvniRadek = $(this).find("nazev").text() + ($(this).find("identifikator").text() == "" ? "" : " (" + $(this).find("identifikator").text() + ")");
var druhyRadek = (($(this).find("autoriText").text() == "" ? "" : $(this).find("autoriText").text() + "; ")) + $(this).find("druhNazev").text() + "; " + (($(this).find("datum_vydani").text() == "" ? ($(this).find("celekDatumVydani").text() == "" ? "" : $(this).find("celekDatumVydani").text()) : $(this).find("datum_vydani").text()));
var $odkaz = $('<a class="zaznam' + (i % 2) + '" id="nascit' + i + '"><div class="prvniRadek">' + prvniRadek + '</div><div class="druhyRadek">' + druhyRadek + '</div></a>');
$odkaz.click(function () {
pouzitCitaci($(this).attr("id").substring(6));
});
$naseptavac.append($odkaz);
i++;
});
if (i > 0) {
$naseptavac.show();
} else {
$naseptavac.hide();
}
});
};
// Zobrazi prehled dohledanych citace v dialogovem okne.
var prehledCitaci = function (text) {
aktualniDialog = "prehledCitaci";
$dialog.html('');
var nacitani = $('<div id="nacitani">Načítání...</div>');
$dialog.append(nacitani);
var $seznam = $('<ul id="CitacePRODohledaneCitace"></ul>');
$.get(server + "xml/naseptavac-dohledani.php?text=" + encodeURIComponent(text), function (data) {
var i = 0;
xml = data;
$(data).find('dokument').each(function () {
var $li = $('<li></li>');
var $odkaz = $('<a class="nalezenaCitace" style="cursor: pointer;" id="citace' + i + '">' + $(this).find("citace").text() + '</a>');
$odkaz.click(function () {
pouzitCitaci($(this).attr("id").substring(6));
});
$li.append($odkaz);
$seznam.append($li);
i++;
});
$("#nacitani").html(i > 0 ? "Zvolte citaci:" : "Nenalezena žádná citace.");
});
$dialog.append($seznam);
$dialog.dialog('option', 'buttons', {"Nový": function (e) {
pouzitCitaci("Kniha");
}});
};
// Skryje nebo zobrazi polozky v editacnim formulari citace dle zvoleneho druhu.
var zmenaDruhu = function (druh, forma) {
if (druh == 12 || druh == 19) {
forma = true;
}
$("#radekAutori").css("display", druh != 12 ? "table-row" : "none");
$("#radekPodnazev").css("display", druh != 12 ? "table-row" : "none");
$("#radekVydani").css("display", druh == 1 || druh == 18 ? "table-row" : "none");
$("#radekMisto").css("display", druh != 9 ? "table-row" : "none");
$("#radekVydavatel").css("display", druh == 1 || druh == 18 || druh == 19 || druh == 12 ? "table-row" : "none");
//$("#radekAutoriCelku").css("display", druh == 18 ? "table-row" : "none");
$("#radekNazevCasopisu").css("display", druh == 9 || druh == 18 || druh == 19 || druh == 12 ? "table-row" : "none");
$("#radekRocnik").css("display", druh == 9 ? "table-row" : "none");
$("#radekCislo").css("display", druh == 9 ? "table-row" : "none");
$("#radekPocetStran").css("display", druh == 1 || druh == 5 ? "table-row" : "none");
$("#radekRozsahStran").css("display", druh == 9 || druh == 18 ? "table-row" : "none");
$("#radekISBN").css("display", druh == 1 || druh == 18 ? "table-row" : "none");
$("#radekDOI").css("display", druh == 9 && forma ? "table-row" : "none");
$("#radekSkola").css("display", druh == 5 ? "table-row" : "none");
$("#radekDruhPrace").css("display", druh == 5 ? "table-row" : "none");
$("#radekVedouci").css("display", druh == 5 ? "table-row" : "none");
$("#radekNosic").css("display", forma ? "table-row" : "none");
if (forma && $("#nosic").val() == "") {
$("#nosic").val("on-line");
}
$("#formy").css("display", druh == 12 || druh == 19 ? "none" : "inline-block");
$("#online").attr("checked", forma);
};
// Zobrazi formular pro editaci citace v dialogovem okne.
var pouzitCitaci = function (pouzitaCitace) {
aktualniDialog = "pouzitCitaci";
var druhID = 1;
if ("Kniha" != pouzitaCitace) {
$(xml).find('dokument').eq(pouzitaCitace).each(function () {
druhID = $(this).find("druh").text();
});
}
if (druhID == 4) {
druhID = 9;
} else if (druhID == 6) {
druhID = 1;
} else if (druhID == 16) {
druhID = 18;
} else if (druhID == 10) {
druhID = 5;
}
var genre = "book";
$dialog.html('');
var druhForma = $('<td></td>');
var $druh = $('<select name="druh" id="druh"></select>');
$druh.append($("<option" + (druhID == 1 ? ' selected="selected"' : '') + ' value="1">Kniha</option>'));
$druh.append($("<option" + (druhID == 9 ? ' selected="selected"' : '') + ' value="9">Článek</option>'));
$druh.append($("<option" + (druhID == 18 ? ' selected="selected"' : '') + ' value="18">Příspěvek ve sborníku</option>'));
$druh.append($("<option" + (druhID == 12 ? ' selected="selected"' : '') + ' value="12">Webová stránka</option>'));
$druh.append($("<option" + (druhID == 19 ? ' selected="selected"' : '') + ' value="19">Příspěvek na webu</option>'));
$druh.append($("<option" + (druhID == 5 ? ' selected="selected"' : '') + ' value="5">Akademická práce</option>'));
$druh.change(function () {
zmenaDruhu($("#druh").val(), $("#online").is(":checked"));
});
druhForma.append($druh);
var tisteny = $('<input type="radio" id="tisteny" name="forma" value="0" checked="checked"/>');
tisteny.click(function () {
zmenaDruhu($("#druh").val(), false);
});
var online = $('<input type="radio" id="online" name="forma" value="1"/>');
online.click(function () {
zmenaDruhu($("#druh").val(), true);
});
var forma = $('<span id="formy"></span>');
forma.append(tisteny);
forma.append('<label for="tisteny">Tištěný</label>');
forma.append(online);
forma.append('<label for="online">On-line</label>');
druhForma.append(forma);
var $tabulka = $('<table id="CitacePROFormularovaTabulka"></table>');
$tabulka.append($("<tr></tr>").append($("<th>Druh: </th>")).append(druhForma));
if ("Kniha" == pouzitaCitace) {
$tabulka.append($('<tr id="radekAutori"><th>Autoři:</th><td><input type="text" name="autoriText" id="autoriText" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekNazev"><th>Název:</th><td><input type="text" name="nazev" id="nazev" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekPodnazev"><th>Podnázev:</th><td><input type="text" name="podnazev" id="podnazev" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekVydani"><th>Vydání:</th><td><input type="text" name="vydani" id="vydani" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekMisto"><th>Místo vydání:</th><td><input type="text" name="misto_vydani" id="misto_vydani" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekVydavatel"><th>Vydavatel:</th><td><input type="text" name="nakladatelstvi" id="nakladatelstvi" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekNazevCasopisu"><th>Název celku:</th><td><input type="text" name="celekNazev" id="celekNazev" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekRok"><th>Rok:</th><td><input type="text" name="datum_vydani" id="datum_vydani" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekPocetStran"><th>Počet stran:</th><td><input type="text" name="pocet_stran" id="pocet_stran" value=""/></td></tr>'));
//$tabulka.append($('<tr id="radekAutoriCelku"><th>Autoři sborníku:</th><td><input type="text" name="autoriText" id="autoriText" value="' + $(this).find("autoriCelekTextCely").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekRocnik"><th>Ročník:</th><td><input type="text" name="rocnikPeriodika" id="rocnikPeriodika" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekCislo"><th>Číslo:</th><td><input type="text" name="cisloPeriodika" id="cisloPeriodika" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekRozsahStran"><th>Rozsah stran:</th><td><input type="text" name="rozsah_stran" id="rozsah_stran" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekISBN"><th>ISBN:</th><td><input type="text" name="isbn" id="isbn" value=""/></td></tr>'));
$tabulka.append($('<tr><th>URL:</th><td><input type="text" name="url" id="url" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekNosic"><th>Nosič:</th><td><input type="text" name="nosic" id="nosic" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekDOI"><th>DOI:</th><td><input type="text" name="doi" id="doi" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekSkola"><th>Škola:</th><td><input type="text" name="skola" id="skola" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekDruhPrace"><th>Druh práce:</th><td><input type="text" name="druh_prace" id="druh_prace" value=""/></td></tr>'));
$tabulka.append($('<tr id="radekVedouci"><th>Vedoucí práce:</th><td><input type="text" name="vedouci_prace" id="vedouci_prace" value=""/></td></tr>'));
} else {
$(xml).find('dokument').eq(pouzitaCitace).each(function () {
$tabulka.append($('<tr id="radekAutori"><th>Autoři:</th><td><input type="text" name="autoriText" id="autoriText" value="' + $(this).find("autoriTextCely").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekNazev"><th>Název:</th><td><input type="text" name="nazev" id="nazev" value="' + $(this).find("nazev").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekPodnazev"><th>Podnázev:</th><td><input type="text" name="podnazev" id="podnazev" value="' + $(this).find("podnazev").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekVydani"><th>Vydání:</th><td><input type="text" name="vydani" id="vydani" value="' + $(this).find("vydani").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekMisto"><th>Místo vydání:</th><td><input type="text" name="misto_vydani" id="misto_vydani" value="' + $(this).find(druhID == 12 || druhID == 18 || druhID == 19 ? "celekMistoVydani" : "misto_vydani").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekVydavatel"><th>Vydavatel:</th><td><input type="text" name="nakladatelstvi" id="nakladatelstvi" value="' + $(this).find(druhID == 12 || druhID == 18 || druhID == 19 ? "celekNakladatelstvi" : "nakladatelstvi").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekNazevCasopisu"><th>Název celku:</th><td><input type="text" name="celekNazev" id="celekNazev" value="' + $(this).find("celekNazev").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekRok"><th>Rok:</th><td><input type="text" name="datum_vydani" id="datum_vydani" value="' + $(this).find(druhID == 12 || druhID == 18 || druhID == 19 ? "celekDatumVydani" : "datum_vydani").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekPocetStran"><th>Počet stran:</th><td><input type="text" name="pocet_stran" id="pocet_stran" value="' + $(this).find("pocet_stran").text() + '"/></td></tr>'));
//$tabulka.append($('<tr id="radekAutoriCelku"><th>Autoři sborníku:</th><td><input type="text" name="autoriText" id="autoriText" value="' + $(this).find("autoriCelekTextCely").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekRocnik"><th>Ročník:</th><td><input type="text" name="rocnikPeriodika" id="rocnikPeriodika" value="' + $(this).find("celekRocnikPeriodika").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekCislo"><th>Číslo:</th><td><input type="text" name="cisloPeriodika" id="cisloPeriodika" value="' + $(this).find("celekCisloPeriodika").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekRozsahStran"><th>Rozsah stran:</th><td><input type="text" name="rozsah_stran" id="rozsah_stran" value="' + $(this).find("rozsah_stran").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekISBN"><th>ISBN:</th><td><input type="text" name="isbn" id="isbn" value="' + $(this).find("isbn").text() + '"/></td></tr>'));
$tabulka.append($('<tr><th>URL:</th><td><input type="text" name="url" id="url" value="' + $(this).find("url").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekNosic"><th>Nosič:</th><td><input type="text" name="nosic" id="nosic" value="' + $(this).find("nosic").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekDOI"><th>DOI:</th><td><input type="text" name="doi" id="doi" value="' + $(this).find("doi").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekSkola"><th>Škola:</th><td><input type="text" name="skola" id="skola" value="' + $(this).find("skola").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekDruhPrace"><th>Druh práce:</th><td><input type="text" name="druh_prace" id="druh_prace" value="' + $(this).find("druh_prace").text() + '"/></td></tr>'));
$tabulka.append($('<tr id="radekVedouci"><th>Vedoucí práce:</th><td><input type="text" name="vedouci_prace" id="vedouci_prace" value="' + $(this).find("vedouci_prace").text() + '"/></td></tr>'));
});
}
var citacniStyl = $('<td></td>');
var citacniStylSelect = $('<select name="styl" id="styl"></select>');
citacniStylSelect.append($('<option value="11">APA</option>'));
citacniStylSelect.append($('<option value="9">CSE</option>'));
citacniStylSelect.append($('<option value="10">CSE NY</option>'));
citacniStylSelect.append($('<option value="2" selected="selected">ČSN ISO 690</option>'));
citacniStylSelect.append($('<option value="3">Harvard</option>'));
citacniStylSelect.append($('<option value="7">Chicago (16th edition)</option>'));
citacniStylSelect.append($('<option value="8">IEEE</option>'));
citacniStylSelect.append($('<option value="12">ISO 690</option>'));
citacniStylSelect.append($('<option value="5">MLA (7th edition)</option>'));
citacniStylSelect.append($('<option value="4">NISO / ANSI Z39.29 (2005)</option>'));
citacniStylSelect.append($('<option value="6">Turbian (7th edition)</option>'));
citacniStyl.append(citacniStylSelect);
$tabulka.append($("<tr></tr>").append($("<th>Citační styl: </th>")).append(citacniStyl));
$dialog.append($tabulka);
if (druhID == 9) {
genre = "article";
zmenaDruhu(9, true);
} else if (druhID == 18) {
genre = "proceeding";
zmenaDruhu(18, true);
} else if (druhID == 19) {
genre = "wikipedia";
zmenaDruhu(19, true);
} else if (druhID == 12) {
genre = "web";
zmenaDruhu(12, true);
} else if (druhID == 5) {
genre = "thesis";
zmenaDruhu(5, false);
} else {
zmenaDruhu(1, false);
}
$dialog.dialog('option', 'buttons', {"Vložit citaci": function (e) {
var url = server + "vygenerovat-citaci?genre=" + genre
+ "&citacepro_style=" + $("#styl").val()
+ (druhID != 12 ? "&authors=" + $("#autoriText").val() : "")
+ (druhID == 1 || druhID == 5 || druhID == 12 ? "&title=" + $("#nazev").val() + (":" + $("#podnazev").val()) : "")
+ (druhID == 9 || druhID == 18 || druhID == 19 ? "&atitle=" + $("#nazev").val() + (":" + $("#podnazev").val()) : "")
+ (druhID == 9 || druhID == 18 || druhID == 19 ? "&title=" + $("#celekNazev").val() : "")
+ (druhID == 1 || druhID == 18 ? "&edition=" + $("#vydani").val() : "")
+ (druhID != 19 ? "&place=" + $("#misto_vydani").val() : "")
+ (druhID == 1 || druhID == 18 || druhID == 19 || druhID == 12 ? "&publisher=" + $("#nakladatelstvi").val() : "")
+ "&year=" + $("#datum_vydani").val()
+ (druhID == 9 ? "&volume=" + $("#rocnikPeriodika").val() : "")
+ (druhID == 9 ? "&issue=" + $("#cisloPeriodika").val() : "")
+ (druhID == 1 || druhID == 5 ? "&pages=" + $("#pocet_stran").val() : "")
+ (druhID == 9 || druhID == 18 ? "&pages=" + $("#rozsak_stran").val() : "")
+ (druhID == 1 || druhID == 18 ? "&isbn=" + $("#isbn").val() : "")
+ "&url=" + $("#url").val()
+ (druhID == 9 && $("#online").is(":checked") ? "&doi=" + $("#doi").val() : "")
+ (druhID == 5 ? "&school=" + $("#skola").val() + "&supervisor=" + $("#vedouci_prace").val() : "");
$.get(url, function (data) {
//alert(data);
//var surfaceModel = ve.init.target.getSurface().getModel();
//var selection = surfaceModel.getSelection();
// If selection is an instance of ve.dm.LinearSelection (as opposed to NullSelection or TableSelection)
// you can get a range (start and end offset) using:
//var range = selection.getRange();
//range = data;
var rangeToRemove = new ve.Range( 2, 4);
var surfaceModel = ve.init.target.getSurface().getModel();
var fragment = surfaceModel.getLinearFragment( rangeToRemove );
fragment.insertContent( data);
//$('#wpTextbox1').textSelection('encapsulateSelection', {pre: "<ref>", peri: data, post: "</ref>"});
$dialog.dialog("close");
});
}});
};
// Vyhleda hodnotu v XML.
var getNodeValue = function getNodeValue(obj, tag) {
if (obj.getElementsByTagName(tag) != null) {
if (obj.getElementsByTagName(tag)[0] != null) {
if (obj.getElementsByTagName(tag)[0].firstChild != null) {
return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
}
}
}
return null;
};
return {
init: init
};
})();
mw.hook( 've.activationComplete' ).add(function(){
var surfaceModel = ve.init.target.getSurface().getModel();
var selection = surfaceModel.getSelection();
// If selection is an instance of ve.dm.LinearSelection (as opposed to NullSelection or TableSelection)
// you can get a range (start and end offset) using:
var range = selection.getRange();
//$(document).ready(MediaWikiGadgetCitacePRO.init);
//var rangeToRemove = new ve.Range( 2, 4);
//var surfaceModel = ve.init.target.getSurface().getModel();
//var fragment = surfaceModel.getLinearFragment( rangeToRemove );
//fragment.insertContent("test" );
});