market.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Javascript for market plugin
  4. *
  5. * @package Market
  6. */
  7. $numchars = elgg_get_plugin_setting('market_numchars', 'market');
  8. if (0) { ?><script><?php }
  9. ?>
  10. elgg.provide('elgg.market');
  11. elgg.market.init = function() {
  12. var $form = $('form[name="marketForm"]');
  13. $form.on('submit', function(e) {
  14. if(!($('input[name="accept_terms"]').prop('checked'))) {
  15. alert(elgg.echo('market:accept:terms:error'));
  16. $('input[name="accept_terms"]').focus();
  17. e.preventDefault(); //prevent form from submitting
  18. }
  19. //e.preventDefault();
  20. });
  21. $('.market_charleft').val(<?php echo $numchars; ?> - $('#plaintext-description').val().length);
  22. $('#plaintext-description').keyup(function () {
  23. var $countField = $('.market_charleft');
  24. var maxLimit = <?php echo $numchars; ?>;
  25. // if too long...trim it!
  26. console.log('Max: ' + maxLimit + ' Chars: ' + $(this).val().length);
  27. if ($(this).val().length > maxLimit) {
  28. $(this).val($(this).val().substring(0, maxLimit));
  29. } else {
  30. // otherwise, update 'characters left' counter
  31. $countField.val(maxLimit - $(this).val().length);
  32. }
  33. });
  34. $('#market-type').change(function() {
  35. var value = $(this).val();
  36. $('#market-price').prop('readonly', false);
  37. if (value == 'free') {
  38. $('#market-price').val('0');
  39. $('#market-price').prop('readonly', true);
  40. } else if (value == 'swap') {
  41. $('#market-price').val('');
  42. $('#market-price').prop('readonly', true);
  43. }
  44. });
  45. };
  46. elgg.register_hook_handler('init', 'system', elgg.market.init);