zondag 20 februari 2011

chrome search engines

I've switched for quite some time now to chrome. However one oddity remained with chrome after I came back from holiday in Turkey: entering search terms in the address / search bar would lead me to the turkish google site, displaying turkish sites first, and all google information in Turkish.

I do like Turkish pizza, and I wish good health and good fortune to the Turkish people and I even don't mind when the Turkish become member of the European Union but having my search results in Turkish is just over the edge. This is where my love for Turkey stops.

Problem was to change this behavior I tried setting locale, but nothing was wrong with that (or maybe resetting did not solve it).
Until half an hour ago: I found the search engine option under the manage key at the basic preference panel. There I could not edit the default google search engine, so I tried to add an entry, but I found no way to add that entry to the default search engine part. I then removed google but alas I was not able to restore that leaving me only with bing or yahoo as a valid option.

I tried reinstalling chrome: to no avail as the user data settings are not updated. Removing the whole user data setting part (under ~/Library/Application Support/Google/Chrome/Default) Did solve my problem but that also removed all my local settings. Only removing the Web Data file was the accurate and spot on solution. This appears to be a sqlite datafile so I may be able to change it from there, but chrome is just capable of restoring this file to its original state and that solved my issue.

woensdag 19 januari 2011

file api with jquery

I have been working on a pure html website last year called iscriptdesign. It focuses on parameterized design with svg. Templates with svg and javascript code are processed, so that the user input gets evaluated by embedded javascript producing the svg. The svg can be exported, and you can use the output for a laser cutter or water cutter. Check it out ! One of the major shortcomings is the fact that it is not easy to display templates yourself. I was not able to load the template contents by a file uri, and so I had to rely on the templates on the same server as the html/javascript code for iscriptdesign resided. In the back of my mind I was looking for a more cms like approach to allow for personal uploads from third parties.

Until recently I started to realize the possibilities of the html5 file api. How sweet would it be if people could just drag n drop a template from their local filesystem on a drop spot of iscriptesign? Yesterday I started working on the project and now it's finished.

One of the real challenges was to incorporate it in jquery. Okay not really necessary of course but having the greater part of my website in jquery does make it somewhat desirable and you overtyping an example is not challenging is it?
help from stackoverflow and javaranch gave me head start (now that is challenging).

code



jQuery.fn.initDrop = function() {
return this.each(function () {
$(this).bind("dragover", function () {$(this).addClass('focus');$(".drop_container").addClass('focus'); return false;});
$(this).bind("dragleave",function () { $(this).removeClass('focus');$(".drop_container").removeClass('focus'); return false;});
$(this).bind("drop",function(e) {
$(".focus").removeClass("focus");
$(".drop_container").addClass('focus');
e.preventDefault();
var file = e.originalEvent.dataTransfer.files[0];
var reader = new FileReader();
reader.onload = function (evt) {
digestRaw(evt.target.result, true);
};
reader.readAsText(file);
});
$(this).prepend('
');
});
};


The div label dropspot is a simple div tag.

<div class="dropspot" id="dropspot">Drop Spot</div>

Which gets its drop behavior by:

$("#dropspot").initDrop();


Lessons


  • Unfortunately I only found this working for Firefox (Mac and Windows) and Chrome (Mac, Windows not tested). Safari is not supporting this yet.

  • dropevent needs to be unwrapped by retrieving e.orginalevent.

  • dragend is not working should be dragleave.

  • In my case i need to remove linefeed/carriage return characters for windows(msdos) files I need to do a text.replace("result.replace(/\r\n?|\n/g, "");