Sha256: 1363bd4b559542fca4b7a96a807606bf2811a7436318d4efeb58a88501cce741

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

tb.cms.pages = {};

(function(){

tb.cms.pages = {
  edit: function(){
    tb.cms.pages.initFormTabs();
    $(".btn-preview").on('click', clickedPreviewButton);
    $("#spud_page_layout").on('change', changedLayoutSelection);
  }
};

var clickedPreviewButton = function(e){
  var button = $(this);
  var previewInput = $('input#preview');
  var form = button.parents('form')[0];

  button.button('reset');
  form.target = '_blank';
  previewInput.val(1);

  setTimeout(function(){
    form.target = '';
    form.onSubmit = null;
    previewInput.val(0);
    form.querySelectorAll('.btn').forEach(function(btn) {
      btn.disabled = false;
    });
  }, 200);
};

var changedLayoutSelection = function(e){
  var $this = $(this);
  $.get($this.attr("data-source"), { template: $this.val() }, function(data) {

    spud.admin.editor.unload();

    $("#page_partials_form").replaceWith(data);
    tb.cms.pages.initFormTabs();

    tb.editor.init();

  }, 'text').error(function(jqXHR) {
    alert("Error: " + jqXHR.responseText);
  });
};

tb.cms.pages.initFormTabs = function(){
  var tabNames = [];

  $('.formtabs .formtab').each(function(tabind) {
    if(tabind === 0){
      $(this).addClass('active');
    }
    this.id = 'tab-' + tabind;
    tabNames.push($('.tab_name',this).first().val());
  });

  var tabButtons = $('.formtabs .formtab_buttons').first();
  for(var x = 0; x < tabNames.length; x++){
    var tabButton = $('<li><a href="#tab-' + x + '" data-toggle="tab">' + tabNames[x] + '</a></li>');
    if(x === 0) {
      tabButton.addClass('active');
    }
    tabButtons.append(tabButton);
  }
};

})();

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tb_cms-1.3.6 app/assets/javascripts/admin/cms/pages.js