Drag2Crop mootools plugin : Drag picture inside a box

UPDATE 09/06/2010 : Start drag at “Top” and “Left” values.

facebook_thumbnail

Drag2Crop : This small mootools plugin extends “Drag plgin” allow to drag picture inside a small box to get a thumbnail showing the good part of the picture, and after Drag complete return values [Top, Left, Width, Height] of picture relative to the box (Like facebook).

The MooTools 1.2 JavaScript

var Drag2Crop = new Class({
    Extends: Drag,
    Implements:[Options,Events],
    initialize: function(picture, options) {
        this.setOptions({
            relative    :    'relative',
            modifiers   :    { x: 'scrollLeft', y: 'scrollTop' },
            style       :    false,
            invert      :    true,
            top  		:    0,
            left		:    0,
            onComplete  :    this.complete.bind(this),
            debug       :    false
        }, options);
		this.top        =     this.options.top.toInt();
        this.left       =     this.options.left.toInt();
        this.picture    =     $(picture);
        this.relative   =     $(this.options.relative).setStyles({cursor:'move'}).scrollTo(-this.left, -this.top);
 this.parent(this.relative);
 this.__construct();
 },
 __construct	:    function(){
 if(Browser.Engine.trident) document.ondragstart = function (){return false;}; // IE fix
 },
 coordinates	: function(){
 this.getCoordinates	=	this.relative.getScroll();
 this.getSize		=	this.relative.getSize();
 this.width  		=   this.relative.getSize().x.toInt();
 this.height  		=   this.relative.getSize().y.toInt();
 this.left  			=   -this.getCoordinates.x.toInt();
 this.top    		=   -this.getCoordinates.y.toInt();
 },
 complete    :    function(){
 this.coordinates();
 this.fireEvent("done",[this.top,this.left,this.width,this.height]);
 }
});

The Usage

window.addEvent('load', function(){
	new Drag2Crop('pictureId', {
		relative 	: 	'relative',
		top			:	-30, // Start at top : -30
		left		:	-60, // Start at left : -60
        onStart		:    function(){
            this.picture.setStyles({opacity:0.5});
        },
        onDone      :    function(top,left){
            this.picture.setStyles({opacity:1});
			$('test').set('text', 'Top : ' + top + ' | Left : ' + left);
        }
    });
});

See Demo

GitHub Repository

Projet @ Mootools Forge

Events :

beforeStart : Executed before the Drag instance attaches the events. Receives the dragged element as an argument.

start : Executed when the user starts to drag (on mousedown). Receives the dragged element as an argument.

snap : Executed when the user has dragged past the snap option. Receives the dragged element as an argument.

drag : Executed on every step of the drag. Receives the dragged element and the event as arguments.

complete : Executed when the user completes the drag. Receives the dragged element and the event as arguments.

cancel : Executed when the user has cancelled the drag. Receives the dragged element as an argument.

top: (number) start drag at top value.

left: (number) start drag at left value.

done : Executed when the user completes the drag.Receives the values [Top, Left, Width, Height] of picture relative to the box

The thrilling potential of SixthSense technology

Smarty : {capture} to put code in your header page

If you are using Smarty to generate your templates, I strongly advice you to take advantage of the function: {capture}

This function is used to collect the output of the template between the tags {capture}{/capture} into a variable instead of displaying it.

Exemple  :

index.tpl

{capture name=header}
{literal}
<script type="text/javascript">
alert('Javascript in head');
</script>
{/literal}
{/capture}
<!-- Include Page Header using Smarty {include} -->
{include file="header.tpl"}
My index page content

header.tpl

<html>
<head>
<title>Page ttle</title>
{$smarty.capture.header}
</head>

Nb : “Javascript code” must be placed between {literal}{/literal}

SDK Iphone pour windows et linux

La moindre des choses qu’on puisse dire sur la politique d’Apple  concernant le développement des application destinées à Iphone et Ipod touch est “Meeeeeeeeeeerde”.

Apple tente de vendre un Mac pour tout curieux qui souhaite personnaliser son mobile à la pomme, puisque son kit de développement XCODE (Iphone SDK) n’est disponible que pour son OSX (à partir de leopard 1.5.2 si je ne me trompe pas).

En gros, les utilisateurs de Linux et Windows sont ignorés par Apple, ce qui laisse deviner que la croissance positive des ventes d’Iphone a peut être une grande influence sur la vente des Macs.

Alternative PC :

Depuis la sortie des Mac Intel, certains bricoleurs ont déjà hackés OSX pour le faire tourner sur PC, idem pour “Snow Leopard”, il ne reste plus qu’a trouvé un bon tutoriel.

