//= require rails_admin/custom/ckeditor_ajax (function($) { function replaceCkeditor(textarea) { if (!window.CKEDITOR || !textarea || !textarea.id) { return; } try { if (window.CKEDITOR.instances[textarea.id]) { window.CKEDITOR.instances[textarea.id].updateElement(); window.CKEDITOR.instances[textarea.id].destroy(true); } } catch (error) {} var $textarea = $(textarea); $textarea.removeClass('ckeditored'); window.CKEDITOR.replace(textarea, $textarea.data('options') || {}); $textarea.addClass('ckeditored'); } function refreshPaneEditors($scope) { $scope.find('[data-richtext=ckeditor]').each(function() { replaceCkeditor(this); }); } function ensurePaneEditors($scope) { var $editors = $scope.find('[data-richtext=ckeditor]'); if ($editors.length === 0) { return; } if (window.CKEDITOR) { setTimeout(function() { refreshPaneEditors($scope); }, 0); return; } var options = $editors.first().data('options') || {}; if (options.base_location) { window.CKEDITOR_BASEPATH = options.base_location; } if (options.jspath) { $.getScript(options.jspath, function() { setTimeout(function() { refreshPaneEditors($scope); }, 0); }); } } function nearestField($input) { return $input.closest('.form-group, .control-group'); } function buildProductLocaleTabs() { var $form = $('form').filter(function() { return $(this).find('[name="product[name]"]').length > 0; }).first(); if ($form.length === 0) { return; } var fieldMap = [ { key: 'zh-CN', label: '简体中文', nameField: nearestField($form.find('[name="product[name]"]')), detailField: nearestField($form.find('[name="product[detail]"]')) }, { key: 'en', label: 'English', nameField: nearestField($form.find('[name="product[name_en]"]')), detailField: nearestField($form.find('[name="product[detail_en]"]')) }, { key: 'ru', label: 'Русский', nameField: nearestField($form.find('[name="product[name_ru]"]')), detailField: nearestField($form.find('[name="product[detail_ru]"]')) }, { key: 'zh-TW', label: '繁體中文', nameField: nearestField($form.find('[name="product[name_tw]"]')), detailField: nearestField($form.find('[name="product[detail_tw]"]')) } ]; if ($form.find('.product-locale-tabs').length > 0) { return; } var hasAllFields = true; $.each(fieldMap, function(_, group) { if (group.nameField.length === 0 || group.detailField.length === 0) { hasAllFields = false; return false; } }); if (!hasAllFields) { return; } var $anchor = fieldMap[0].nameField; var $mount = $('
'); $anchor.before($mount); var $tabs = $(''); var $header = $('名称与详情按语言分别维护,未填写时接口默认回退到简体中文。