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 = "
  • " + repo.name + "
  • "; return markup; } function formatRepoSelection (repo) { console.log(repo) return repo.text; } var sortThisOut = function(){ $('[data-add-key]').on('click', function(e){ e.preventDefault(); $new = $(this).prev().clone() $new.find('.fields--stacked input:not(:first)').remove() $new.find('input').val('') $new.insertBefore($(this)) }) $('[data-add-value]').on('click', function(e){ e.preventDefault(); $new = $(this).prev().clone() $new.find('input').val('') $new.insertBefore($(this)) }) $('#select_all').change(function(){ //'select all' change var status = this.checked; // 'select all' checked status $('.check_box_column input').each(function(){ //iterate all listed checkbox items this.checked = status; //change '.checkbox' checked status }); }); $('.check_box_column input').change(function(){ //'.checkbox' change //uncheck 'select all', if one of the listed checkbox item is unchecked if(this.checked == false){ //if this item is unchecked $('#select_all')[0].checked = false; //change 'select all' checked status to false } //check 'select all' if all checkbox items are checked if ($('.check_box_column input:checked').length == $('.check_box_column input').length ){ $('#select_all')[0].checked = true; //change 'select all' checked status to true } }); $('input:checkbox').change(function(){ if($('input:checkbox').is(':checked')) { $('html').addClass('bulk_actions_show'); } else { $('html').removeClass('bulk_actions_show'); } }); }