Sha256: 42c7c05e250b35afbaa733dea1c067b1d07c524272023047d2ff29590d42b113

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 KB

Contents

spud.admin.cms.pages = {};

(function(){

spud.admin.cms.pages = {
  edit: function(){
    spud.admin.editor.init({selector: '.page-partial-content-editor', width: $("#page_partials_form").width()});
    spud.admin.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);
  }, 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);
    spud.admin.cms.pages.initFormTabs();

    spud.admin.editor.init({selector: '.page-partial-content-editor', width: $("#page_partials_form").width()});

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

spud.admin.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

6 entries across 6 versions & 1 rubygems

Version Path
tb_cms-1.3.1 app/assets/javascripts/admin/cms/pages.js
tb_cms-1.3.0 app/assets/javascripts/admin/cms/pages.js
tb_cms-1.3.beta1 app/assets/javascripts/admin/cms/pages.js
tb_cms-1.2.3 app/assets/javascripts/admin/cms/pages.js
tb_cms-1.2.2 app/assets/javascripts/admin/cms/pages.js
tb_cms-1.2.1 app/assets/javascripts/admin/cms/pages.js