This question about Using an extension: Answered

Getting values selected from color picker

I would like to use colors selected by user from the color picker to generate list of colors separated by comma, so that user will be able to copy them. How can I do that?

Selected colors do not need to be saved in current topic, I only need to generate list.

-- MateuszKDzior - 18 Nov 2015

With a little fiddling, I was able to come up with a solution that I believe serves your purpose. It may not be the most elegant and I invite anyone to improve on it.

Here you go:

Your color list:

%STARTSECTION{"code"}%
%JQREQUIRE{"farbtastic"}%
%ADDTOZONE{"script" requires="JQUERYPLUGIN::FARBTASTIC" text="<script type='text/javascript'> 
 var clearList = function() { $('#colorlist').val(''); };
 $(function() { 
  // Function to check if selected color is in list and if not, adds it
  var checkColor = function(theColor) { 
    var oldList = $('#colorlist').val();
    var addComma = '';
    if (oldList != '') { var addComma = ', '; }
    if (oldList.indexOf(theColor) == '-1'){
      var newList = oldList + addComma + theColor;
      $('#colorlist').val(newList);
    }
  }
  // Captures selections in farbtastic color selector
  $('#colorpicker').on('mouseup', function() {
    checkColor($('input#color').val());
  });
  // Simply selects content of color list field when clicked
  $('#colorlist')
     .focus(function () { $(this).select(); } )
     .mouseup(function (e) {e.preventDefault(); 
  });
  // Adds instructions to the color field
  $('input#color').val('Click to select colors')
 }); 
 </script>"
}%
<input type="text" id="color" name="color" value="#9eeefa" class="jqFarbtastic" />  *Your color list:* <input type='text' id='colorlist' size='70' readonly='readonly' title='Click to select color list'> <input type='button' onclick='clearList();' value=' Clear list '>
%ENDSECTION{"code"}%

-- Main.LynnwoodBrown - 30 Nov 2015 - 19:00
 

QuestionForm edit

Subject Using an extension
Extension JQueryPlugin
Version Foswiki 2.0.2
Status Answered
Related Topics
Topic revision: r2 - 30 Nov 2015, LynnwoodBrown
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy