Changeset 72075 in spip-zone for _libs_


Ignore:
Timestamp:
Apr 16, 2013, 9:40:42 AM (7 years ago)
Author:
kent1@…
Message:

Ajouter la compatibilité iPad => https://github.com/F1LT3R/farbtastic-color-picker

File:
1 edited

Legend:

Unmodified
Added
Removed
  • _libs_/farbtastic/farbtastic.js

    r28736 r72075  
    22// Originaly from acko : http://acko.net/dev/farbtastic
    33// Modified by kent1 for new jQuery compatibility
    4 // Farbtastic 1.3.1
     4// Added iPad compatibility : https://github.com/F1LT3R/farbtastic-color-picker
     5// Farbtastic 1.4.0
    56
    67jQuery.fn.farbtastic = function (callback) {
     
    158159   */
    159160  fb.mousedown = function (event) {
    160     // Capture mouse
    161     if (!document.dragging) {
    162       $(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup);
    163       document.dragging = true;
    164     }
    165161
    166162    // Check which area is being dragged
     
    172168    return false;
    173169  }
     170
     171  /**
     172   * TouchConvert: Converts touch co-ordinates to mouse co-ordinates
     173   */
     174  fb.touchconvert = function (e) {
     175    var e = e.originalEvent.touches.item(0);
     176    return e;
     177  }
     178
     179  /**
     180   * Touchmove handler for iPad, iPhone etc
     181   */
     182  fb.touchmove = function (e) {
     183    fb.mousemove( fb.touchconvert(e)  );
     184    event.preventDefault();
     185    return false;
     186  }
     187
     188  /**
     189   * Touchend handler for iPad, iPhone etc
     190   */
     191  fb.touchend = function (event) {
     192    $(document).unbind('touchmove', fb.touchmove);
     193    $(document).unbind('touchend', fb.touchend);
     194    document.dragging = false;
     195    event.preventDefault();
     196    return false;
     197  }
     198
    174199
    175200  /**
     
    233258      // Change linked value
    234259      $(fb.callback).each(function() {
    235         if (this.value != fb.color) {
     260        if (this.value && this.value != fb.color) {
    236261          this.value = fb.color;
    237262        }
     
    320345
    321346  // Install mousedown handler (the others are set on the document on-demand)
    322   $('*', e).mousedown(fb.mousedown);
    323 
     347  $('*', e).mousedown(function(e){
     348    // Capture mouse
     349    if (!document.dragging) {
     350      $(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup);
     351      document.dragging = true;
     352    }
     353    fb.mousedown(e);
     354  });
     355
     356  // TouchStart bound, calls conversion of touchpoints to mousepoints
     357  $('*', e).bind("touchstart", function (e) {
     358    // Capture mouse
     359    if (!document.dragging) {
     360      $(document).bind('touchmove', fb.touchmove).bind('touchend', fb.touchend);
     361      document.dragging = true;
     362    }
     363    fb.mousedown( fb.touchconvert(e) );
     364    e.preventDefault();
     365    return false;
     366  });
     367 
    324368    // Init color
    325369  fb.setColor('#000000');
     
    329373    fb.linkTo(callback);
    330374  }
    331 };
     375}
Note: See TracChangeset for help on using the changeset viewer.