Sha256: 95570cf6c6b899e847d39599f4993279650bab9d966a5a5617a3dca776a0986e

Contents?: true

Size: 1.53 KB

Versions: 14

Compression:

Stored size: 1.53 KB

Contents

jQuery(document).ready(function($) {
  if ($("body").attr("id").indexOf("guts_navigation_items") == -1) { return; }
  
  $(window).on("load", function() {
    if ($("body").attr("id").indexOf("guts_navigation_items_edit") == -1) { return; }
    
    // Trigger change for edit to run
    $("#navigation_item_navigatable_type").trigger("change");
  });
  
  $("#navigation_item_navigatable_type").on("change", function() {
    var value = $(this).val();
    if (value === "") {
      // Show custom entry
      $("#navigation_item_navigatable_id").html("").hide();
      $("#navigation_item_custom").show();
    } else {
      // Show dynamic navigatable entries
      $("#navigation_item_navigatable_id").html("").show();
      $("#navigation_item_custom").hide();

      $.ajax({
        url: $(this).data("callback-url"),
        data: {model: $(this).val()},
        dataType: "json",
      }).done(function(data) {
        $.each(data, function() {
          // Populate the navigatable objects
          $("#navigation_item_navigatable_id").append('<option value="'+this.id+'">'+this.format+'</option>');
        });
        
        var initial = $("#navigation_item_navigatable_id").data("initial");
        if (initial) {
          // Edit screen, re-select the initial after the AJAX call
          $("#navigation_item_navigatable_id option").each(function() {
            if ($(this).val() == initial) {
              $("#navigation_item_navigatable_id").val($(this).val()).trigger("change");
            }
          });
        }
      });
    }
  });
});

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
guts-1.3.4 app/assets/javascripts/guts/navigation.js
guts-1.3.3 app/assets/javascripts/guts/navigation.js
guts-1.3.2 app/assets/javascripts/guts/navigation.js
guts-1.3.1 app/assets/javascripts/guts/navigation.js
guts-1.3.0 app/assets/javascripts/guts/navigation.js
guts-1.2.2 app/assets/javascripts/guts/navigation.js
guts-1.2.1 app/assets/javascripts/guts/navigation.js
guts-1.2.0 app/assets/javascripts/guts/navigation.js
guts-1.1.1 app/assets/javascripts/guts/navigation.js
guts-1.1.0 app/assets/javascripts/guts/navigation.js
guts-1.0.8 app/assets/javascripts/guts/navigation.js
guts-1.0.7 app/assets/javascripts/guts/navigation.js
guts-1.0.5 app/assets/javascripts/guts/navigation.js
guts-1.0.3 app/assets/javascripts/guts/navigation.js