مدیاویکی:Gadget-ProveIt.js

از مشروطه
پرش به ناوبری پرش به جستجو

نکته: پس از ذخیره کردن ممکن است برای دیدن تغییرات نیاز باشد که حافظهٔ نهانی مرورگر خود را پاک کنید.

  • فایرفاکس / سافاری: کلید Shift را نگه دارید و روی دکمهٔ Reload کلیک کنید، یا کلید‌های Ctrl-F5 یا Ctrl-R را با هم فشار دهید (در رایانه‌های اپل مکینتاش کلید‌های ⌘-R)
  • گوگل کروم: کلیدهای Ctrl+Shift+R را با هم فشار دهید (در رایانه‌های اپل مکینتاش کلید‌های ⌘-Shift-R)
  • اینترنت اکسپلورر: کلید Ctrl را نگه‌دارید و روی دکمهٔ Refresh کلیک کنید، یا کلید‌های Ctrl-F5 را با هم فشار دهید
  • اپرا: بروید به Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* 
 * ProveIt, Copyright 2011, Georgia Tech
 * Available under the GNU Free Documentation License, Creative Commons Attribution/Share-Alike License 3.0, and the GNU General Public License version 2
 * 
 * ProveIt is a powerful GUI tool for viewing, adding, editing, and inserting references.
 * See [[:en:User:ProveIt GT]] for more information.
 * 
 * Localized by [[User:Mjbmr]] for fa.wikipedia.org
 */
