//= require comfortable_mexican_sofa/jquery.js //= require comfortable_mexican_sofa/jquery_ui.js //= require comfortable_mexican_sofa/rails.js //= require comfortable_mexican_sofa/codemirror/codemirror.js $.CMS = function(){ var current_path = window.location.pathname; var admin_path_prefix = $('meta[name="cms-admin-path"]').attr('content'); $(function(){ $.CMS.slugify(); $.CMS.tree_methods(); $.CMS.load_page_blocks(); $.CMS.enable_rich_text(); $.CMS.enable_codemirror(); $.CMS.enable_date_picker(); $.CMS.enable_sortable_list(); if($('form#page_edit, form#page_new').get(0)) $.CMS.enable_page_save_form(); if($('#mirrors').get(0)) $.CMS.enable_mirrors_widget(); if($('#page_save').get(0)) $.CMS.enable_page_save_widget(); if($('#uploader_button').get(0)) $.CMS.enable_uploader(); if($('.categories_widget').get(0)) $.CMS.enable_categories_widget(); }); return { enable_sortable_list: function(){ $('.sortable, ul.sortable ul').sortable({ handle: '.dragger', axis: 'y', update: function(){ $.post(current_path + '/reorder', '_method=put&'+$(this).sortable('serialize')); } }) }, slugify: function(){ $('input#slugify').bind('keyup.cms', function() { var slug_input = $('input#slug'); var delimiter = slug_input.hasClass('delimiter-underscore') ? '_' : '-'; slug_input.val( slugify( $(this).val(), delimiter ) ); }); function slugify(str, delimiter){ var opposite_delimiter = (delimiter == '-') ? '_' : '-'; str = str.replace(/^\s+|\s+$/g, ''); var from = "ÀÁÄÂÈÉËÊÌÍÏÎÒÓÖÔÙÚÜÛàáäâèéëêìíïîòóöôùúüûÑñÇç"; var to = "aaaaeeeeiiiioooouuuuaaaaeeeeiiiioooouuuunncc"; for (var i=0, l=from.length ; i