MediaWiki:Wikisource.citeBox.js

Vikikaynak, özgür kütüphane

Not: Yayımladıktan sonra değişiklikleri görmek için tarayıcınızın önbelleğini temizlemeniz gerekebilir.

  • Firefox / Safari: Shift tuşuna basılıyken Yeniden Yükle'ye tıklayın ya da Ctrl-F5 ya da Ctrl-R tıklayın (Mac için ⌘-R).
  • Google Chrome: Ctrl-Shift-R'ye basın. (Mac için ⌘-Shift-R)
  • Internet Explorer / Edge: Ctrl basılıyken Yenile'ye tıklayın ya da Ctrl-F5 yapın.
  • Opera: Ctrl-F5 tıklayın.
/*********************
Bir kitaptan alıntı
Yazar: Tpt
*********************/
if(typeof ws == 'undefined') {
    ws = {};
}

ws.citeBox = {
  defaultTemplate: 'Liste',
  templates: {},
  data: {},
  i18n: { 
    title: 'Bu kitabı alıntılayın',
    description: 'Bu kitaba atıfta bulunun.',
    display_mode: 'Ekran modu:'
  },
  isInit: false,

  add: function(name, content) {
    this.templates[name] = content;
  },

  init: function( i18np ) {
    if( $('div#citeBox').length > 0) {
        return;
    }
    $.extend(this.i18n, i18np);

    $.getScript('//wikisource.org/w/index.php?title=MediaWiki:Wikisource.data.js&action=raw&ctype=text/javascript', function() {
      mw.loader.using(['jquery.ui', 'mediawiki.util'], function() {
        var message = $('<div id="citeBox" title="' + ws.citeBox.i18n.title + '"></div>').appendTo("#content");
        message.dialog({
          autoOpen: false,
          modal: true,
          width: 500,
          buttons: {
            Tamam: function() {
              $(this).dialog("close");
            }
          }
        });
        var portletLink = mw.util.addPortletLink('p-tb', '#', ws.citeBox.i18n.title, 't-cite', ws.citeBox.i18n.description);
        ws.citeBox.data = ws.data.getAll();
        $(portletLink).click(function() {
          ws.citeBox.open();
        });
        ws.citeBox.isInit = true;
      });
    });
  },

  getContent: function() {
    var content = '<p><label for="citeBox-select">' + this.i18n.display_mode + '</label> <select id="citeBox-select">';
    for(var id in this.templates) {
       content += '<option value="' + id + '">' + id + '</option>';
    }
    content += '</select></p><div id="citeBox-content">' + this.format(this.defaultTemplate) + '</div>';
    return content;
  },

  format: function(id) {
    var func = this.templates[id];
    return func(this.data);
  },

  open: function() {
  	if(!ws.citeBox.isInit) {
  		//Wait for initialization
  		setTimeout(ws.citeBox.open, 100);
  		return;
  	}
    var citeBox = $('div#citeBox');
    if(citeBox.text() == '') {
      citeBox.html(ws.citeBox.getContent());
      $("select#citeBox-select").change(function () {
        var node = $("select#citeBox-select option:selected");
        if(node.length)
          $('#citeBox-content').html(ws.citeBox.format(node.text()));
      });
    }
    citeBox.dialog("open");
  }
};

