Project

General

Profile

« Previous | Next » 

Revision 274ff13f

Added by Andreas Kohlbecker over 7 years ago

ref #5956 improving classification breadcrumb navigation

  • avoiding boxes that are not being closed on mouse out second part
  • fixing loading animation

View differences:

modules/cdm_dataportal/js/jquery.cdm.taxonomic_children.js
164 164
        .css('overflow', 'auto');
165 165
      this.children = $('<div class="children"></div>');
166 166

  
167
      this.loading = $('<i class="fa-spinner fa-2x" />')
168
        .css('position', 'absolute')
169
        .hide();
167
      this.loading_class_attr = 'fa fa-spinner fa-pulse';
168
      // used to preserve the class attributes of the icon
169
      this.icon_class_attr = null;
170

  
171
      this.container.append(this.children);
172

  
170 173

  
171
      this.container.append(this.children).append(this.loading);
172 174
    },
173 175

  
174 176
    // Bind events that trigger methods
......
273 275
        .show();
274 276

  
275 277
      if(!this.isDataLoaded){
278
        this.icon_class_attr = this.$element.prev('i').attr('class'),
279
        this.$element.prev('i').attr('class', this.loading_class_attr);
276 280
        $.get(this.requestURI(undefined, undefined), function(html){
277 281
          plugin.handleDataLoaded(html);
278 282
        });
279 283
      } else {
280
        this.container.slideDown();
281
        this.adjustHeight();
282
        this.scrollToSelected();
284
        if(this.container.find('ul').length > 0) {
285
          this.container.show();
286
          this.adjustHeightAndMaxWidth();
287
          this.scrollToSelected();
288
        }
283 289
      }
284 290
    },
285 291

  
......
291 297

  
292 298
    handleDataLoaded: function(html){
293 299

  
294
      this.loading.hide();
295 300
      this.isDataLoaded = true;
296 301
      var listContainer = $(html);
297
      if(listContainer[0].tagName != 'UL'){
302
      if(listContainer[0].tagName != 'UL') {
298 303
        // unwrap from potential enclosing div, this is
299 304
        // necessary in case of compose_classification_selector
300 305
        listContainer = listContainer.children('ul');
301 306
      }
307

  
302 308
      this.container.hide();
303
      this.children.append(listContainer);
304
      this.itemsCount = listContainer.children().length;
305 309

  
306
      this.container.show();
307
      this.adjustHeight();
308
      this.scrollToSelected();
310
      if(listContainer.children().length > 0) {
311
        this.children.append(listContainer);
312
        this.itemsCount = listContainer.children().length;
313

  
314
        this.container.show();
315
        this.adjustHeightAndMaxWidth();
316
        this.scrollToSelected();
317
        this.checkMouseOver();
318
      }
319

  
320
      this.$element.prev('i').attr('class', this.icon_class_attr);
309 321
    },
310 322

  
311 323
    calculateViewPortRows: function() {
......
324 336
      return rows;
325 337
    },
326 338

  
327
    adjustHeight: function(){
339
    adjustHeightAndMaxWidth: function(){
328 340

  
341
      // adjustHeightAndMaxWidth
329 342
      var viewPortRows = this.calculateViewPortRows(this.itemsCount); //(itemsCount > this.options.viewPortRows.min ? this.options.viewPortRows.max : this.options.viewPortRows.min);
330 343
      this.log('itemsCount: ' + this.itemsCount + ' => viewPortRows: ' + viewPortRows);
331 344

  
......
333 346
      this.children
334 347
        .css('padding-top', this.lineHeight + 'px') // one row above current
335 348
        .css('padding-bottom', (viewPortRows - 2) * this.lineHeight + 'px'); // subtract 2 lines (current + one above)
349

  
350
      // adjust width to avoid the container hang out of the viewport
351
      max_width = Math.floor($(window).width() - this.element.getBoundingClientRect().left - 40);
352
      this.log('max_width: ' + max_width);
353
      this.container.css('max-width', max_width + 'px');
336 354
    },
337 355

  
338 356
    scrollToSelected: function () {
......
412 430
      this.log("finalRequest: " + request);
413 431

  
414 432
      return request;
433
    },
434

  
435
    monitorMouseOver: function() {
436
      while(this.container.delay(100).is(':visible')){
437
        this.checkMouseOver();
438
      }
439
    },
440

  
441
    checkMouseOver: function(){
442
      if(this.container.find(':hover').length == 0){
443
        this.hideChildren();
444
      }
415 445
    }
416 446

  
417 447
  });

Also available in: Unified diff