Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [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
Arcioch
post
Post #2





Grupa: Zarejestrowani
Postów: 324
Pomógł: 110
Dołączył: 18.09.2012

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


Wydaje mi się że wystarczy zmienić ostatniego binda ale nie jestem pewien (IMG:style_emoticons/default/wink.gif) spróbuj zmienić to:

  1. jQuery('#dd-form').bind('submit',function(e) {
  2. if(e) e.preventDefault();
  3. fnSubmit(true);
  4. });


na to:

  1. jQuery('#dd-form').bind('submit',function() {
  2. fnSubmit(true);
  3. });
Go to the top of the page
+Quote Post
vodkon
post
Post #3





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

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


Niestety nie pomogło nadal trzeba wcisnąć checkbox
na stronie http://davidwalsh.name/mootools-drag-ajax jest jeszcze kod html/php
chodzi o to aby usunąć checkbox tak aby skrypt wykonywał się automatycznie bez konieczności zaznaczania checkbox

Ten post edytował vodkon 21.09.2012, 11:06:35
Go to the top of the page
+Quote Post
Arcioch
post
Post #4





Grupa: Zarejestrowani
Postów: 324
Pomógł: 110
Dołączył: 18.09.2012

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


Oki zrobię sobie to na lokalu i napisze zaraz rozwiązanie (IMG:style_emoticons/default/wink.gif)

Rozwiązanie (IMG:style_emoticons/default/smile.gif)

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


Przetestuj (IMG:style_emoticons/default/wink.gif)

Ten post edytował Arcioch 21.09.2012, 11:19:32
Go to the top of the page
+Quote Post
vodkon
post
Post #5





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

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


Dziękuje działa
Go to the top of the page
+Quote Post

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: 27.08.2025 - 13:04