/*
Configuration : utiliser la fonction ws.citeBox.add prenant en premier paramètre le nom du type de référence et sen second une fonction prenant en paramètre un tableau associatif des métadonnées et retournant la référence.
*/
if((mw.config.get('wgNamespaceNumber') == 0 || mw.config.get('wgCanonicalNamespace') == 'Index') && (mw.config.get('wgAction') == 'view' || mw.config.get('wgAction') == 'purge')) {
  $(function() {
    ws.citeBox.add('Liste', function(data) {
      content = '<ul>';
      if(data.title)
        content += '<li>Başlık: ' + data.title + '</li>';
      if(data.periodical)
        content += '<li>Dergi: ' + data.periodical + '</li>';
      if(data.volume)
        content += '<li>Cilt: ' + data.volume + '</li>';
      if(data.author)
        content += '<li>Yazar(lar) : ' + data.author + '</li>';
      if(data.translator)
        content += '<li>Çevirmen(ler) : ' + data.translator + '</li>';
      if(data.illustrator)
        content += '<li>Resimleyen(ler) : ' + data.illustrator + '</li>';
      if(data.publisher)
        content += '<li>Editör: ' + data.publisher + '</li>';
      if(data.school)
        content += '<li>Kurum: ' + data.school + '</li>';
      if(data.year)
        content += '<li>Yayımcı: ' + data.year + '</li>';
      if(data.place)
        content += '<li>Basım yeri: ' + data.place + '</li>';
      if(data.chapter)
        content += '<li>Bölüm: ' + data.chapter + '</li>';
      if(data.pages) {
        if(data.pages.length > 4) {
          content += '<li>Sayfalar: ' + data.pages + '</li>';
        } else {
          content += '<li>Sayfa: ' + data.pages + '</li>';
        }
      }
      content += '</ul>';
      return content;
    });

    ws.citeBox.add('BibTeX', function(data) {
      content = '<pre style="display:block;">@Book{\n';
      if(data.type)
        content += '  type = "' + data.type + '",\n';
      if(data.title)
        content += '  title = "' + data.title + '",\n';
      if(data.volume)
        content += '  volume = "' + data.volume + '",\n';
      if(data.author)
        content += '  author = "' + data.author + '",\n';
      if(data.publisher)
        content += '  publisher = "' + data.publisher + '",\n';
      if(data.school)
        content += '  school = "' + data.school + '",\n';
      if(data.year)
        content += '  year = "' + data.year + '",\n';
      if(data.place)
        content += '  place = "' + data.place + '",\n';
      if(data.chapter)
        content += '  chapter = "' + data.chapter + '",\n';
      if(data.pages)
        content += '  pages = "' + data.pages + '",\n';
      content += '  url = "' + document.location.href + '",\n';
      content += '}</pre>';
      return content;
    });

    ws.citeBox.add('Vikipedi', function(data) {
      content = '<pre>{{eser\n';
      content += '|başlık= ' + data.title + '\n';
      content += '|yazar= ' + data.author + '\n';
      if(data.translator)
        content += '|çevirmen= ' + data.translator + '\n';
      if(data.illustrator)
        content += '|resimleyen= ' + data.illustrator + '\n';
      content += '|editör= ' + data.publisher + '\n';
      content += '|yıl= ' + data.year + '\n';
      if(data.place)
        content += '|basım yeri= ' + data.place + '\n';
      if(data.volume)
        content += '|cilt= ' + data.volume + '\n';
      if(data.chapter)
        content += '|bölüm= ' + data.chapter + '\n';
      if(data.pages)
        content += '|kısım= ' + data.pages + '\n';
      content += '|dil= tr\n';
      content += '|wikisource= ' + mw.config.get('wgTitle') + '\n';
      content += '}}</pre>';
      return content;
    });

    ws.citeBox.add('Vikisöz', function(data) {
      content = '<pre>{{Kaynak kitap\n';
      content += '|başlık= ' + data.title + '\n';
      content += '|yazar= ' + data.author + '\n';
      content += '|editör= ' + data.publisher + '\n';
      content += '|yıl= ' + data.year + '\n';
      content += '|sayfa= ' + data.pages + '\n';
      if(data.volume)
        content += '|cilt= ' + data.volume + '\n';
      if(data.chapter)
        content += '|kısım= ' + data.chapter + '\n';
      if(data.translator)
        content += '|çevirmen= ' + data.translator + '\n';
      content += '|s= ' + mw.config.get('wgTitle') + '\n';
      content += '}}</pre>';
      return content;
    });

    ws.citeBox.add('Vikisözlük', function(data) {
      content = '<pre>{{source|';
      content += data.author;
      content += ", ''{{ws|" + mw.config.get('wgTitle') + '|' + data.title + "}}''";
      if(data.publisher)
        content += ', ' + data.publisher;
      if(data.year)
        content += ', ' + data.year;
      if(data.pages) {
      	if(isNaN(data.pages)) {
          content += ', pages ' + data.pages;
      	} else {
          content += ', page ' + data.pages;
      	}
      }
      content += '}}</pre>';
      return content;
    });

    var i18n = {
      title: 'Bu metni alıntılayın',
      description: 'Bu metni farklı bir formatta alıntılayın.',
      display_mode: 'Görüntüleme biçimi :'
    };
    ws.citeBox.init( i18n );
  });
}