_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

Benutzer:Schnark/js/dialog.js

Im heutigen Artikel tauchen wir in die faszinierende Welt von Benutzer:Schnark/js/dialog.js ein. Von seinen Ursprüngen bis zu seiner heutigen Relevanz werden wir jeden Aspekt untersuchen, der es in der heutigen Gesellschaft so interessant und relevant macht. Wir werden uns mit seinen Auswirkungen in verschiedenen Bereichen sowie seinem Einfluss auf die Entscheidungsfindung und Meinungsbildung befassen. Dies ist ein Thema, das zweifellos die Neugier und das Interesse vieler Menschen weckt, daher ist es wichtig, sich damit zu befassen, um seinen wahren Umfang zu verstehen. Begleiten Sie uns auf dieser spannenden Erkundungstour!
//Dokumentation unter ] <nowiki>
/*global mw: true */
(function($, libs){

var schnark_dialog = {
version: 1.6,
l10n: {ok: 'OK', cancel: 'Abbrechen', other: 'Sonstiges'},
render: {
 input: function (param, uid) {
   if (param.multiline) return schnark_dialog.render.inputbox(param, uid);
   var h = mw.html;
   var text = param.text;
   if (!param.html) text = h.escape(text);
   return $(h.element('div', {id: uid + 'dialog-tog-' + param.name, style: 'display:table; width:100%;'}, new h.Raw(
                  h.element('label', {'for': uid + 'dialog-' + param.name, style: 'display:table-cell;'}, new h.Raw(text)) +
                  h.element('input', {type: 'text', name: uid + 'dialog-' + param.name, id: uid + 'dialog-' + param.name, size: '50', style: 'display:table-cell; width:100%;', value: param.standard || ''})
               )));
},
 inputbox: function (param, uid) {
   var h = mw.html;
   var text = param.text;
   if (!param.html) text = h.escape(text);
   return $(h.element('div', {id: uid + 'dialog-tog-' + param.name}, new h.Raw(
                  h.element('label', {'for': uid + 'dialog-' + param.name}, new h.Raw(text)) +
                  h.element('textarea', {name: uid + 'dialog-' + param.name, id: uid + 'dialog-' + param.name, cols: '50', style: 'width:100%;', rows: '2'}, param.standard || '')
               )));
},
 label: function (param, uid) {
   var h = mw.html;
   var text = param.text;
   if (!param.html) text = h.escape(text);
   return $(h.element('div', {id: uid + 'dialog-tog-' + param.name}, new h.Raw(text)));
},
 select: function (param, uid) {
   var h = mw.html;
   var options = '';
   for (var i = 0; i < param.list.length; i++) {
       var prop = {value: i.toString()};
       if (param.standard === i) prop.selected = 'selected';
       options += h.element('option', prop, param.list);
   }
   var text = param.text;
   if (!param.html) text = h.escape(text);
   var help = param.list;
   if (!param.html) help = h.escape(help);
   var ret = $(h.element('div', {id: uid + 'dialog-tog-' + param.name}, new h.Raw(
                  h.element('label', {'for': uid + 'dialog-' + param.name}, new h.Raw(text)) +
                  h.element('select', {name: uid + 'dialog-' + param.name, id: uid + 'dialog-' + param.name}, new h.Raw(options)) +
                  h.element('div', {id: uid + 'dialog-help-' + param.name}, new h.Raw(help)))));
   ret.find('select').change(function() {
       $('#' + uid + 'dialog-help-' + param.name)(param.list);
     });
   return ret;
},
 select_multi: function (param, uid) {
   var h = mw.html;
   var checkboxes = '';
   for (var i = 0; i < param.list.length; i++) {
       var prop = {type: 'checkbox', id: uid + 'dialog-' + param.name + i};
       if ($.isArray(param.standard) && $.inArray(i, param.standard) != -1) prop.checked = 'checked';
       var item = param.list;
       if (!param.html) item = h.escape(item);
       checkboxes += h.element('input', prop) +
                     h.element('label', {'for': uid + 'dialog-' + param.name + i}, new h.Raw(item)) +
                     h.element('br', {});
   }
   var text = param.text;
   if (!param.html) text = h.escape(text);
   var ret = $(h.element('div', {id: uid + 'dialog-tog-' + param.name}, new h.Raw(
                  h.element('span', {}, new h.Raw(text)) +
                  h.element('div', {}, new h.Raw(checkboxes))
               )));
   return ret;
},
 select_other: function (param, uid, dummy, resize) {
   var h = mw.html;
   param.list.push();
   var options = '';
   var std = (typeof param.standard == 'string') ? param.list.length - 1 : (param.standard || 0);
   for (var i = 0; i < param.list.length; i++) {
       var prop = {value: i.toString()};
       if (i == std) prop.selected = 'selected';
       options += h.element('option', prop, param.list);
   }
   var text = param.text;
   if (!param.html) text = h.escape(text);
   var help = param.list;
   if (!param.html) help = h.escape(help);
   var input = param.multiline ?
               h.element('textarea', {name: uid + 'dialog-' + param.name + '-other', id: uid + 'dialog-' + param.name + '-other', cols: '50', style: 'width:100%;', rows: '2'}, (typeof param.standard == 'string') ? param.standard : '')
               :
               h.element('input', {type: 'text', name: uid + 'dialog-' + param.name + '-other', id: uid + 'dialog-' + param.name + '-other',
                                   size: '50', style: 'width:100%',
                                   value: (typeof param.standard == 'string') ? param.standard : ''});
   var ret = $(h.element('div', {id: uid + 'dialog-tog-' + param.name}, new h.Raw(
                  h.element('label', {'for': uid + 'dialog-' + param.name}, new h.Raw(text)) +
                  h.element('select', {name: uid + 'dialog-' + param.name, id: uid + 'dialog-' + param.name}, new h.Raw(options)) +
                  h.element('div', {}, new h.Raw(input)) +
                  h.element('div', {id: uid + 'dialog-help-' + param.name}, new h.Raw(help)))));
   if (std != param.list.length - 1) ret.find('#' + uid + 'dialog-' + param.name + '-other').hide();
   ret.find('select').change(function() {
       var nr = $('#' + uid + 'dialog-' + param.name + ' :selected').val();
       $('#' + uid + 'dialog-help-' + param.name)(param.list);
       if (nr == param.list.length - 1) {
          $('#' + uid + 'dialog-' + param.name + '-other').show();
       } else {
          $('#' + uid + 'dialog-' + param.name + '-other').hide();
       }
       resize();
     });
   return ret;
},
 toggle: function (param, uid, params, resize) {
   var h = mw.html;
   var text = param.text;
   if (!param.html) text = h.escape(text);
   var ret = $(h.element('div', {id: uid + 'dialog-tog-' + param.name}, new h.Raw(
                  h.element('input', {type: 'checkbox', id: uid + 'dialog-' + param.name, checked: 'checked'}) +
                  h.element('label', {'for': uid + 'dialog-' + param.name}, new h.Raw(text))
               )));
   ret.find('input').change(function() {
      var func = this.checked ? 'show' : 'hide';
      for (var i = 0; i < param.list.length; i++) {
          params].offtoggle = !this.checked;
          $('#' + uid + 'dialog-tog-' + params].name)();
      }
      resize();
   });
   return ret;
}
},
get: {
 input: function (param, uid) {
   return $('#' + uid + 'dialog-' + param.name).val();
},
 inputbox: function (param, uid) {
   return $('#' + uid + 'dialog-' + param.name).val();
},
 select: function (param, uid) {
   return param.list;
},
 select_multi: function (param, uid) {
   var ret = ;
   for (var i = 0; i < param.list.length; i++)
       if ($('#' + uid + 'dialog-' + param.name + i).prop('checked')) ret.push(param.list);
   return ret;
},
 select_other: function (param, uid) {
   var nr = $('#' + uid + 'dialog-' + param.name + ' :selected').val();
   if (nr == param.list.length - 1) {
      return $('#' + uid + 'dialog-' + param.name + '-other').val();
   } else {
      return param.list;
   }
},
 toggle: function (param, uid) {
   return !!$('#' + uid + 'dialog-' + param.name).prop('checked');
}
},
get_all: function (param, uid) {
     var r = {}, ret;
     for (var i = 0; i < param.length; i++) {
         var p = param;
         if (p.offtoggle) continue;
         if (p.type == 'label') continue;
         ret = schnark_dialog.get(p, uid);
         if (!p.optional && typeof ret != 'boolean' && !ret.length) return false;
         r = ret;
     }
     return r;
},

show: function (title, param, success, abort) {
   abort = abort || function(){};
   var h = mw.html;
   var uid = 'dialog-form-' + $.now();
   var select = function (field) {
       if (field.selectionStart || field.selectionStart == '0') { //Code für Browser
          field.selectionStart = 0;
          field.selectionEnd = field.value.length;
       } else if (document.body.createTextRange) { //Code für IE
          var sel = field.createTextRange();
          sel.moveStart('character', 0);
          sel.moveEnd('character', 0);
          try { sel.select(); } catch (e) {}
       }
       $(field).focus();
   };
   var done = false;
   var kill = function() {
       $(this).dialog('close');
       $('#' + uid).remove();
   },
   ok = function() {
        if (done) return; done = true;
        var ret = schnark_dialog.get_all(param, uid);
        kill();
        if (ret) {
           success(ret);
        } else {
           abort(false);
        }
   },
   abbrechen = function() {
        if (done) return; done = true;
        kill();
        abort(true);
   };
   var resize = function() {
       $('#' + uid).dialog('option', {width: 'auto', height: 'auto'});
   };
   var onEnter = function (event) {
                          if (event.keyCode == $.ui.keyCode.ENTER) ok();
                 };
   var i, p;
   var dialog = $(h.element('div', {id: uid, style: 'width:auto;', title: title})), el;
   for (i = 0; i < param.length; i++) {
       p = param;
       dialog.append(schnark_dialog.render(p, uid, param, resize));
   }
   var buttons = {};
   buttons = ok;
   buttons = abbrechen;
   dialog.dialog({
      buttons: buttons,
      close: abbrechen,
      width: 'auto', height: 'auto'
   });
   for (i = 0; i < param.length; i++) {
       p = param;
       if (p.type == 'toggle' && p.standard === false) $('#' + uid + 'dialog-' + p.name).click().change();
       if (p.type == 'input' && p.focus === true) select(document.getElementById(uid + 'dialog-' + p.name));
       if (p.type == 'select_other' && p.focus === true && typeof p.standard == 'string') select(document.getElementById(uid + 'dialog-' + p.name + '-other'));
       if (p.enter) $('#' + uid + 'dialog-' + p.name).keydown(onEnter);
   }
}
};

window.schnark_dialog = schnark_dialog; //legacy
libs.schnark_dialog = schnark_dialog;
$(document).trigger('loadWikiScript', );

/*
mw.loader.using('jquery.ui', function () {
schnark_dialog.show('Titel', [
{type: 'label', name: 'lab1', text: '<u>Label</u>'},
{type: 'toggle', name: 'tog1', text: '<u>Schalter</u>', list: , html: true, standard: false, enter: true},
{type: 'inputbox', name: 'inp1', text: 'Eingabe'},
{type: 'input', name: 'inp2', text: 'Eingabe', optional: true, focus: true, standard: 'Text', enter: true},
{type: 'select_other', name: 'sel1', text: 'Wahl', list: , ], standard: 'c', html: true, enter: true},
{type: 'select_multi', name: 'sel2', text: 'Aussuchen', list: , ], standard: , enter: true}
], function(a){var t='';for(var i in a) t+=i+': '+a+'\n';alert(t);}, function(a){alert(a);});
});
*/

})(jQuery, mw.libs);

//</nowiki>