Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/ https://fsfe.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

support_js.xsl 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:template name="support-portal-javascript">
  4. <script type="text/javascript">
  5. /* <![CDATA[ */
  6. function map_json_to_html(data) {
  7. for (x in data) {
  8. $(x).html(data[x]);
  9. }
  10. }
  11. $(document).ready(function() {
  12. var secret = window.location.search.slice(1);
  13. if (secret.length == 32) {
  14. $.getJSON('portal-backend?'+secret, function(data) {
  15. $("#support_portal_loading").hide();
  16. $("#support_portal").show();
  17. if (data.error) {
  18. $("#support_portal").html(data.error);
  19. } else {
  20. map_json_to_html(data);
  21. }
  22. });
  23. } else {
  24. $("#support_portal_loading").html("Expected parameter not found, nothing to show here.");
  25. }
  26. });
  27. /* ]]> */
  28. </script>
  29. </xsl:template>
  30. <xsl:template name="support-form-javascript">
  31. <script type="text/javascript" src="/scripts/jquery.validate.min.js"></script>
  32. <!--
  33. script type="text/javascript" src="/scripts/jquery.validate-localization/messages_fi.js"></script
  34. *How to inser lang code in above?*
  35. -->
  36. <script type="text/javascript">
  37. /* <![CDATA[ */
  38. $(document).ready(function() {
  39. $("input[name=ref_url]").val(document.referrer);
  40. $("input[name=ref_id]").val(window.location.search.toString().slice(1));
  41. $("form.support").validate({
  42. rules: {
  43. email: {email: true, required: true},
  44. country_code: {required: true}
  45. },
  46. /* // didn't work with Firefox! Terrible hack written below
  47. submitHandler: function(form, event) {
  48. // stop form from submitting normally
  49. event.preventDefault(); // does not seem to work on Firefox
  50. var $submitbutton = $("form.support input[type='submit']");
  51. $submitbutton.val($submitbutton.attr("data-loading-text"))
  52. // Send the data using post and put the results in a div
  53. var $form = $("form.support");
  54. $.post($form.attr("action"), $form.serialize(),
  55. function(data) {
  56. $("#support_form").fadeOut();
  57. $("#introduction").append('<div id="support_form_sent">'+data+'</div>');
  58. }
  59. );
  60. return false; // prevent submit, not sure if has any effect
  61. }
  62. */
  63. });
  64. // terrible hack to prevent submit in Firefox!
  65. var newbutton = '<input type="button" value="' + $("form.support input[type='submit']").val() + '" data-loading-text="' + $("form.support input[type='submit']").attr("data-loading-text") + '"/>';
  66. $("form.support input[type='submit']").after(newbutton);
  67. $("form.support input[type='submit']").remove();
  68. $("form.support input[type='button']").click(function(){
  69. if ( $("form.support").valid() ) {
  70. var $submitbutton = $("form.support input[type='button']");
  71. $submitbutton.val($submitbutton.attr("data-loading-text"))
  72. /* Send the data using post and put the results in a div */
  73. var $form = $("form.support");
  74. $.post($form.attr("action"), $form.serialize(),
  75. function(data) {
  76. $("#support_form").fadeOut();
  77. $("#introduction").append('<div id="support_form_sent">'+data+'</div>');
  78. }
  79. );
  80. }
  81. });
  82. });
  83. /* ]]> */
  84. </script>
  85. </xsl:template>
  86. <xsl:template match="support-portal-javascript">
  87. <xsl:call-template name="support-portal-javascript" />
  88. </xsl:template>
  89. <xsl:template match="support-form-javascript">
  90. <xsl:call-template name="support-form-javascript" />
  91. </xsl:template>
  92. </xsl:stylesheet>