polyglot.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup UnaStudio UNA Studio
  6. * @{
  7. */
  8. function BxDolStudioPolyglot(oOptions) {
  9. this.sActionsUrl = oOptions.sActionUrl;
  10. this.sObjName = oOptions.sObjName == undefined ? 'oBxDolStudioPolyglot' : oOptions.sObjName;
  11. this.sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
  12. this.iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  13. this.sCodeMirror = oOptions.sCodeMirror == undefined ? '' : oOptions.sCodeMirror;
  14. this.sPage = oOptions.sPage == undefined ? 'general' : oOptions.sPage;
  15. var $this = this;
  16. $(document).ready (function () {
  17. if($this.sCodeMirror != '')
  18. $this.initCodeMirror($this.sCodeMirror);
  19. });
  20. }
  21. BxDolStudioPolyglot.prototype.initCodeMirror = function(sSelector) {
  22. var oSelector = $(sSelector);
  23. for(var i = 0; i < oSelector.length; i++) {
  24. var e = CodeMirror.fromTextArea(oSelector.get(i), {
  25. lineNumbers: true,
  26. mode: "htmlmixed",
  27. htmlMode: true,
  28. matchBrackets: true
  29. });
  30. }
  31. };
  32. /**
  33. * Is needed if AJAX is used to change (reload) pages.
  34. */
  35. BxDolStudioPolyglot.prototype.changePage = function(sType, iStart, iLength) {
  36. var oDate = new Date();
  37. var $this = this;
  38. var oParams = {
  39. pgt_action: 'get-page-by-type',
  40. pgt_value: sType,
  41. _t:oDate.getTime()
  42. };
  43. if(sType == 'keys') {
  44. oParams.pgt_category = $('#pgt-keys-category').val();
  45. oParams.pgt_language = $('#pgt-keys-language').val();
  46. oParams.pgt_keyword = $('#pgt-keys-keyword').val();
  47. if(iStart)
  48. oParams.pgt_start = iStart;
  49. if(iLength)
  50. oParams.pgt_length = iLength;
  51. }
  52. $.get(
  53. this.sActionsUrl,
  54. oParams,
  55. function(oData) {
  56. if(oData.code != 0) {
  57. bx_alert(oData.message);
  58. return true;
  59. }
  60. $('#bx-std-pc-menu > .bx-std-pmi-active').removeClass('bx-std-pmi-active');
  61. $('#bx-std-pmi-' + sType).addClass('bx-std-pmi-active');
  62. $('#bx-std-pc-content').bx_anim('hide', $this.sAnimationEffect, $this.iAnimationSpeed, function() {
  63. $(this).html(oData.content).bx_anim('show', $this.sAnimationEffect, $this.iAnimationSpeed);
  64. });
  65. },
  66. 'json'
  67. );
  68. return true;
  69. };
  70. /** @} */