RenderImageSelector
Renders a widget to select an image attached to a topic

Documentation

Select an image attached to a OBJECT topic

Parameters
  • OBJECT, default BASEWEB.BASETOPIC
  • SELECTED
  • FIELDNAME

Implementation

%STARTINCLUDE%<!-- -->
<div class="fwbImageSelector">
  %ATTACHMENTS{
    topic="%OBJECT{default="%BASEWEB%.%BASETOPIC%"}%"
    name=".*\.(jpe?g|JPE?G|gif|GIF|png|PNG)$"
    _exclude="%DEFAULT{default=""}%"
    sort="name"
    format="<label class='$percntIF{\"'%SELECTED%'='$name'\" then=\" selected orig\"}$percnt'>
        <input type='radio' name='%FIELDNAME{default="file"}%' value='$urlpath' $percntIF{\"'%SELECTED%'='$name'\" then=\" checked='checked'\"}$percnt />
        <img src='$urlpath' alt='$name' height='100px' />
      </label>"
  }%
  %CLEAR%
</div>
%ADDTOZONE{"script" 
   id="RENDERIMAGESELECTOR::JS"
   requires="JQUERYPLUGIN::LIVEQUERY"
   text="<script type='text/javascript' src='%PUBURLPATH%/Applications/RenderImageSelector/script.js?t=%GMTIME{"$epoch"}%'></script>"
}%%ADDTOZONE{"head" 
   id="RENDERIMAGESELECTOR::CSS" 
   text="<link rel='stylesheet' href='%PUBURLPATH%/Applications/RenderImageSelector/style.css?t=%GMTIME{"$epoch"}%' media='all' />"
}%<!-- -->%STOPINCLUDE%

Css

.fwbImageSelector input {
  display:none;
}
.fwbImageSelector label {
  float:left;
  margin:0 5px 5px 0;
  padding:1px;
}
.fwbImageSelector label img {
  float:left;
  border-radius:5px;
  overflow:hidden;
  margin:2px;
}
.fwbImageSelector label.selected img {
  border:2px solid #b22222;
  box-shadow:2px 2px 10px -1px #000;
  margin:-1px 1px 1px -1px;
}

Javascript

"use strict";
jQuery(function($) {
   $(".fwbImageSelector").livequery(function() {
      var $selector = $(this);

      $selector.find("label").on("click", function() {
         var $this = $(this),
             isChecked = $this.find("input").prop("checked");

         $selector.find("input:checked").prop("checked", false);
         $selector.find(".selected").removeClass("selected");

         if (!isChecked) {
            $this.addClass("selected").find("input").prop("checked", true);
         }
         return false;
      });
   });
});

Test

Copyright

© 2006-2013 Michael Daum http://michaeldaumconsulting.com

This file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. For more details read the LICENSE.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, to the extent permitted by law; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

TopicFunction edit

TopicType TopicFunction, DocuTopic, ApplicationTopic, WikiTopic
TopicTitle
Summary Renders a widget to select an image attached to a topic
WikiApplication WikiWorkbench
Topic attachments
ISorted ascending Attachment Action Size Date Who Comment
style.csscss style.css manage 356 bytes 23 Jan 2017 - 09:50 AdminUser Generated by AttachContentPlugin
nobody.jpegjpeg nobody.jpeg manage 3 K 23 Jan 2017 - 09:50 AdminUser  
script.jsjs script.js manage 549 bytes 23 Jan 2017 - 09:50 AdminUser Generated by AttachContentPlugin
Das Urheberrecht © liegt bei den mitwirkenden Autoren. Alle Inhalte dieser Kollaborations-Plattform sind Eigentum der Autoren.