1 // This is a manifest file that'll be compiled into application.js, which will include all the files
4 // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
7 // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
10 // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11 // GO AFTER THE REQUIRES BELOW.
14 //= require jquery_ujs
16 //= require bootstrap/dropdown
17 //= require bootstrap/tab
18 //= require bootstrap/tooltip
19 //= require bootstrap/popover
20 //= require bootstrap/collapse
21 //= require bootstrap/modal
22 //= require bootstrap/button
23 //= require bootstrap3-editable/bootstrap-editable
30 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
34 $(document).ajaxStart(function(){
35 $('.modal-with-loading-spinner .spinner').show();
36 }).ajaxStop(function(){
37 $('.modal-with-loading-spinner .spinner').hide();
40 $('[data-toggle=tooltip]').tooltip();
42 $('.expand-collapse-row').on('click', function(event) {
43 var targets = $('#' + $(this).attr('data-id'));
44 if (targets.css('display') == 'none') {
45 $(this).addClass('icon-minus-sign');
46 $(this).removeClass('icon-plus-sign');
48 $(this).addClass('icon-plus-sign');
49 $(this).removeClass('icon-minus-sign');
51 targets.fadeToggle(200);
57 on('ajax:send', function(e, xhr) {
60 $('.loading').fadeTo('fast', 1);
63 on('ajax:complete', function(e, status) {
66 $('.loading').fadeOut('fast', 0);
69 on('ajaxSend', function(e, xhr) {
70 // jQuery triggers 'ajaxSend' event when starting an ajax call, but
71 // rails-generated ajax triggers generate 'ajax:send'. Workbench
72 // event listeners currently expect 'ajax:send', so trigger the
73 // rails event in response to the jQuery one.
74 $(document).trigger('ajax:send');
76 on('ajaxComplete', function(e, xhr) {
77 // See comment above about ajaxSend/ajax:send
78 $(document).trigger('ajax:complete');
80 on('click', '.removable-tag a', function(e) {
81 var tag_span = $(this).parents('[data-tag-link-uuid]').eq(0)
82 tag_span.fadeTo('fast', 0.2);
83 $.ajax('/links/' + tag_span.attr('data-tag-link-uuid'),
86 data: { '_method': 'DELETE' },
88 done(function(data, status, jqxhr) {
91 fail(function(jqxhr, status, error) {
92 this.addClass('label-danger').fadeTo('fast', '1');
96 on('click', 'a.add-tag-button', function(e) {
98 var new_tag_uuid = 'new-tag-' + Math.random();
99 var tag_head_uuid = $(this).parents('tr').attr('data-object-uuid');
100 var new_tag = window.prompt("Add tag for collection "+
106 $('<span class="label label-info removable-tag"></span>').
107 attr('data-tag-link-uuid', new_tag_uuid).
109 css('opacity', '0.2').
110 append(' <span class="removable-tag"><a title="Delete tag"><i class="fa fa-fw fa-trash-o"></i></a></span>');
114 append(new_tag_span).
116 $.ajax($(this).attr('data-remote-href'),
118 type: $(this).attr('data-remote-method'),
120 'link[head_uuid]': tag_head_uuid,
121 'link[link_class]': 'tag',
122 'link[name]': new_tag
124 context: new_tag_span}).
125 done(function(data, status, jqxhr) {
126 this.attr('data-tag-link-uuid', data.uuid).
129 fail(function(jqxhr, status, error) {
130 this.addClass('label-danger').fadeTo('fast', '1');
136 on('ajax:complete ready', function() {
137 // See http://getbootstrap.com/javascript/#buttons
140 on('ready ajax:complete', function() {
141 $('[data-toggle~=tooltip]').tooltip({container:'body'});
143 on('ready ajax:complete', function() {
144 // This makes the dialog close on Esc key, obviously.
145 $('.modal').attr('tabindex', '-1')
148 HeaderRowFixer = function(selector) {
149 this.duplicateTheadTr = function() {
150 $(selector).each(function() {
151 var the_table = this;
152 if ($('>tbody>tr:first>th', the_table).length > 0)
154 $('>tbody', the_table).
155 prepend($('>thead>tr', the_table).
160 this.fixThead = function() {
161 $(selector).each(function() {
163 $('> tbody > tr:eq(1) > td', this).each( function(i,v){
164 widths.push($(v).width());
166 for(i=0;i<widths.length;i++) {
167 $('thead th:eq('+i+')', this).width(widths[i]);
173 var fixer = new HeaderRowFixer('.table-fixed-header-row');
174 fixer.duplicateTheadTr();
176 $(window).resize(function(){
179 $(document).on('ajax:complete', function(e, status) {
180 fixer.duplicateTheadTr();
184 $(document).ready(function() {
185 /* When wiselinks is initialized, selection.js is not working. Since we want to stop
186 using selection.js in the near future, let's not initialize wiselinks for now. */
188 // window.wiselinks = new Wiselinks();
190 $(document).off('page:loading').on('page:loading', function(event, $target, render, url){
191 $("#page-wrapper").fadeOut(200);
194 $(document).off('page:redirected').on('page:redirected', function(event, $target, render, url){
197 $(document).off('page:always').on('page:always', function(event, xhr, settings){
198 $("#page-wrapper").fadeIn(200);
201 $(document).off('page:done').on('page:done', function(event, $target, status, url, data){
204 $(document).off('page:fail').on('page:fail', function(event, $target, status, url, error, code){