jquery.yii.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * jQuery Yii plugin file.
  3. *
  4. * @author Qiang Xue <qiang.xue@gmail.com>
  5. * @link http://www.yiiframework.com/
  6. * @copyright 2008-2010 Yii Software LLC
  7. * @license http://www.yiiframework.com/license/
  8. */
  9. ;(function($) {
  10. $.yii = {
  11. version : '1.0',
  12. submitForm : function (element, url, params) {
  13. var f = $(element).parents('form')[0];
  14. if (!f) {
  15. f = document.createElement('form');
  16. f.style.display = 'none';
  17. element.parentNode.appendChild(f);
  18. f.method = 'POST';
  19. }
  20. if (typeof url == 'string' && url != '') {
  21. f.action = url;
  22. }
  23. if (element.target != null) {
  24. f.target = element.target;
  25. }
  26. var inputs = [];
  27. $.each(params, function(name, value) {
  28. var input = document.createElement("input");
  29. input.setAttribute("type", "hidden");
  30. input.setAttribute("name", name);
  31. input.setAttribute("value", value);
  32. f.appendChild(input);
  33. inputs.push(input);
  34. });
  35. // remember who triggers the form submission
  36. // this is used by jquery.yiiactiveform.js
  37. $(f).data('submitObject', $(element));
  38. $(f).trigger('submit');
  39. $.each(inputs, function() {
  40. f.removeChild(this);
  41. });
  42. }
  43. };
  44. })(jQuery);