Alternative Linux :

On parle beaucoup de iphone-dev Toolchain, disponible pour plusieurs plateformes et qui permet de coder en Objective-C comme pour XCODE.
Plus d’infos sur : http://code.google.com/p/iphone-dev/wiki/Building [EN].
NB : malheureusement pour les utilisateurs de Windows “iphone-dev Toolchain est indisponible.

Alternative Windows :

Winchain : Un nom familier pour les Linuxiens, en faites c’est peut être une reprise de l’iphone-dev toolchain et qui a été peut être abandonner, à voir les commentaires de la partie HowToUse j’en doute que ca marche encore pour l’iphone OS 3.X mais bon il faut l’essayer avant.

DragonFireSDK (Payant) : Il vient de sortir, On dit que c’est un SDK pour Windows, mais en vérité (après un test en Bêta) c’est une dizaines de fonctions dite API, donc rien à voir avec le vrai SDK d’Iphone, la programmation se passe dans Microsoft Visual C ++, et après compilation, DragonFireSDK émule le code dans une fenêtre sous forme d’Iphone, au final vous devez uploader votre application sur http://dragonfiresdk.com/buildserver.htm qui convertira votre code en Application Iphone dans un de leurs serveurs MAC, la définition de DragonFireSDK serai donc : Intermédiaire entre Windows et le SDK d’iphone sous Mac

Malgré les alternatives, vous n’êtes pas le bienvenue dans l’App Store, à moins que vous disposez d’un Mac et d’une Apple ID.
Y a t’il une solution pour faire fonctionner Android sur mon Ipod Touch ?

Plesk : How to pointing domain to a subdirectory

First create your “subdirectory_name” then run terminal and edit httpd.include (vi, pico …):

pico /var/www/vhosts/domain.com/conf/httpd.include

Change every “/var/www/vhosts/domain.com/httpdocs
To “/var/www/vhosts/domain.com/httpdocs/subdirectory_name

Restart apache :

service httpd restart

This trick can be used to configure another domain to be pointing in another domaine : exemple

Change every “/var/www/vhosts/domain2.com/httpdocs
To “/var/www/vhosts/domain1.com/httpdocs

Mise à jour Snow Leopard 10.6.2 : Menus barre disparu

Pressé d’installer la mise à jour 10.6.2 de Snow Leopard, je me retrouve sans la barre de menus

Capture d’écran 2009-11-17 à 01.30.21

Une situation merdique mais bon, il fallait juste patienter quelques jours pour que d’autres partagent leurs expériences.

1 – Si vous utilisez Istats regardez par ici : http://forums.appleinsider.com/showthread.php?t=102462

2 – Si non (comme dans mon cas) ce billet est votre sauveur : http://www.mymacosx.com/tricks-and-tips/10-6-2-caused-empty-menu-bar-spotlight-icon-disabled.html

Capture d’écran 2009-11-17 à 02.22.27

Convertir window-1256 vers utf-8 VS 1and1 hosting rules

Il est très facile de convertir une chaîne d’un encodage à un autre sous PHP avec la fonction iconv()

$string = iconv("windows-1256", "UTF-8", $string);

Seulement, après avoir converti une base de donnée (40 mo) de window-1256 vers utf-8 le résultat donna une nouvelle base de plus de 90 mo.

Et quand on sait que le numéro 1 de l’hébergement dans le monde 1and1 limite l’utilisation d’une base de données MYSQL à 100 mo !

limitation_1and1_mysql

Marquee using mootools

I think that everyone has a love story with marquee, I remember my first html page in notepad with a lot of <Marquee>.

Today too, this tag still has the same charm, I love it.
I’ve made a little class using mootools to reborn my favorite html tag.

  • Easy to setup.
  • Stop “onmouseover”
  • Restart “onmouseout”

See demo

For this moment, this class support only “slide” from right to left, I’ll add direction option when I’ve finished some works.

Download script

UTF-8 and live.com (hotmail) issue

It is necessary to know first of all that: the problems with e-mails sent with UTF8 encoding  is not your, but that of the system of the addressee which does not manage correctly 8 bits,  as case of “Mail Subject” in “LIVE.com” (hotmail).

The solution is encoding the data of the message in MIME base64 :

Example :

mail($emailto,"=?UTF-8?B?".base64_encode($subject)."?=",$message,$headers);

My angry bird “Twits”

twitter

Angry bird invites to twitter, done rapidly on Photoshop.
Do you think following him ?

Download .PSD source

Page 1 of 212»