Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [jQuery] Przerobienie funkcji
vodkon
post
Post #1





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 8.02.2011

Ostrzeżenie: (0%)
-----


Witam znalazłem fajny skrypt http://davidwalsh.name/mootools-drag-ajax który zmienia kolejność wyświetlania rekordów i mam problem z przerobieniem funkcji. chce usunąć pole "#autoSubmit" tak żeby za każdym razem wykonywała się akcja bez konieczności wciskania checkbox
przerobić polecenie tak aby akcja działa się bez zaznaczania checkboxa

  1. /* when the DOM is ready */
  2. jQuery(document).ready(function() {
  3. /* grab important elements */
  4. var sortInput = jQuery('#sort_order');
  5. var submit = jQuery('#autoSubmit');
  6. var messageBox = jQuery('#message-box');
  7. var list = jQuery('#sortable-list');
  8. /* create requesting function to avoid duplicate code */
  9. var request = function() {
  10. jQuery.ajax({
  11. beforeSend: function() {
  12. messageBox.text('Updating the sort order in the database.');
  13. },
  14. complete: function() {
  15. messageBox.text('Database has been updated.');
  16. },
  17. data: 'sort_order=' + sortInput[0].value + '&ajax=' + submit[0].checked + '&do_submit=1&byajax=1', //need [0]?
  18. type: 'post',
  19. url: '<?php echo $_SERVER["REQUEST_URI"]; ?>'
  20. });
  21. };
  22. /* worker function */
  23. var fnSubmit = function(save) {
  24. var sortOrder = [];
  25. list.children('li').each(function(){
  26. sortOrder.push(jQuery(this).data('id'));
  27. });
  28. sortInput.val(sortOrder.join(','));
  29. console.log(sortInput.val());
  30. if(save) {
  31. request();
  32. }
  33. };
  34. /* store values */
  35. list.children('li').each(function() {
  36. var li = jQuery(this);
  37. li.data('id',li.attr('title')).attr('title','');
  38. });
  39. /* sortables */
  40. list.sortable({
  41. opacity: 0.7,
  42. update: function() {
  43. fnSubmit(submit[0].checked);
  44. }
  45. });
  46. list.disableSelection();
  47. /* ajax form submission */
  48. jQuery('#dd-form').bind('submit',function(e) {
  49. if(e) e.preventDefault();
  50. fnSubmit(true);
  51. });
  52. });


Ten post edytował vodkon 21.09.2012, 00:19:56
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 21:59