var arrayProto = function(){ if (!Array.isArray) { Array.isArray = function(arg) { return Object.prototype.toString.call(arg) === '[object Array]'; }; } Array.prototype.uniq = function() { return this.filter(function(value, index, self) { return self.indexOf(value) === index; }); } Array.prototype.flatten = function() { return [].concat.apply([], this); } } var fieldsHelper = function(){ $('form').on('keypress', '[data-no-submit]', function(e){ return e.keyCode != 13 }); $('[data-fields]').on('click', function(e){ var time = new Date().getTime() var regexp = new RegExp($(this).data('fields-id'), 'g') $(this).before($(this).data('fields').replace(regexp, time)) e.preventDefault(); }); } var reorderableElements = function(){ $('.reorderable').sortable({ axis:'y', handle: '.sort_handle', tolerance: 'pointer', containment: 'parent', revert: 50, update: function(){ $('.order_field', this).each(function(i){ $(this).val(i) }) } }); $('.sortable_table tbody').sortable({ axis:'y', handle: '.sort_handle', tolerance: 'pointer', containment: 'parent', revert: 50, update: function(){ $.ajax({ url: $(this).attr('index_data-sort'), method: 'POST', dataType: 'script', data: $(this).sortable('serialize')}); } }); } var searchableSelectFields = function(){ $('select[data-searchable-select]').select2(); $('.select2').select2(); $('select[multiple]').each(function (i, e) { $e = $(e); console.log($e.data('pagination')) if (!!$e.data('max-choices')) { $e.select2({ maximumSelectionLength: $e.data('max-choices') }); } else { $e.select2(); } }); } function formatRepo (repo) { if (repo.loading) return repo.text; console.log(repo) markup = "