Category Archives: Work stuff

DropzoneJs 5.5 & Thumbnail Problems

DropzoneJs is a very good JavaScript upload script and flexible.

Too bad, upgrade is something a bit tricky and make existing script not work.  Well I would not complain if there is a good document, but there is not.

Problem with thumbnail not display when retrieve existing file. It used to be function createThumbnailFromUrl.  The parameter has changed so this solution does work

dz is your Dropzone object. The key is to have dataURL set on your file.

var thumb = { name: filename, size: 0, dataURL: ‘/upload-directory/’ + ‘filename’ };
dz.files.push(thumb);

// Call the default addedfile event handler
dz.emit(‘addedfile’, thumb);

dz.createThumbnailFromUrl(thumb,
dz.options.thumbnailWidth, dz.options.thumbnailHeight,
dz.options.thumbnailMethod, true, function (thumbnail) {
dz.emit(‘thumbnail’, thumb, thumbnail);
});

// Make sure that there is no progress bar, etc…
dz.emit(‘complete’, thumb);

jQuery Toggle/Manipulate FontAwesome 5

FontAwesome is great, but after upgrade to 5, there are prefix types (far, fas, fab) added and then the way to render with SVG/JS to make its mess.  There are 2 types of use, but SVG/JS is way better in advance features to decorate the icons.

Not sure if it’s only me that seems the manual/instruction on how to manipulate the font awesome using SVG/JS does not work as promise. I have to figure it out myself.

So here is my solutions

This is jQuery toggle function to change from <i class=”fas fa-plus-circle”></i> to <i class=”fas fa-minus-circle”></i> icon

jQuery('.btn').on("click", function(){
   jQuery(this).find('[data-fa-i2svg]')
       .attr('data-prefix', 'fas');
    if (jQuery(this).find('[data-fa-i2svg]')
       .attr('data-icon') == 'minus-circle') {
         jQuery(this).find('[data-fa-i2svg]')
           .removeClass('fa-minus-circle')
           .addClass('fa-plus-circle')
           .attr('data-icon', 'plus-circle');
   }else{
         jQuery(this).find('[data-fa-i2svg]')
           .removeClass('fa-plus-circle')
           .addClass('fa-minus-circle')
           .attr('data-icon', 'minus-circle');
   }
});

Explanation:

  1. There are 2 elements that shared ‘data-fa-i2svg’ attribute (<i> and <svg>)
  2. You have to find the element with attribute ‘data-fa-i2svg’ then  add/remove class with original FontAwesome class which starts with fa-xxxxx.
  3. Change the attribute ‘data-icon’ to the FontAwesome class (eliminate the fa- prefix)
  4. Last thing, change the attribute ‘data-prefix'  to make it correct prefix type for each icon.

 

Bootstrap DateRangePicker & FancyBox

Lately I have a messed problem that daterangepicker not function correctly on fancybox v. 2.1.5 (modal).

DateRangePicker w/ FancyBox
After fix problem. it works correctly

The problem is daterangepicker works fine on parent page, but not work on fancybox dialog. The calendar not showing, no error in console. I guess there is something not in the right place.

My keywords to searching for the answer  is “bootstrap daterangepicker fancybox” and not find any related answer so I try myself to use option “parentEl” of daterangepicker which seems for something and still not work, apparently I don’t know how to use it since there is no example or much explanation.

I’m finding a solution for a day, without any of daterangepicker explanation on the document how to use the option “parentEl”.  Not even mention that it is for use with modal. Would you say poor documentation?

The very short description says:

parentEl: (string) jQuery selector of the parent element that the date range picker will be added to, if not provided this will be ‘body’

So after reading the problem all over the internet, found that the modal have to use option “parentEl” but still don’t know how since there is no example. I have tried it myself several ways.

Here is my solution

add a script in the ajax file that loads inside fancyBox so it will be loaded right after the form.

<input type="text" name="date" id="date" value="" class="fancyBoxDateRangePicker">


$(document).ready(function(){
$('.fancyBoxDateRangePicker').daterangepicker({
"parentEl": ".fancybox-overlay",
});

The input with daterangepicker has a css class name “fancyBoxDateRangePicker”  (use your own) and the class “fancybox-overlay” is the default css class in fancyBox so you don’t have to do anything with that.

Then after you use this, still one more problem that the calendar layer will be loaded under the fancybox modal so you have to add style to override.

.daterangepicker.dropdown-menu {
max-width: none;
z-index: 99999 !important;
}

Then one more problem, if the parent screen scroll, you can add more style to fix it

.fancybox-lock {
overflow: visible !important;
}

 

Hope this will help your problem 😀

Color Name from Hex to Color

I have to implement the color extractor from image so I have too look at the php script that can extract color in image to hex code, but then need to convert hex or rgb to human color name. So this is useful.

In case you are looking for this. It’s an array of color name matching with RGB in format

$colors = array(
"Acid Green" => array(176, 191, 26),
"Aero" => array(124, 185, 232),
...
...

Look at this link: http://pastebin.com/KsPbPU1j

jStarbox Does Not Show Stars on Hidden Tab

If you are using jStarbox so you know what I refer to.

I have downloaded Flat Bootstrap Responsive Website to tried jStarbox and was on the UI implementation. It was so messy because I have it on my hidden tab. After switch the tab to appear the rating stars not display as expected. I spent about 2 days for this as I am not that good with jQuery and Javascript much.

jStarbox

The visible tab is fine, but the hidden tabs seems has problem. I am not sure because of the design or the jStarbox does not have this prevention.

It appeared that .colorbar not set to the size of .positioner after visible. (.positioner still have width of 0px) here is what I do.

starbox.starbox(‘setOption’, ‘average’, averageVal); //call method to reset the average value

var size = 85; //manual fixed the size

positioner.children(‘.stars’).children(‘.colorbar’).css(“width”, (averageVal*size)+”px”); //add style

To try jStarBox Click here https://github.com/sabberworm/jStarbox

Recruit 1 Web Graphic Designer & 1 PHP Web Developer


I am recruiting new member for IT team. 1 Position of Web Graphic Designer, 1 Position of PHP Web Developer
I really like someone to join the team. Please let me know if you are qualify.
General Qualification:
1. Age 26 – 35 years old
2. Thai nationality
3. 2 – 3 Years Experience
4. Fair English communication

Salary is 25,000 Baht – 40,000 Baht depends on your experience.
Our office located in Silom, Bangkok. Easy to commute by BTS/MRT

More qualification is after the jump or download this recruitment description here
Continue reading Recruit 1 Web Graphic Designer & 1 PHP Web Developer