window.proveit = jQuery.extend({
  HALF_EDIT_BOX_HEIGHT: 200,
  LANG: "fa",
  NEW_PARAM_PREFIX: "newparam",
  EDIT_PARAM_PREFIX: "editparam",
  JQUERYUI_SCRIPT_URL: "//ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/jquery-ui.min.js",
  JQUERYUI_STYLES_URL: "//ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/base/jquery-ui.css",
  descriptions: {
    fa: {
      encyclopedia: "دانشنامه",
      web: "وب",
      book: "کتاب",
      journal: "ژورنال",
      news: "خبر",
      type: "نوع",
      video: "ویدئو",
      videogame: "بازی رایانه\u200cای",
      encyclopediaatf: "دانشنامه عتف",
      encyclopediavalimar: "دانشنامه والیمار",
      dehkhoda: "لغت\u200cنامهٔ دهخدا",
      moien: "فرهنگ لغت معین",
      wiki: "ویکی",
      medium: "متوسط تولید",
      raw: "نامشخص",
      time: "زمان",
      dio: "دیوو",
      quote: "نقل قول",
      ref: "شناسه پیوند",
      months: "ژانویه,فوریه,مارس,آوریل,مه,ژوئن,ژوئیه,اوت,سپتامبر,اکتبر,نوامبر,دسامبر".split(","),
      numbers: "۰,۱,۲,۳,۴,۵,۶,۷,۸,۹".split(","),
      showhide: "نمایش/نهفتن",
      edit: "ویرایش",
      bold: "ضخیم",
      updateeditform: "بروزرسانی جعبه ویرایش",
      by: "توسط",
      date: "تاریخ",
      cancel: "لغو",
      referencetype: "نوع منبع",
      references: "منابع",
      addareference: "افزودن یک منبع",
      editrefname: "این یک عنوان یکتا برای هر منبع است که از طریق آن می توانید در هر جای صفحه دوباره از همین منبع استفاده کنید",
      required: "اجباری",
      requiredfield: "فیلد اجباری",
      addfield: "افزودن فیلد",
      removefield: "حذف فیلد",
      addanotherfield: "افزودن فیلدی دیگر",
      addtoeditform: "افزودن به جعبه ویرایش",
      citestimes: "به این منبع در مقاله %s بار ارجاع شده است",
      editthisref: "این منبع را ویرایش کنید",
      addthisreftocursor: "این منبع را در مکان نشانگر اضافه کن",
      documnettitle: "برای مشاهده مستندات کلیک کنید",
      documnet: "ویکی\u200cپدیا:آن\u200cرا اثبات کن",
      accessdatearray: "بازیابی,بازبینی,تاریخ بازبینی,تاریخ بازیابی,accessdate".split(",")
    },
  },
  getDescriptions: function () {
    return this.descriptions[proveit.LANG]
  },
  log: function (a) {
    typeof console === "object" && console.log && console.log("[ProveIt] %o", a)
  },
  isSupportedEditPage: function () {
    return (wgCanonicalNamespace == "") && (wgAction == "edit" || wgAction == "submit")
  },
  getRefBox: function () {
    return jQuery("#refs")
  },
  getPosition: function (a) {
    var c = 0,
      b = 0;
    do c += a.offsetLeft, b += a.offsetTop;
    while (a = a.offsetParent);
    return {
      left: c,
      top: b
    }
  },
  localizeNumbers: function (a) {
    a = a.toString()
    for (var i=0; i<10; i++) {
      var reg=new RegExp(i,'g');
      a = a.replace(reg,this.getDescriptions().numbers[i]);
    }
    return a;
  },
  highlightLengthAtIndex: function (a, c) {
    (a < 0 || c < 0) && this.log("highlightStringAtIndex: invalid negative arguments");
    var b = this.getMWEditBox(),
      d = b.value,
      e = this.getPosition(b).top;
    b.value = d.substring(0, a);
    b.focus();
    b.scrollTop = 1E6;
    e = b.scrollTop;
    b.value += d.substring(a);
    if (e > 0) b.scrollTop = e + this.HALF_EDIT_BOX_HEIGHT;
    jQuery(b).focus().textSelection("setSelection", {
      start: a,
      end: a + c
    });
    e = this.getPosition(b).top;
    window.scroll(0, e);
    return !0
  },
  highlightTargetString: function (a) {
    var c = this.getMWEditValue().indexOf(a);
    return c == -1 ? (this.log('Target string "' + a + '" not found.'), !1) : this.highlightLengthAtIndex(c, a.length)
  },
  getMWEditBox: function () {
    return jQuery("#wpTextbox1")[0]
  },
  getMWEditValue: function () {
    var a = this.getMWEditBox(),
      c = a.value;
    !a.selectionStart && document.selection && (c = c.replace(/\r\n/g, "\n"));
    return c
  },
  getMWEditForm: function () {
    return jQuery("#editform")[0]
  },
  addOnsubmit: function (a) {
    var c = this.getMWEditForm();
    if (!c) throw Error("No edit form, possibly due to protected page.");
    c.addEventListener("submit", a, !1)
  },
  getEditSummary: function () {
    return jQuery("#wpSummary")[0]
  },
  summaryFunctionAdded: !1,
  shouldAddSummary: !0,
  loadMaximized: !1,
  includeProveItEditSummary: function () {
    if (this.shouldAddSummary && !this.summaryFunctionAdded) try {
      var a = this;
      this.addOnsubmit(function () {
        var c = a.getEditSummary();
        var est = "ویرایش شده با استفاده از «[[ویکی\u200cپدیا:آن\u200cرا اثبات کن]]»";
        if (c.value!=""){
          var es = ") (" + est;
        } else {
          var es = est;
        }
        c.value.indexOf(est) == -1 && (c.value += es)
      });
      this.summaryFunctionAdded = !0
    } catch (c) {
      this.log("Failed to add onsubmit handler. e.message: " + c.message)
    }
  },
  load: function () {
    this.summaryFunctionAdded = !1;
    this.isSupportedEditPage() && jQuery.getScript(proveit.JQUERYUI_SCRIPT_URL, function () {
      $(function () {
        proveit.createGUI()
      })
    });
    return !0
  },
  clearRefBox: function () {
    var a = this.getRefBox();
    if (a == null) return this.log("Ref box is not loaded yet."), !1;
    a = jQuery("tr:not('tr#dummyRef')", a);
    jQuery(a).remove()
  },
  insertRefIntoMWEditBox: function (a, c) {
    var b = this.getMWEditBox();
    if (!b) return this.log("insertRefIntoMWEditBox: txtarea is null"), !1;
    var b = jQuery(b),
      d = a.getInsertionText(c);
    b.textSelection("encapsulateSelection", {
      peri: d,
      replace: !0
    });
    b = b.textSelection("getCaretPosition", {
      startAndEnd: !0
    });
    this.highlightLengthAtIndex(b[0], b[1] - b[0]);
    this.includeProveItEditSummary()
  },
  changeRefFromEditPane: function (a, c) {
    var b = jQuery("div.input-row", c),
      d = jQuery("#editrefname").val();
    a.name = d != "" ? d : null;
    a.params = {};
    for (var e, f, d = 0; d < b.length; d++) e = b[d], f = jQuery(".paramvalue", e)[0], e = jQuery(e).hasClass("addedrow") ? jQuery(".paramdesc", e)[0].value.trim() : f.id.substring(this.EDIT_PARAM_PREFIX.length), this.log("paramName: " + e), f = f.value.trim(), this.log("paramVal: " + f), e != "" && f != "" && (a.params[e] = f);
    if (a.toString() != a.orig) a.save = !1;
    a.update();
    return a;
  },
  saveRefFromEdit: function (a) {
    if (!a.save) {
      var c = this.makeRefBoxRow(a, !0),
        b = jQuery(".selected", this.getRefBox()).get(0);
      this.log("newRichItem: " + c + ", oldRichItem: " + b + "oldRichItem.parentNode: " + b.parentNode);
      var d = jQuery("td.number", b).text();
      jQuery("td.number", c).text(d);
      b.parentNode.replaceChild(c, b);
      jQuery(c).addClass("selected");
      a.updateInText();
      this.includeProveItEditSummary();
    }
  },
  updateEditPane: function (a) {
    jQuery("#editrefname").val(a.name || "");
    var c = {},
      b;
    for (b in a.params) c[b] = a.params[b];
    var d = a.getDefaultParams();
    for (b = 0; b < d.length; b++) c[d[b]] || (c[d[b]] = "");
    var d = a.getRequiredParams(),
      e = [],
      f;
    for (f in c) e.push(f);
    (f = a.getSorter()) ? e.sort(f) : e.sort();
    jQuery("#edit-fields").children(".paramlist").children().remove("div:not(.hidden)");
    for (b = 0; b < e.length; b++) this.addPaneRow(jQuery("#edit-pane").get(), c, this.getDescriptions(), e[b], false, !0);
    var g = jQuery("#edit-buttons .accept"),
      i = function () {
        proveit.log("Entering acceptEdit");
        proveit.changeRefFromEditPane(a, jQuery("#edit-pane").get());
        proveit.saveRefFromEdit(a);
        g.unbind("click", i);
        jQuery("#edit-pane").hide();
        jQuery("#view-pane").show()
      };
    setTimeout(function () {
      jQuery("#edit-fields").scrollTop(0)
    }, 0);
    g.click(i);
    jQuery(".tab-link").one("click", function () {
      g.unbind("click", i)
    })
  },
  addPaneRow: function (a, c, b, d, e, f) {
    var g = jQuery("#" + (f ? "preloadedparamrow" : "addedparamrow")).clone();
    jQuery(g).attr("id", "");
    var i = jQuery(".paramdesc", g).eq(0),
      j = jQuery(".paramvalue", g).eq(0);
    jQuery(".paramlist", a).append(g);
    e ? (jQuery(i).addClass("required"), jQuery(".delete-field", g).remove()) : this.activateRemoveField(g);
    f ? (i.attr("for", this.EDIT_PARAM_PREFIX + d), j.attr("id", this.EDIT_PARAM_PREFIX + d), a = b[d], a || (this.log("Undefined description for param: " + d + ".  Using directly as description."), a = d), jQuery(i).text(a), jQuery(i).attr("title", d), jQuery(j).val(c[d]), jQuery(g).show()) : (jQuery(g).show("highlight", {}, "slow"), jQuery(".inputs", a).scrollTop(1E5))
  },
  togglestyle: !0,
  toggleinsert: !1,
  split: function (a, c, b) {
    if (Object.prototype.toString.call(c) !== "[object RegExp]") return proveit.split._nativeSplit.call(a, c, b);
    var d = [],
      e = 0,
      f = (c.ignoreCase ? "i" : "") + (c.multiline ? "m" : "") + (c.sticky ? "y" : ""),
      c = RegExp(c.source, f + "g"),
      g, i, j;
    a += "";
    proveit.split._compliantExecNpcg || (g = RegExp("^" + c.source + "$(?!\\s)", f));
    if (b === void 0 || +b < 0) b = Infinity;
    else if (b = Math.floor(+b), !b) return [];
    for (; i = c.exec(a);) {
      f = i.index + i[0].length;
      if (f > e && (d.push(a.slice(e, i.index)), !proveit.split._compliantExecNpcg && i.length > 1 && i[0].replace(g, function () {
        for (var a = 1; a < arguments.length - 2; a++) arguments[a] === void 0 && (i[a] = void 0)
      }), i.length > 1 && i.index < a.length && Array.prototype.push.apply(d, i.slice(1)), j = i[0].length, e = f, d.length >= b)) break;
      c.lastIndex === i.index && c.lastIndex++
    }
    e === a.length ? (j || !c.test("")) && d.push("") : d.push(a.slice(e));
    return d.length > b ? d.slice(0, b) : d
  },
  splitNameVals: function (a) {
    var c = {};
    c.names = proveit.split(a.substring(a.indexOf("|") + 1), /=(?:[^|]*?(?:\[\[[^|\]]*(?:\|(?:[^|\]]*))?\]\])?)+(?:\||\}\})/);
    c.names.length--;
    c.values = proveit.split(a.substring(a.indexOf("=") + 1, a.indexOf("}}")), /\|[^|=]*=/);
    return c
  },
  scanForRefs: function () {
    this.log("Entering scanForRefs.");
    this.clearRefBox();
    var a = this.getMWEditValue(),
      c, b = {},
      d = [];
    a.match(/<[\s]*ref[^\/>]*>/gi);
    if (a = a.match(/<[\s]*ref[^>]*>(?:[^<]*<[\s]*\/[\s]*ref[\s]*>)?/gi)) for (var e = 0; e < a.length; e++) {
      var f = this.makeRef(a[e]);
      f ? (c = f.name) || d.push(f) : c = (c = a[e].match(this.REF_REGEX)) && (c[1] || c[2] || c[3]);
      if (c) {
        if (!b[c] && (b[c] = {}, !b[c].strings)) b[c].strings = [];
        if (f && !b[c].reference) b[c].reference = f, d.push(f);
        b[c].strings.push(a[e])
      }
    }
    for (a = 0; a < d.length; a++) d[a].name && d[a].setCitationStrings(b[d[a].name].strings), this.addNewElement(d[a])
  },
  REF_REGEX: /<[\s]*ref[\s]*name[\s]*=[\s]*(?:(?:\"(.*?)\")|(?:\'(.*?)\')|(?:(.*?)))[\s]*\/?[\s]*>/,
  makeRef: function (a) {
    var c = /<[\s]*ref[^>]*>[^<]*\S[^<]*<[\s]*\/[\s]*ref[\s]*>/.test(a);
    this.log("refText: " + a + "; isReference: " + c);
    if (!c) return null;
    var regpatt=new RegExp("{{[\\s]*(.*?)[\\s\\S]*?}}",'i');
    c = a.match(regpatt) ? this.CiteReference : this.RawReference;
    if (c != this.RawReference) {
      var b = a.match(regpatt)[0],
        d = a.match(this.REF_REGEX);
      if (d && d != null) var e = d[1] || d[2] || d[3];
      d = b.split(/\|/g);
      var f = d[0].replace(/{{/img , "");
    }
    a = new c({
      name: e,
      type: f,
      save: !0,
      inMWEditBox: !0,
      orig: a
    });
    if (c != this.RawReference) {
      c = this.splitNameVals(b);
      b = c.names;
      c = c.values;
      for (e = 0; e < b.length; e++) d = b[e].trim().replace(/(?:\s*\|)*(.*)/, "$1"), f = c[e].trim(), f != "" && (a.params[d] = f);
    }
    return a;
  },
  AbstractReference: function (a) {
    if (!this.setType) this.setType = function (a) {
      this.type = a;
    };
    this.update = function () {
      var a = this.toString(),
        b = this.getCitationStrings();
      if (b.length > 0) for (var d = 0; d < b.length; d++) b[d] == this.orig && (proveit.log("Updating " + b[d] + " to " + a), b[d] = a);
      else this.name != null && (proveit.log("Adding " + a + " to citationStrings"), b.push(a))
    };
    this.name = a.name != "" ? a.name : null;
    this.setType(a.type);
    this.save = a.save;
    this.inMWEditBox = a.inMWEditBox;
    this.orig = a.orig;
    this.params = {};
    this.getSorter = function () {
      var a = this;
      return function (b, d) {
        var e = a.getSortIndex(b),
          f = a.getSortIndex(d);
        return e != -1 && f != -1 ? e - f : b < d ? -1 : b == d ? 0 : 1
      }
    };
    this.isValid = function () {
      return !0
    };
    this.getLabel = function () {
      var a = "";
      if (this.params.author) a = this.params.author + "; ";
      else if (this.params.نویسنده) a = this.params.نویسنده + "; ";
      else if (this.params.last) a = this.params.last, this.params.first && (a += ", " + this.params.first), a += "; ";
      this.params.عنوان && (a += this.params.عنوان);
      if (a == "") {
        for (var b in this.params) break;
        b && (a = b)
      }
      return a;
    };
    this.getInsertionText = function (a) {
      proveit.log("getInsertionText");
      if (a) return this.toString();
      else if (this.name) return '<ref name="' + this.name + '" />';
      else throw Error("getInsertionText: ref.name is null");
    };
    this.updateInText = function () {
      var a = proveit.getMWEditBox();
      if (a && a != null) {
        a.focus();
        var b = proveit.getMWEditValue(),
          b = b.replace(this.orig, this.toString());
        a.value = b;
        this.orig = this.toString();
        this.save = !0;
        proveit.highlightTargetString(this.toString())
      }
    };
    this.toStringInternal = function (a, b) {
      var d = this.name ? '<ref name="' + this.name + '">' : "<ref>";
      d += "{{" + a + (b ? this.type : "");
      for (var e in this.params) d += " | " + e + "=" + this.params[e];
      d += "}}</ref>";
      return d
    };
    this.citationStrings = [];
    this.setCitationStrings = function (a) {
      this.citationStrings = a
    };
    this.getCitationStrings = function () {
      return this.citationStrings
    };
    this.getIcon = function () {
      return "//upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Crystal_Clear_mimetype_info.png/20px-Crystal_Clear_mimetype_info.png";
    }
  },
  CiteReference: function (a) {
    var c = {
      book: "یادکرد کتاب",
      videogame: "یادکرد بازی رایانه\u200cای",
      news: "یادکرد خبر",
      encyclopedia: "یادکرد دانشنامه",
      encyclopediaatf: "یادکرد دانشنامه عتف",
      encyclopediavalimar: "یادکرد دانش\u200cنامه والیمار",
      web: "یادکرد وب",
      video: "یادکرد ویدئو",
      journal: "یادکرد ژورنال",
      dehkhoda: "یادکرد-دهخدا",
      moien: "یادکرد-معین",
      wiki: "یادکرد-ویکی"
    };
    this.setType = function (a) {
      var b = c[a];
      this.type = b != null ? b : a
    };
    proveit.AbstractReference.call(this, a);
    this.getSortIndex = function (a) {
      return jQuery.inArray(a, "عنوان,پیوند,نشانی,ناشر,تاریخ,بازیابی,تاریخ بازیابی".split(","))
    };
    this.toString = function () {
      return this.toStringInternal("", !0)
    };
    var b = {
      book: "نام خانوادگی,نام,پیوند نویسنده,نام خانوادگی۲,نام۲,پیوند نویسنده۲,نام ویراستار,نام خانوادگی ویراستار,پیوند ویراستار,فصل,پیوند فصل,عنوان,عنوان۲,ترجمه عنوان,کوشش,ترجمه,دیگران,پیوند,تاریخ بازبینی,پیوند بایگانی,تاریخ بایگانی,ویرایش,جلد,تاریخ,سال,ناشر,مکان,زبان,شابک".split(","),
      videogame: "عنوان,سازنده,ناشر,تاریخ,نسخه".split(","),
      news: "نویسنده,پیوند,عنوان,خبرگزاری,تاریخ,بازیابی".split(","),
      encyclopedia: "پیوند نویسنده,مقاله,دانشنامه,صفحه,پیوند,تاریخ بازبینی".split(","),
      encyclopediaatf: "عنوان,مدخل,شناسه,تاریخ".split(","),
      encyclopediavalimar: "عنوان,مدخل,شناسه,تاریخ".split(","),
      web: "نام خانوادگی,نام,عنوان,نشانی,تاریخ بازبینی,تاریخ,اثر".split(","),
      video: "نویسنده,عنوان,ناشر,تاریخ,پیوند,تاریخ بازدید".split(","),
      journal: "عنوان,ژورنال,مکان,ناشر,دوره,شماره,سال,صفحه,پیوند,تاریخ بازبینی".split(","),
      dehkhoda: "عنوان,بازیابی".split(","),
      moien: "عنوان,بازیابی".split(","),
      wiki: "پیوند,عنوان,زبان,بازیابی".split(",")
    };
    this.getRequiredParams = function () {
      var r = b[this.type];
      return r ? r : [];
    };
    var d = {
      book: "نام خانوادگی,نام,پیوند نویسنده,نام خانوادگی۲,نام۲,پیوند نویسنده۲,نام ویراستار,نام خانوادگی ویراستار,پیوند ویراستار,فصل,پیوند فصل,عنوان,عنوان۲,ترجمه عنوان,کوشش,ترجمه,دیگران,پیوند,تاریخ بازبینی,پیوند بایگانی,تاریخ بایگانی,ویرایش,جلد,تاریخ,سال,ناشر,مکان,زبان,شابک".split(","),
      videogame: "عنوان,ساازنده,ناشر,تاریخ,پلت\u200cفرم,نسخه,مرحله,زبان,isolang,نقل قول".split(","),
      news: "نام,نام خانوادگی,نویسنده,همکاران,پیوند,عنوان,اثر,ناشر,صفحات,صفحه,تاریخ,بازیابی,زبان".split(","),
      encyclopedia: "نام خانوادگی,نام,پیوند نویسنده,مقاله,دانشنامه,سال,ناشر,مکان,شابک,صفحه,پیوند,تاریخ بازبینی".split(","),
      encyclopediaatf: "عنوان,مدخل,شناسه,تاریخ".split(","),
      encyclopediavalimar: "عنوان,مدخل,شناسه,تاریخ".split(","),
      web: "نام خانوادگی,نام,عنوان,نشانی,تاریخ بازبینی,اثر,تاریخ,ناشر,نشانی بایگانی,تاریخ بایگانی,کد زبان".split(","),
      video: "نویسنده,عنوان,medium,ناشر,شهر,تاریخ,پیوند,تاریخ بازدید,زبان,time,شابک,quote,یادداشت,oclc,نشانی بایگانی,تاریخ بایگانی".split(","),
      journal: "نام خانوادگی,نام,نام خانوادگی۲,نام۲,عنوان,ژورنال,مکان,ناشر,دوره,شماره,سال,صفحه,پیوند,تاریخ بازبینی,doi".split(","),
      dehkhoda: "عنوان,بازیابی".split(","),
      moien: "عنوان,بازیابی".split(","),
      wiki: "پیوند,عنوان,زبان,بازیابی".split(",")
    };
    this.getDefaultParams = function () {
      var a = d[this.type];
      return a ? a : [];
    };
    this.isValid = function () {
      if (this.type == "") return !1;
      var a = this.getRequiredParams(), b = !0, c;
      for (c in a) if (a[c] && (b &= c in this.params, !b)) break;
      return b
    };
    var f = this.getIcon;
    this.getIcon = function () {
      return f.call(this);
    }
  },
  RawReference: function (a) {
    proveit.AbstractReference.call(this, a);
    this.type = "raw";
    this.toString = function () {
      return this.orig
    };
    this.params.عنوان = this.orig;
    this.getIcon = function () {
      return "//upload.wikimedia.org/wikipedia/commons/thumb/b/b4/Crystal_Clear_action_filenew.png/20px-Crystal_Clear_action_filenew.png";
    }
  },
  getRefFromAddPane: function (a) {
    for (var c = a.id, c = new(this.togglestyle ? this.CiteReference : this.CiteReference)({
      name: jQuery("#addrefname").val(),
      type: c
    }), b, a = jQuery(".paramlist", a)[0], d = jQuery("div", a), e = 0; e < d.length; e++) {
      b = d[e];
      this.log("getRefFromAddPane: i: " + e + ", paramRow: " + b);
      var f = jQuery(".paramvalue", b)[0],
        a = jQuery(b).hasClass("addedrow") ? jQuery(".paramdesc", b)[0].value.trim() : f.id.substring(this.NEW_PARAM_PREFIX.length);
      this.log("getRefFromAddPane: paramRow.childNodes.length: " + b.childNodes.length);
      this.log("getRefFromAddPane: valueTextbox.refName: " + f.refName);
      this.log("getRefFromAddPane: valueTextbox.id: " + f.id);
      b = f.value.trim();
      this.log("getRefFromAddPane: paramName: " + a + "; paramVal: " + b);
      a != "" && b != "" && (c.params[a] = b)
    }
    c.update();
    this.log("Exiting getRefFromAddPane");
    return c
  },
  addReference: function (a) {
    this.addNewElement(a);
    a.orig = a.toString();
    this.insertRefIntoMWEditBox(a, !0);
    a.save = !0;
    a.inMWEditBox = !0
  },
  clearCitePanes: function (a) {
    a.hasChildNodes() && a.removeChild(a.firstChild)
  },
  activateRemoveField: function (a) {
    jQuery(".delete-field", a).click(function () {
      jQuery(a).hide("highlight", {}, "slow", function () {
        jQuery(a).remove()
      })
    })
  },
  changeAddPane: function (a) {
    jQuery("#add-fields").scrollTop(0);
    jQuery(a.parentNode).show();
    var c = jQuery(".addpanes", a.parentNode.parentNode).get(0);
    this.clearCitePanes(c);
    var b = a.value,
      d = document.getElementById("dummyCitePane").cloneNode(!0);
    d.id = b.replace(" ", "_");
    jQuery(".ref-name-row", d).children("input").attr("id", "addrefname");
    jQuery(".ref-name-row", d).children("label").attr("for", "addrefname");
    a = a.id == "citemenu" ? new this.CiteReference({}) : new this.CiteReference({});
    a.type = b;
    var b = this.getDescriptions(),
      e = a.getDefaultParams().slice(0);
    e.sort(a.getSorter());
    for (var f = 0; f < e.length; f++) a.params[e[f]] = "";
    this.log("changeAddPane: newRef: " + a);
    e = [];
    for (j in a.params) e.push(j);
    e.sort(a.getSorter());
    for (var g = a.getRequiredParams(), i = jQuery(".paramlist", d)[0], f = 0; f < e.length; f++) {
      var j = e[f], h;
      h = document.getElementById("preloadedparamrow").cloneNode(!0);
      var k = jQuery(".paramdesc", h);
      if (g[j]) {
        k.addClass("required");
        var l = jQuery(".delete-field", h)[0];
        l.parentNode.removeChild(l)
      } else this.activateRemoveField(h);
      if (b[j]){
        k.text(b[j]);
      } else {
        k.text(j);
      }
      k.attr("for", this.NEW_PARAM_PREFIX + j);
      this.getDescriptions().accessdatearray.indexOf(j) != -1 && jQuery(".paramvalue", h).val(this.localizeNumbers(this.formatDate(new Date)))
      h.id = "";
      this.activateRemoveField(h);
      jQuery(".paramvalue", h)[0].id = this.NEW_PARAM_PREFIX + j;
      this.log("changeAddPane: param: " + j + "; newRef.params[param]: " + a.params[j]);
      jQuery(h).show();
      i.appendChild(h)
    }
    jQuery(d).show();
    c.insertBefore(d, c.firstChild);
    this.log("Exiting changeAddPane")
  },
  createGUI: function () {
    importStylesheetURI(this.JQUERYUI_STYLES_URL);
    var a = jQuery("<div/>", {
      id: "proveit"
    }),
      c = jQuery("<div/>", {
        id: "tabs"
      }),
      b = jQuery("<h1/>"),
      d = jQuery("<a/>", {
        title: this.getDescriptions().documnettitle,
        href: encodeURI(wgServer + wgArticlePath.replace(/\$1/img ,this.getDescriptions().documnet.replace(/ /img,"_"))),
        target: "_blank"
      }),
      e = jQuery("<img/>", {
        src: "//upload.wikimedia.org/wikipedia/commons/thumb/8/81/Proveit-fa.svg/118px-Proveit-fa.svg.png",
        alt: "ProveIt",
        height: 30,
        width: 118
      });
    d.append(e);
    b.append(d);
    var f = jQuery("<button/>", {
      text: this.getDescriptions().showhide
    });
    b.append(f);
    c.append(b);
    e = jQuery("<ul/>");
    d = jQuery("<li/>");
    b = jQuery("<a/>", {
      id: "add-link",
      "class": "tab-link",
      href: "#add-tab"
    }).append(this.getDescriptions().addareference);
    d.append(b);
    e.append(d);
    g = jQuery("<li/>");
    d = jQuery("<a/>", {
      id: "view-link",
      "class": "tab-link",
      href: "#view-tab"
    });
    d.append(this.getDescriptions().references+" (");
    var h = jQuery("<span/>", {
      id: "numRefs"
    }).append(this.localizeNumbers("0"));
    d.append(h).append(")");
    g.append(d);
    e.append(g);
    c.append(e);
    var i = jQuery("<div/>", {
      id: "view-tab",
      css: {
        display: "none"
      }
    }),
      e = jQuery("<div/>", {
        id: "view-pane"
      }),
      g = jQuery("<div/>", {
        "class": "scroll",
        style: "height: 210px;"
      }),
      j = jQuery("<table/>", {
        id: "refs"
      }),
      h = jQuery("<tr/>", {
        id: "dummyRef",
        style: "display: none;"
      });
    h.append(jQuery("<td/>", {
      "class": "number"
    })).append(jQuery("<td/>", {
      "class": "type"
    })).append(jQuery("<td/>", {
      "class": "title"
    }));
    var k = jQuery("<td/>", {
      "class": "edit"
    }).append(jQuery("<button/>", {
      text: this.getDescriptions().edit
    }));
    h.append(k);
    j.append(h);
    g.append(j);
    e.append(g);
    i.append(e);
    k = jQuery("<div/>", {
      id: "edit-pane",
      style: "display: none"
    });
    e = jQuery("<div/>", {
      id: "edit-fields",
      "class": "inputs scroll",
      style: "height: 170px",
      tabindex: 0
    });
    h = jQuery("<div/>", {
      "class": "ref-name-row",
      tabindex: -1
    });
    g = jQuery("<label/>", {
      "for": "editrefname",
      title: this.getDescriptions().editrefname,
      "class": "paramdesc"
    }).append("&lt;ref&gt; name");
    h.append(g);
    h.append(jQuery("<input/>", {
      id: "editrefname",
      "class": "paramvalue"
    }));
    g = jQuery("<div/>", {
      "class": "paramlist"
    });
    e.append(h);
    e.append(g);
    k.append(e);
    var l = jQuery("<div/>", {
      id: "edit-buttons"
    }),
      e = jQuery("<button/>", {
        style: "margin-right: 50px;"
      }).append(this.getDescriptions().addfield);
    l.append(e);
    e = jQuery("<span/>", {
      "class": "required",
      text: this.getDescriptions().bold
    });
    l.append(e).append(" = "+this.getDescriptions().requiredfield);
    g = jQuery("<button/>", {
      "class": "right-side accept",
      text: this.getDescriptions().updateeditform
    });
    l.append(g);
    j = jQuery("<button/>", {
      "class": "right-side cancel",
      text: this.getDescriptions().cancel
    });
    l.append(j);
    k.append(l);
    i.append(k);
    c.append(i);
    k = jQuery("<div/>", {
      id: "dummyCitePane",
      "class": "typepane",
      style: "display: none"
    });
    h = h.clone();
    k.append(h);
    k.append(jQuery("<div/>", {
      "class": "paramlist"
    }));
    c.append(k);
    h = jQuery("<div/>", {
      id: "preloadedparamrow",
      "class": "preloadedrow input-row",
      style: "display: none"
    }).append(jQuery("<label/>", {
      "class": "paramdesc"
    }));
    k = jQuery("<input/>", {
      "class": "paramvalue",
      tabindex: -1
    });
    h.append(k);
    l = jQuery("<button/>", {
      "class": "delete-field"
    }).append(this.getDescriptions().removefield);
    h.append(l);
    c.append(h);
    h = jQuery("<div/>", {
      id: "addedparamrow",
      "class": "addedrow input-row",
      style: "display: none"
    }).append(jQuery("<input/>", {
      "class": "paramdesc",
      tabindex: -1
    })).append(k.clone()).append(l.clone());
    c.append(h);
    var p = jQuery("<div/>", {
      id: "add-tab",
      css: {
        display: "none"
      }
    }),
      h = jQuery("<div/>", {
        id: "add-fields",
        "class": "inputs scroll",
        style: "height: 170px"
      }),
      n = jQuery("<div/>", {
        style: "display: none",
        id: "cite",
        "class": "input-row"
      }),
      m = jQuery("<label/>", {
        "for": "citemenu",
        "class": "paramdesc required",
        text: this.getDescriptions().referencetype
      });
    n.append(m);
    for (var q = jQuery("<select/>", {
      id: "citemenu",
      change: function () {
        proveit.changeAddPane(q.get(0))
      }
    }), o = this.CiteReference.getTypes(), k = this.getDescriptions(), l = 0; l < o.length; l++) q.append(jQuery("<option/>", {
      value: o[l],
      text: k[o[l]]
    }));
    n.append(q);
    h.append(n);
    h.append(jQuery("<div/>", {
      "class": "addpanes",
      id: "citepanes",
      tabindex: 0
    }));
    n = jQuery("<div/>", {
      style: "display: none",
      id: "citation",
      "class": "input-row"
    });
    m = m.clone().attr("for", "citationmenu");
    n.append(m);
    for (var r = jQuery("<select/>", {
      id: "citemenu",
      change: function () {
        proveit.changeAddPane(r.get(0))
      }
    }), m = "web,wiki,book,videogame,news,encyclopedia,encyclopediaatf,encyclopediavalimar,journal,dehkhoda,moien,video".split(","), o = 0; o < m.length; o++) r.append(jQuery("<option/>", {
      value: m[l],
      text: k[m[l]]
    }));
    n.append(r);
    h.append(n).append(jQuery("<div/>", {
      "class": "addpanes",
      id: "citationpanes",
      style: "display: none;"
    }));
    p.append(h);
    h = jQuery("<div/>", {
      id: "add-buttons"
    });
    h.append(jQuery("<button/>", {
      style: "margin-right: 50px;",
      text: this.getDescriptions().addfield
    })).append(e.clone()).append(" = "+this.getDescriptions().required).append(g.clone().text(this.getDescriptions().addtoeditform)).append(j.clone());
    p.append(h);
    c.append(p);
    a.append(c);
    jQuery(document.body).prepend(a);
    var s = function () {
        jQuery("#edit-pane").hide();
        jQuery("#view-pane").show()
      };
    jQuery("#tabs").tabs({
      selected: 0,
      show: function (a, b) {
        switch (b.index) {
        case 1:
          s(), proveit.changeAddPane(document.getElementById(proveit.togglestyle ? "citemenu" : "citationmenu"))
        }
      }
    });
    jQuery(b).click(function () {
      jQuery(i).is(":hidden") ? f.click() : s()
    });
    jQuery(d).click(function () {
      jQuery(p).is(":hidden") && f.click()
    });
    jQuery("#add-buttons button:first").button({
      icons: {
        primary: "ui-icon-circle-plus"
      }
    }).click(function () {
      proveit.addPaneRow(document.getElementById("add-tab"))
    }).next().next().button({
      icons: {
        primary: "ui-icon-circle-check",
        secondary: "ui-icon-circle-arrow-e"
      }
    }).click(function () {
      proveit.addReference(proveit.getRefFromAddPane(jQuery("#add-tab .typepane").get(0)));
      jQuery("#tabs").tabs({
        selected: "#view-tab"
      });
      jQuery("div.scroll, #view-pane").scrollTop(1E5)
    }).next().button({
      icons: {
        primary: "ui-icon-circle-close"
      }
    }).click(function () {
      jQuery("#tabs").tabs({
        selected: "#view-tab"
      })
    });
    jQuery("button.cancel").click(s);
    jQuery("#edit-buttons button:first").button({
      icons: {
        primary: "ui-icon-circle-plus"
      }
    }).click(function () {
      proveit.addPaneRow(jQuery("#edit-pane"))
    }).next().next().button({
      icons: {
        primary: "ui-icon-circle-check"
      }
    }).next().button({
      icons: {
        primary: "ui-icon-circle-close"
      }
    });
    jQuery(".delete-field").button({
      icons: {
        primary: "ui-icon-close"
      },
      text: !1
    });
    f.button({
      icons: {
        primary: "ui-icon-triangle-1-n"
      },
      text: !1
    });
    var t = jQuery("#view-tab, #add-tab");
    f.toggle(function () {
      t.show();
      f.button("option", "icons", {
        primary: "ui-icon-triangle-1-s"
      })
    }, function () {
      t.hide();
      f.button("option", "icons", {
        primary: "ui-icon-triangle-1-n"
      })
    });
    this.scanForRefs();
    this.loadMaximized && f.click();
    jQuery("#refs tr").eq(0).click().click();
    jQuery("#refs tr:even").addClass("light");
    jQuery("#refs tr:odd").addClass("dark")
  },
  makeRefBoxRow: function (a, c) {
    var b = jQuery('<tr><td class="number"></td><td class="type"></td><td class="title"></td><td class="edit"></td></tr>').get(0);
    a.isValid() || jQuery(b).addClass("invalid");
    jQuery(".edit button", b).get(0);
    var d = this, e = "", f = "";
    if (a.params.title != null){
      e = a.params.title;
      f = this.truncateTitle(e);
    } else if (a.params.عنوان != null) {
      e = a.params.عنوان;
      f = this.truncateTitle(e);
    } else if (a.params.کتاب != null) {
      e = a.params.کتاب;
      f = this.truncateTitle(e);
    } else if (a.params.مقاله != null) {
      e = a.params.مقاله;
      f = this.truncateTitle(e);
    }
    jQuery("td.title", b).text(f);
    jQuery("td.title", b).attr("title", e);
    e = "";
    a.params.year ? e = a.params.year : a.params.date ? a.params.date && (f = a.params.date.match(/^([12]\d{3})/)) && (e = f[1]) : a.params.سال ? a.params.سال : a.params.تاریخ;
    var g = "";
    a.params.author ? g = a.params.author : a.params.last ? a.params.last && (g = a.params.last) : a.params.نویسنده;
    if (a.params.coauthors || a.params.last2) g += " <i>et al.</i>";
    var i = a.getIcon(),
      j = "",
      f = a.type;
    jQuery("td.type", b).css("background-image", "url(" + i + ")");
    jQuery("td.type", b).attr("title", a.type);
    var h = i = "",
      k = "";
    g != "" && (i = this.getDescriptions().by + ': <span class="author">' + g + "</span>");
    e != "" && (h = this.getDescriptions().date + ': <span class="date">' + e + "</span>");
    f != null && (j != "" && (f = '<a href="' + j + '" target="_blank">' + f + "</a>"), k = this.getDescriptions().type + ': <span class="type">' + f.replace(/raw/g , this.getDescriptions().raw) + "</span>");
    g = "";
    f == "raw" ? g = k + " | " + a.toString() : i != "" ? g = h != "" ? k != "" ? i + " | " + h + " | " + k : i + " | " + h : k != "" ? i + " | " + k : i : h != "" ? g = k != "" ? h + " | " + k : h : k != "" && (g = k);
    g = "<p>" + g + "</p>";
    e = jQuery("<div />", {
      "class": "expanded"
    });
    jQuery(e).append(g);
    jQuery("td.title", b).append(e);
    if (!c) f = jQuery("#refs tr").length, jQuery("td.number", b).text(this.localizeNumbers(f)), jQuery("#numRefs").text(this.localizeNumbers(f));
    jQuery(b).click(function () {
      d.highlightTargetString(a.orig);
      jQuery("#refs tr").removeClass("selected");
      jQuery(b).addClass("selected")
    });
    for (var f = function () {
        d.updateEditPane(a);
        jQuery("#view-pane").hide();
        jQuery("#edit-pane").show()
      }, l = a.getCitationStrings(), g = jQuery('<span class="all-citations" />'), j = 0; j < l.length; j++) {
      var alphabet = "الف,ب,پ,ت,ث,ج,چ,ح,خ,د,ذ,ر,ز,ژ,س,ش,ص,ض,ط,ظ,ع,غ,ف,ق,ک,گ,ل,م,ن,ه,ی".split(",");
      i = j + 1;
      for (h = ""; i > 0;) k = --i % 26, h = alphabet[k], i = Math.floor(i / 26);
      i = jQuery('<a href="#">' + h + "</a>");
      h = function (a) {
        return function () {
          for (var b = 0, c = 0, d = proveit.getMWEditValue(), c = 0; c < a; c++) {
            b = d.indexOf(l[c], b);
            if (b == -1) return proveit.log("citationStrings[" + c + "]: " + l[c] + " not found.  Returning."), !1;
            b += l[c].length
          }
          b = d.indexOf(l[a], b);
          b == -1 ? proveit.log("citationStrings[" + a + "]: " + l[a] + " not found.") : proveit.highlightLengthAtIndex(b, l[a].length);
          return !1
        }
      }(j);
      i.click(h);
      g.append(i)
    }
    l.length > 1 && (j = jQuery("<p />"), j.append(this.getDescriptions().citestimes.replace(/\%s/img,'<span class="num-citations">' + this.localizeNumbers(l.length)) + "</span>: ").append(g), e.append(j));
    a.type != "raw" ? (g = jQuery("<button />", {
      text: this.getDescriptions().edit
    }), jQuery(g).button({
      icons: {
        primary: "ui-icon-pencil"
      },
      text: !1
    }), g.click(f), jQuery(".edit", b).append(g), g = jQuery("<button />", {
      "class": "edit",
      text: this.getDescriptions().editthisref
    }), jQuery(g).button({
      icons: {
        primary: "ui-icon-pencil"
      },
      text: !0
    }), g.click(f), e.append(g), jQuery(b).dblclick(f)) : jQuery(".edit", b).append("&nbsp;");
    l.length > 0 && (f = jQuery("<button />", {
      "class": "insert",
      text: this.getDescriptions().addthisreftocursor
    }), jQuery(f).button({
      icons: {
        primary: "ui-icon-arrowthick-1-e"
      },
      text: !0
    }), f.click(function () {
      d.insertRefIntoMWEditBox(a, !1);
      return !1
    }), e.append(f));
    return b
  },
  truncateTitle: function (a) {
    var c = a;
    a.length > 86 && (c = c.substring(0, 86), a = c.lastIndexOf(" "), a != -1 && (c = c.substr(0, a), c += " ..."));
    return c
  },
  formatDate: function (a) {
    var c = a.getFullYear(),
      b = this.getDescriptions().months[a.getMonth()],
      a = (a.getDate() < 10 ? "0" : "") + a.getDate();
    return a + " " + b + " " + c
  },
  addNewElement: function (a) {
    var c = this.getRefBox();
    jQuery(c).append(this.makeRefBoxRow(a, !1))
  }
}, window.proveit);
proveit.CiteReference.getTypes = function () {
  return "web,wiki,book,videogame,news,encyclopedia,encyclopediaatf,encyclopediavalimar,journal,dehkhoda,moien,video".split(",")
};
if (!String.prototype.trim) String.prototype.trim = function () {
  return this.replace(/^\s+|\s+$/g, "")
};
proveit.split._compliantExecNpcg = /()??/.exec("")[1] === void 0;
proveit.split._nativeSplit = String.prototype.split;
proveit.load();