var $body; var $modal; var $modalCover; var $newComponentItem; var $newComponentStep1; var $newComponentStep2; $(document).ready(function() { $body = $('body'); $modal = $('.history-modal'); $modalCover = $('.modal-cover'); $newComponentItem = $('.new-component-item'); $newComponentStep1 = $('.new-component-step-1'); $newComponentStep2 = $('.new-component-step-2'); $newComponentButton = $('.new-component-button'); $(document).bind('XModule.loaded', function(e, element) { if ($(element).hasClass('.xmodule_display')) { return } var previewType = $(element).data('preview-type'); var moduleType = $(element).data('type'); new CMS.Views.ModuleEdit({ el: element, model: new CMS.Models.Module({ module: $(element).data('module'), id: $(element).data('id'), type: moduleType == 'None' ? null : moduleType, previewType: previewType == 'None' ? null : previewType, }) }); }); XModule.loadModules() $('.expand-collapse-icon').bind('click', toggleSubmodules); $('.visibility-options').bind('change', setVisibility); $newComponentButton.bind('click', showNewComponentForm); $newComponentStep1.find('.new-component-type a').bind('click', showNewComponentProperties); $newComponentStep2.find('.save-button').bind('click', saveNewComponent); $newComponentStep2.find('.cancel-button').bind('click', cancelNewComponent); $('.unit-history ol a').bind('click', showHistoryModal); $modal.bind('click', hideHistoryModal); $modalCover.bind('click', hideHistoryModal); }); function toggleSubmodules(e) { e.preventDefault(); $(this).toggleClass('expand').toggleClass('collapse'); $(this).closest('.branch, .window').toggleClass('collapsed'); } function setVisibility(e) { $(this).find('.checked').removeClass('checked'); $(e.target).closest('.option').addClass('checked'); } function editComponent(e) { e.preventDefault(); $(this).closest('.xmodule_edit').addClass('editing').find('.component-editor').slideDown(150); } function closeComponentEditor(e) { e.preventDefault(); $(this).closest('.xmodule_edit').removeClass('editing').find('.component-editor').slideUp(150); } function showNewComponentForm(e) { e.preventDefault(); $newComponentItem.addClass('adding'); $(this).slideUp(150); $newComponentStep1.slideDown(150); } function showNewComponentProperties(e) { e.preventDefault(); var displayName; var componentSource; var selectionRange; var $renderedComponent; switch($(this).attr('data-type')) { case 'video': displayName = 'Video'; componentSource = '