views_boxes_view.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. (function ($) {
  2. Drupal.behaviors.view_boxes = {
  3. attach: function(context) {
  4. //All of this code is for the custom id field
  5. // Bind an update event to all of our id-value fields
  6. // this takes the values from all of the corresponding
  7. // id-fields parse and update our value
  8. $(".id-value").bind("update", function(e) {
  9. values = [];
  10. groupid = $(this).attr('group');
  11. $("#" + groupid).find(".id-field").each(function(i) {
  12. value = $(this).val();
  13. re = /.*id:(.*)\]/;
  14. if(value.match(re)) {
  15. id = value.replace(re, "$1");
  16. values.push(id);
  17. }
  18. });
  19. $(this).val(values.join("+"));
  20. });
  21. // make all wrappers sortable
  22. // and set up an update whenever a field is left
  23. $(".id-group", context).each(function () {
  24. $(this, context).find(".id-field").focusout(function (e){
  25. valueid = $(this).attr("key").replace(/_/g,"-");
  26. $("#edit-" + valueid).trigger("update");
  27. });
  28. $(this, context).find("input.form-submit").click(function (e){
  29. valueid = $(this).attr("key").replace(/_/g,"-");
  30. $("#edit-" + valueid).trigger("update");
  31. });
  32. $(this, context).find(".id-sortable", context).sortable({
  33. stop: function(event, ui) {
  34. valueid = $(this).attr("key").replace(/_/g,"-");
  35. $("#edit-" + valueid).trigger("update");
  36. }
  37. });
  38. });
  39. // Redefining this here as the popup wasn't hiding properly following a click
  40. if (Drupal.jsAC != null) {
  41. Drupal.jsAC.prototype.select = function (node) {
  42. this.input.value = $(node).data('autocompleteValue');
  43. $(this.popup).css({ visibility: 'hidden' });
  44. valueid = $(this.input).attr("key").replace(/_/g,"-");
  45. $("#edit-" + valueid).trigger("update");
  46. };
  47. }
  48. }
  49. };
  50. })(jQuery);