Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3760 connectés 

 


 Mot :   Pseudo :  
  Aller à la page :
 
 Page :   1  2  3  4  5  ..  991  992  993  ..  1454  1455  1456  1457  1458  1459
Auteur Sujet :

blabla@web

n°2009886
ratibus
Posté le 19-07-2010 à 09:52:19  profilanswer
 

Reprise du message précédent :

0x90 a écrit :

Dans un vrai langage j'aurais fournit une fonction de comparaison, en php ils ont :

Citation :

The optional second parameter sort_flags may be used to modify the sorting behavior using these values:
Sorting type flags:
   SORT_REGULAR - compare items normally (don't change types)
   SORT_NUMERIC - compare items numerically
   SORT_STRING - compare items as strings
   SORT_LOCALE_STRING - compare items as strings, based on the current locale. Added in PHP 4.4.0 and 5.0.2, it uses the system locale, which can be changed using setlocale().

[:-arnadul-]


C'est usort pour la fonction de tri avec méthode custom ;)


---------------
Mon blog
mood
Publicité
Posté le 19-07-2010 à 09:52:19  profilanswer
 

n°2009906
flo850
moi je
Posté le 19-07-2010 à 10:29:59  profilanswer
 

et on peut meme créer la fonction de tri dynamiquement avec create_function :o

n°2009927
gatsu35
Blablaté par Harko
Posté le 19-07-2010 à 10:58:49  profilanswer
 

ratibus a écrit :


C'est usort pour la fonction de tri avec méthode custom ;)


C'est la puissance du PHP, 10 fonctions pour au final un même résultat.


---------------
Blablaté par Harko
n°2009947
masklinn
í dag viðrar vel til loftárása
Posté le 19-07-2010 à 11:58:43  profilanswer
 

ratibus a écrit :


C'est usort pour la fonction de tri avec méthode custom ;)


That's the point.


Message édité par masklinn le 19-07-2010 à 11:59:09

---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
n°2009948
Dj YeLL
$question = $to_be || !$to_be;
Posté le 19-07-2010 à 12:00:22  profilanswer
 

On peut rien en faire de usort (enfin de uasort, pour garder les clés).
 
Faut une fonction custom qui s'occupe de tri de A à Z ama)


---------------
Gamertag: CoteBlack YeLL
n°2009949
0x90
Posté le 19-07-2010 à 12:01:37  profilanswer
 

ratibus a écrit :


C'est usort pour la fonction de tri avec méthode custom ;)


 
Et y'a aussi uasort [:pingouino] sacré php  [:gigaloool]


---------------
Me: Django Localization, Yogo Puzzle, Chrome Grapher, C++ Signals, Brainf*ck.
n°2009951
masklinn
í dag viðrar vel til loftárása
Posté le 19-07-2010 à 12:04:16  profilanswer
 

0x90 a écrit :

 

Et y'a aussi uasort [:pingouino] sacré php  [:gigaloool]


Et uksort :o

 

sort, rsort, usort, asort, arsort, uasort, ksort, krsort, uksort, natsort, natcasesort et array_multisort [:jar jar]

Message cité 1 fois
Message édité par masklinn le 19-07-2010 à 12:05:43

---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
n°2009969
Dj YeLL
$question = $to_be || !$to_be;
Posté le 19-07-2010 à 13:06:20  profilanswer
 

C'est beau :love:
 
En plus, le gros avantage, c'est que rien qu'en lisant le nom de la fonction on devine à quoi elle sert [:dawa]


---------------
Gamertag: CoteBlack YeLL
n°2009974
theredled
● REC
Posté le 19-07-2010 à 13:21:30  profilanswer
 

Un bon plugin JS de scrollbar redessinnée (mootools de préf), ça existe ? Avec molette prise en compte, curseur proportionnel etc...

 

Ou faut que jle fasse :o

Message cité 2 fois
Message édité par theredled le 19-07-2010 à 13:22:10

---------------
Contes de fées en yaourt --- --- zed, souviens-toi de ma dernière lettre. --- Rate ta musique
n°2009980
Dj YeLL
$question = $to_be || !$to_be;
Posté le 19-07-2010 à 13:37:13  profilanswer
 

Ptin ça me casse les couilles tous les sites qui affichent les commentaires à un article en chronologie descendante :/


---------------
Gamertag: CoteBlack YeLL
mood
Publicité
Posté le 19-07-2010 à 13:37:13  profilanswer
 

n°2009990
flo850
moi je
Posté le 19-07-2010 à 13:58:00  profilanswer
 

masklinn a écrit :


Et uksort :o
 
sort, rsort, usort, asort, arsort, uasort, ksort, krsort, uksort, natsort, natcasesort et array_multisort [:jar jar]


celle là est immonde a utiliser :d

n°2010015
masklinn
í dag viðrar vel til loftárása
Posté le 19-07-2010 à 14:27:31  profilanswer
 

N'empêche, chuis impressionné que les devs PHP aient crée 3 fonctions différentes pour chaque type de sort et se soient jamais dit "tiens si on y collait deux paramètres optionnels, sur nos sorts, un pour un sort inversé et un autre pour un callback?"

 

Notons également la cohérence typiquement PHP: arsort mais uasort [:implosion du tibia]


Message édité par masklinn le 19-07-2010 à 14:30:52

---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
n°2010020
Dj YeLL
$question = $to_be || !$to_be;
Posté le 19-07-2010 à 14:29:15  profilanswer
 

Pis pourquoi les sort d'array modifient l'array d'origine ? :o Je trouve ça totalement con :o

Message cité 1 fois
Message édité par Dj YeLL le 19-07-2010 à 14:29:21

---------------
Gamertag: CoteBlack YeLL
n°2010047
Shinuza
This is unexecpected
Posté le 19-07-2010 à 15:01:38  profilanswer
 

gatsu35 a écrit :


Autrement dit ta vue représente le dataset ?

Non, j'ai pas vraiment de dataset coté client, j'utilise le html comme une vue.
J'ai très peu de logique coté vue, uniquement des choses qui concernent la vue, j'ai bien call & refresh pour les applis communicantes, c'est plus facile à gerer que d'avoir à stocker de données coté client. Plus secure aussi j'imagine, surtout si on a tendance à stocker tout ça dans un objet accessible à l'introspection. Bon après faut quand même être con pour imaginer que les données qui viennent de la vue (coté client) sont fiables.

 

Also je teste un truc avec MooTools (extrait de code)

Code :
  1. Product = new Class({
  2.    'Implements' : [Events],
  3.    'initialize' : function(base, callback) {
  4.        this.base = $(base).store('instance', this);
  5.        this.id = base.getProperty('id');
  6.        this.uniq = base.getData('uniq');
  7.  
  8.        this.quantity = this.base.getElement('.quantity span');
  9.        this.price = this.base.getElement('.price span');
  10.        this.button = this.base.getElement('img');
  11.    },
  12.    'getQuantity' : function() {
  13.        return this.quantity.get('html').toInt();
  14.    },
  15.    'setQuantity' : function(num) {
  16.        this.quantity.set('html', num);
  17.    }
  18. });

J'ai un id unique par Product, depuis mes retours JSON je sais retrouver l'élément qui a déclencher l'event sans le passer en paramètre à n functions.
Ensuite

Code :
  1. $('monidunique').retrieve('instance');


me renvoit l'instance de Product qui correspond à cet élément.

 

L'avantage de faire ça c'est que j'ai pas à balader une référence à l'element dans tous les coins, et que le lookup id est le plus rapide qui existe en DOM.

 
theredled a écrit :

Un bon plugin JS de scrollbar redessinnée (mootools de préf), ça existe ? Avec molette prise en compte, curseur proportionnel etc...

 

Ou faut que jle fasse :o

0x90 en a fait un, mais il manque le jump to position (ça a été pété par quelqu'un qui a repris le code apparement).
J'ai le code, avec sa permission j'peux le poster ici :o (Mootools)

Message cité 2 fois
Message édité par Shinuza le 19-07-2010 à 15:03:27

---------------
Mains power can kill, and it will hurt the entire time you’re dying from it.
n°2010048
masklinn
í dag viðrar vel til loftárása
Posté le 19-07-2010 à 15:02:43  profilanswer
 

Dj YeLL a écrit :

Pis pourquoi les sort d'array modifient l'array d'origine ? :o Je trouve ça totalement con :o


C'est un choix, aussi discutable qu'il soit, et il peut probablement être défendu en parlant d'efficacité toussa (quoi, PHP? Ah OK, il peut pas alors :o)
 
Python a le même problème: list.sort() est en place (par contre sorted(list) non [:hahaguy]).
 
Ruby a les deux: Array#sort renvoie une version triée de l'array, et Array#sort! trie en place

Message cité 1 fois
Message édité par masklinn le 19-07-2010 à 15:03:40

---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
n°2010050
0x90
Posté le 19-07-2010 à 15:06:55  profilanswer
 

Shinuza a écrit :

0x90 en a fait un, mais il manque le jump to position (ça a été pété par quelqu'un qui a repris le code apparement).
J'ai le code, avec sa permission j'peux le poster ici :o (Mootools)


 
Of course :jap:


---------------
Me: Django Localization, Yogo Puzzle, Chrome Grapher, C++ Signals, Brainf*ck.
n°2010055
theredled
● REC
Posté le 19-07-2010 à 15:17:06  profilanswer
 


Dac, tu fais une séparation des couches quand même mais à ta guise, sans les contraintes d'indépendance habituelles du MVC.
 
Moi je vais voir dans le concret, là je peux pas argumenter pour ou contre sans avoir mis les mains dedans :o
 

Shinuza a écrit :

0x90 en a fait un, mais il manque le jump to position (ça a été pété par quelqu'un qui a repris le code apparement).
J'ai le code, avec sa permission j'peux le poster ici :o (Mootools)


 [:mossieurpropre]  

0x90 a écrit :


 
Of course :jap:


 [:mossieurpropre]  [:mossieurpropre]

Message cité 1 fois
Message édité par theredled le 19-07-2010 à 15:17:51

---------------
Contes de fées en yaourt --- --- zed, souviens-toi de ma dernière lettre. --- Rate ta musique
n°2010076
Shinuza
This is unexecpected
Posté le 19-07-2010 à 15:39:21  profilanswer
 

masklinn a écrit :


C'est un choix, aussi discutable qu'il soit, et il peut probablement être défendu en parlant d'efficacité toussa (quoi, PHP? Ah OK, il peut pas alors :o)

 

Python a le même problème: list.sort() est en place (par contre sorted(list) non [:hahaguy]).

 

Ruby a les deux: Array#sort renvoie une version triée de l'array, et Array#sort! trie en place

Javascript aussi fait le sort in-place (mais renvoit le nouvel array). Suffit de faire arr.splice(0, arr.length) pour voir une copie :o

0x90 a écrit :

 

Of course :jap:


:D

 


Code :
  1. /*
  2. Class: Button
  3.     Wrap an element with events and classes for creating a button.
  4.     The button support autoRepeat (with configurable speed and delay),toggle states and radio button groups.
  5.     The element gain a 'pressed' class when pressed, an 'active' class when active and a 'disabled' class when
  6.     disabled. Each of these classes can have a suffix specified through options.
  7.     Events are thrown by the button object AND by the element.
  8.     Toggle buttons can be set in an inconsistent state with setInconstent, you'll have an 'inconsistent'
  9.     class to be able to style it.
  10.  
  11. Syntax:
  12.     > new Button(element, [options]);
  13.     or:
  14.     > $(element).makeButton([options]);
  15.  
  16. Options:
  17.     repeat: boolean, enable repeated onPress event, defaults to false.
  18.     repeatDelay: the delay in ms before onPress events are repeated, defaults to 300ms.
  19.     repeatInterval: the interval in ms between each onPress events, defaults to 50ms.
  20.     toggle: boolean, enable toggle states and events, defaults to false.
  21.     toggleGroup: array of buttons or buttonized elements to deactivate when this is activated (radio buttons), defaults to [].
  22.     allowNone: boolean, allow deactivating the current element when used as radio buttons, defaults to false.
  23.     classSuffix: string, suffix appended to all the class added to the element, defaults to ''.
  24.  
  25. Events:
  26.     onPress:
  27.         When the button is pressed, this event is repeated if the repeat option is set to true.
  28.     onRelease:
  29.         When the button isn't pressed anymore.
  30.     onActivate:
  31.         When the button is clicked (press and release with mouse over the button, or scripted activation).
  32.     onDeactivate:
  33.         When the button is deactivated (only toggle buttons).
  34.     onEnable:
  35.         When the button is enabled (sensitive to click).
  36.     onDisable:
  37.         When the button is disabled (insensitive to click).
  38.  
  39. */
  40. Button = new Class({    
  41.     options: {
  42.         repeat: false,
  43.         repeatDelay: 300,
  44.         repeatInterval: 50,
  45.         toggle: false,
  46.         toggleGroup: null,
  47.         classSuffix: 'Button'
  48.     },
  49.     initialize: function(element, options) {
  50.         this.setOptions(options);
  51.         this.element = $(element);
  52.         this.element.$tmp.button = this;
  53.         ['disable', 'enable', 'activate', 'deactivate', 'setInconsistent'].each(
  54.             function(name) {
  55.                 this.element[name] = function() {
  56.                     return this[name].apply(this, arguments).element;
  57.                 }.bind(this);
  58.             },
  59.             this
  60.         );
  61.         this.element.addEvent(
  62.             'mousedown',
  63.             this.mousedown.bindWithEvent(this)
  64.         );
  65.         this.element.addEvent(
  66.             'click',
  67.             this.click.bindWithEvent(this)
  68.         );
  69.         this.bound = {
  70.             mouseup: this.mouseup.bindWithEvent(this),
  71.             mouseleave: this.mouseleave.bind(this),
  72.             mouseenter: this.mouseenter.bind(this)
  73.         };
  74.         this.enabled = true;
  75.         if(this.options.toggle) {
  76.             this.inconsistent = false;
  77.             this.active = false;
  78.             if(!this.options.toggleGroup) {
  79.                 this.options.toggleGroup = [];
  80.             }
  81.             this.options.toggleGroup.push(this);
  82.         }
  83.         this.clickable = false;
  84.     },
  85.     mouseleave: function(event) {
  86.         if(event)
  87.             new Event(event).stop();
  88.         this.element.removeClass('pressed' + this.options.classSuffix);
  89.         this.clickable = false;
  90.     },
  91.     mouseenter: function(event) {
  92.         if(event)
  93.             new Event(event).stop();
  94.         this.element.addClass('pressed' + this.options.classSuffix);
  95.         this.clickable = true;
  96.     },
  97.     mousedown: function(event) {
  98.         if(event)
  99.             new Event(event).stop();
  100.         if(this.enabled) {
  101.             this.fireEvent('onPress');
  102.             this.element.fireEvent('onPress');
  103.             if(this.options.repeat) {
  104.                 this.timer = this.startRepeat.delay(
  105.                     this.options.repeatDelay,
  106.                     this
  107.                 );
  108.             }
  109.             this.element.addClass('pressed' + this.options.classSuffix);
  110.             this.allowReleaseClick();
  111.             this.clickable = true;
  112.             // not very elegant antiselection hack
  113.             document.ondragstart = function() {
  114.                 return false;
  115.             };
  116.         }
  117.     },
  118.     mouseup: function(event) {
  119.         if(event)
  120.             new Event(event).stop();
  121.         document.removeEvent(
  122.             'mouseup',
  123.             this.bound.mouseup
  124.         );
  125.         $clear(this.timer);
  126.         if(this.enabled) {
  127.             this.fireEvent('onRelease');
  128.             this.element.fireEvent('onRelease');
  129.             this.element.removeEvent(
  130.                 'mouseenter',
  131.                 this.bound.mouseenter
  132.             ).removeEvent(
  133.                 'mouseleave',
  134.                 this.bound.mouseleave
  135.             ).removeClass('pressed' + this.options.classSuffix);
  136.             if(this.clickable) {
  137.                 if(!this.active) {
  138.                     this.activate();        
  139.                 }
  140.                 else if(this.options.allowNone || this.options.toggleGroup.length <= 1) {
  141.                     this.deactivate();
  142.                 }
  143.             }
  144.         }
  145.         this.clickable = false;
  146.     },
  147.     allowReleaseClick: function() {
  148.         if(this.enabled) {
  149.             document.addEvent(
  150.                 'mouseup',
  151.                 this.bound.mouseup
  152.             );
  153.             this.element.addEvent(
  154.                 'mouseleave',
  155.                 this.bound.mouseleave
  156.             ).addEvent(
  157.                 'mouseenter',
  158.                 this.bound.mouseenter
  159.             );
  160.         }
  161.     },
  162.     click: function(event) {
  163.         if(event)
  164.             new Event(event).stop();
  165.     },
  166.     activate: function() {
  167.         if(this.options.toggle) {
  168.             if(!this.active) {
  169.                 this.active = true;
  170.                 this.element.addClass('active' + this.options.classSuffix);
  171.                 this.options.toggleGroup.each(
  172.                     function(item) {
  173.                         if(item != this.element && item != this && $type(item.deactivate) == 'function') {
  174.                             item.deactivate();
  175.                         }
  176.                     }.bind(this)
  177.                 );
  178.                 this.inconsistent = false;
  179.                 this.element.removeClass('inconsistent' + this.options.classSuffix);
  180.                 this.fireEvent('onActivate');
  181.                 this.element.fireEvent('onActivate');
  182.             }
  183.         }
  184.         else {
  185.             this.fireEvent('onActivate');
  186.             this.element.fireEvent('onActivate');
  187.         }
  188.         return this;
  189.     },
  190.     deactivate: function() {
  191.         if(this.options.toggle && (this.active || this.inconsistent)) {
  192.             this.inconsistent = false;
  193.             this.active = false;
  194.             this.element.removeClass('inconsistent' + this.options.classSuffix);
  195.             this.element.removeClass('active' + this.options.classSuffix);
  196.             this.fireEvent('onDeactivate');
  197.             this.element.fireEvent('onDeactivate');
  198.         }
  199.         return this;
  200.     },
  201.     setInconsistent: function() {
  202.         if(this.options.toggle && !this.inconsistent) {
  203.             this.active = false;
  204.             this.inconsistent = true;
  205.             this.element.removeClass('active' + this.options.classSuffix);
  206.             this.element.addClass('inconsistent' + this.options.classSuffix);
  207.             this.fireEvent('onInconsistent');
  208.             this.element.fireEvent('onInconsistent');
  209.         }
  210.         return this;
  211.     },
  212.     enable: function() {
  213.         if(!this.enabled) {
  214.             this.enabled = true;
  215.             this.element.removeClass('disabled' + this.options.classSuffix);
  216.             this.fireEvent('onEnable');
  217.             this.element.fireEvent('onEnable');
  218.         }
  219.         return this;
  220.     },
  221.     disable: function() {
  222.         if(this.enabled) {
  223.             this.enabled = false;
  224.             this.element.addClass('disabled' + this.options.classSuffix);
  225.             this.fireEvent('onDisable');
  226.             this.element.fireEvent('onDisable');
  227.         }
  228.         return this;
  229.     },
  230.     startRepeat: function() {
  231.         this.timer = function() {
  232.             this.fireEvent('onPress');
  233.             this.element.fireEvent('onPress');
  234.         }.periodical(
  235.             this.options.repeatInterval,
  236.             this
  237.         );
  238.     }
  239.  
  240. });
  241. Button.implement(new Events, new Options);
  242. Element.extend({
  243.     makeButton: function(options) {
  244.         new Button(this, options);
  245.         return this;
  246.     }
  247. });
  248.  
  249.  
  250. Scrollable = new Class({
  251.     options:{
  252.         repeatDelay: 300,
  253.         repeatInterval: 20,
  254.         scrollStep: 50,
  255.         fastRatio: 3,
  256.         thumbMinHeight: 14,
  257.         clipTargets: []
  258.     },
  259.  
  260.     initialize:function(element, options) {
  261.         this.element = $(element);
  262.         this.setOptions(options);
  263.         this.install(this.element);
  264.         this.targetHeight = Infinity;
  265.         this.minHeight = 0;
  266.     },
  267.  
  268.     install: function(element) {
  269.         var styles = element.getStyles(
  270.             'borderColor',
  271.             'borderWidth',
  272.             'borderStyle',
  273.             'backgroundColor',
  274.             'backgroundImage',
  275.             'backgroundPosition',
  276.             'backgroundRepeat'
  277.         );
  278.         /* Fix a bug in mootools/IE where backgroundPosition is undefined */
  279.         styles.backgroundPosition = $pick(
  280.             styles.backgroundPosition,
  281.             "0 0"
  282.         );
  283.         element.setStyles("overflow:hidden;border:none;background:none" );
  284.         this.wrapper = new Element(
  285.             'div',
  286.             {
  287.                 'styles': $extend(
  288.                     styles,
  289.                     {
  290.                         zoom: 1
  291.                     }
  292.                 ),
  293.                 'class': 'scrollWrapper'
  294.             }
  295.         ).injectAfter(element).adopt(element);
  296.         this.scrollbar = new Element(
  297.             'div',
  298.             {
  299.                 'class': 'scrollbar',
  300.                 'styles': {
  301.                     'float': 'right'
  302.                 }
  303.             }
  304.         ).injectTop(this.wrapper);
  305.         this.wrapper.addEvent(
  306.             'mousewheel',
  307.             function(event) {
  308.                 event = new Event(event);
  309.                 if((this.canScrollUp && event.wheel > 0) || (this.canScrollDown && event.wheel < 0)) {
  310.                     event.stop();
  311.                     this.scrollBy(this.options.scrollStep * -event.wheel);
  312.                 }
  313.             }.bind(this)
  314.         );
  315.         this.parts = {
  316.             upButton: new Button(
  317.                 new Element(
  318.                     'div',
  319.                     {
  320.                         'class':'scrollUpButton'
  321.                     }
  322.                 ).inject(this.scrollbar),
  323.                 {
  324.                     repeat:true,
  325.                     repeatDelay:300,
  326.                     repeatInterval:50
  327.                 }
  328.             ).addEvent(
  329.                 'onPress',
  330.                 this.scrollBy.bind(
  331.                     this,
  332.                     [-this.options.scrollStep]
  333.                 )
  334.             ),
  335.             scrollBackground: new Element(
  336.                 'div',
  337.                 {
  338.                     'class': 'scrollBackground',
  339.                     'styles': {
  340.                         position:'relative'
  341.                     }
  342.                 }
  343.             ).inject(this.scrollbar).addEvent(
  344.                 'mousedown',
  345.                 function(event) {
  346.                     event = new Event(event);
  347.                     var position = Math.floor(event.page.y - this.parts.scrollBackground.getTop() - this.parts.scrollThumb.element.offsetHeight / 2);
  348.                     position = Math.min(
  349.                         position,
  350.                         this.parts.scrollBackground.offsetHeight - this.parts.scrollThumb.element.offsetHeight
  351.                     );
  352.                     this.parts.scrollThumb.element.setStyle(
  353.                         'top',
  354.                         Math.max(
  355.                             0,
  356.                             position
  357.                         )
  358.                     );
  359.                     this.drag.fireEvent(
  360.                         'onDrag',
  361.                         this.parts.scrollThumb.element,
  362.                         true
  363.                     );
  364.                     this.drag.start(event);
  365.                 }.bind(this)
  366.             )
  367.         };
  368.         this.parts.scrollThumb = new Button(
  369.             new Element(
  370.                 'div',
  371.                 {
  372.                     'class': 'scrollThumb',
  373.                     'styles': {
  374.                         position: 'relative'
  375.                     }
  376.                 }
  377.             ).inject(this.parts.scrollBackground)
  378.         );
  379.         this.parts.scrollThumbInner = new Element(
  380.             'div',
  381.             {
  382.                 'class': 'scrollThumbInner'
  383.             }
  384.         ).inject(this.parts.scrollThumb.element);
  385.         this.parts.downButton = new Button(
  386.             new Element(
  387.                 'div',
  388.                 {
  389.                     'class': 'scrollDownButton'
  390.                 }
  391.             ).inject(this.scrollbar),
  392.             {
  393.                 repeat: true,
  394.                 repeatDelay: 300,
  395.                 repeatInterval: 50
  396.             }
  397.         ).addEvent(
  398.             'onPress',
  399.             this.scrollBy.bind(
  400.                 this,
  401.                 [
  402.                     this.options.scrollStep
  403.                 ]
  404.             )
  405.         );
  406.         this.drag = new Drag.Move(
  407.             this.parts.scrollThumb.element,
  408.             {
  409.                 container: this.parts.scrollBackground,
  410.                 onDrag: function(el, animated) {
  411.                     var offset = el.offsetTop;
  412.                     var buttonsHeight = this.parts.upButton.element.offsetHeight + this.parts.downButton.element.offsetHeight;
  413.                     var scrollbarHeight = this.wrapper.offsetHeight - buttonsHeight;
  414.                     this.scrollTo(
  415.                         Math.round(offset / scrollbarHeight * element.scrollHeight),
  416.                         animated ? false : true
  417.                     );
  418.                 }.bind(this)
  419.             }
  420.         );
  421.         element.setHeight = this.setHeight.bind(this);
  422.         this.scrollFx = new Fx.Scroll(
  423.             element,
  424.             {
  425.                 wait:false,
  426.                 transition:Fx.Transitions.Sine.easeOut,
  427.                 duration:300
  428.             }
  429.         );
  430.         var boundUpdate = this.updateLayout.bind(this);
  431.         this.scrollFx.step = function(old) {
  432.             return function() {
  433.                 boundUpdate();
  434.                 old.apply(this, arguments);
  435.             };
  436.         }(this.scrollFx.step);
  437.         this.scrollTargetPos = element.scrollTop;
  438.         return this;
  439.     },
  440.  
  441.     freeze: function() {
  442.         this.freezed = true;
  443.     },
  444.  
  445.     thaw: function() {
  446.         this.freezed = false;
  447.         this.updateLayout();
  448.     },
  449.  
  450.   updateLayout:function() {
  451.         if (this.freezed)
  452.             return;
  453.         var newHeight = Math.max(
  454.             this.minHeight,
  455.             Math.min(
  456.                 this.targetHeight,
  457.                 this.element.scrollHeight
  458.             )
  459.         );
  460.         //this.element.setStyle('height', newHeight);
  461.         if (this.element.scrollHeight <= this.targetHeight || this.targetHeight == 0) {
  462.             this.element.scrollTop = 0;
  463.             this.wrapper.removeClass('scrolling');
  464.         } else {
  465.             this.wrapper.addClass('scrolling');
  466.             var buttonsHeight = this.parts.upButton.element.offsetHeight + this.parts.downButton.element.offsetHeight;
  467.             var scrollbarHeight = Math.max(
  468.                 0,
  469.                 this.element.offsetHeight - buttonsHeight - 1
  470.             );
  471.             this.parts.scrollBackground.setStyle(
  472.                 'height',
  473.                 scrollbarHeight
  474.             );
  475.             var thumbHeight = Math.round(
  476.                 Math.max(
  477.                     this.options.thumbMinHeight,
  478.                     scrollbarHeight * this.element.offsetHeight / this.element.scrollHeight
  479.                 )
  480.             );
  481.             var thumbOffset = Math.round(
  482.                 Math.max(
  483.                     0,
  484.                     scrollbarHeight * this.element.scrollTop / this.element.scrollHeight
  485.                 )
  486.             );
  487.             thumbOffset = Math.min(
  488.                 thumbOffset,
  489.                 scrollbarHeight - thumbHeight
  490.             );
  491.             this.parts.scrollThumb.element.setStyle(
  492.                 'height',
  493.                 thumbHeight
  494.             );
  495.             this.parts.scrollThumb.element.setStyle(
  496.                 'top',
  497.                 thumbOffset
  498.             );
  499.             this.canScrollUp = (thumbOffset != 0);
  500.             this.canScrollDown = (thumbOffset + thumbHeight != scrollbarHeight);
  501.             this.wrapper.setClassIf(
  502.                 'canScrollUp',
  503.                 this.canScrollUp
  504.             );
  505.             this.wrapper.setClassIf(
  506.                 'canScrollDown',
  507.                 this.canScrollDown
  508.             );
  509.         }
  510.         var clipRect = {
  511.             top: this.element.scrollTop,
  512.             left: this.element.scrollLeft,
  513.             height: this.targetHeight,
  514.             width: this.element.offsetWidth
  515.         };
  516.         this.options.clipTargets.each(
  517.             function(target) {
  518.                 target.setClipRect(clipRect);
  519.             }
  520.         );
  521.         return this;
  522.   },
  523.  
  524.     setHeight: function(height, noForce) {
  525.         if(!noForce) {
  526.             this.element.setStyle(
  527.                 'height',
  528.                 Math.max(
  529.                     0,
  530.                     height - this.element.getStyle('padding-top').toInt() - this.element.getStyle('padding-bottom').toInt()
  531.                 )
  532.             );
  533.         }
  534.         this.minHeight = this.element.getParent().offsetHeight;//65;
  535.         this.targetHeight = height;
  536.         this.updateLayout();
  537.         return this;
  538.     },
  539.  
  540.     scrollBy: function(amount) {
  541.         this.scrollTo(this.scrollTargetPos + amount);
  542.     },
  543.  
  544.     scrollTo: function(position) {
  545.         this.scrollTargetPos = Math.max(
  546.             0,
  547.             Math.min(
  548.                 this.element.scrollHeight - this.element.offsetHeight,
  549.                 position
  550.             )
  551.         );
  552.         this.element.scrollTop = this.scrollTargetPos;
  553.         this.updateLayout();
  554.     }
  555.  
  556. });
 

A lire le code c'est du 1.11, y'a un outils pour faire la conversion sur le site de MooTools.

 
theredled a écrit :


Dac, tu fais une séparation des couches quand même mais à ta guise, sans les contraintes d'indépendance habituelles du MVC.

 

Moi je vais voir dans le concret, là je peux pas argumenter pour ou contre sans avoir mis les mains dedans :o

Ouais j'évite de tout mélanger quand même. Sur pas mal d'aspects ça force à beaucoup réfléchir pour pondre une logique slim et simple coté "vue". Avant hier j'ai réglé un probleme qui m'a saoulé depuis presque une semaine en rajoutant une simple propriété json à mes objets :-/

 

Donc oui, c'est du MVC si on veut, mais pas intégralement coté client, je trouve ça inutile, le client reste une simple vue pour moi. C et M n'ont rien à y faire.

Message cité 4 fois
Message édité par Shinuza le 19-07-2010 à 15:47:09

---------------
Mains power can kill, and it will hurt the entire time you’re dying from it.
n°2010077
Shinuza
This is unexecpected
Posté le 19-07-2010 à 15:40:08  profilanswer
 

Y'a un gros bug dans mon message précédent :D


---------------
Mains power can kill, and it will hurt the entire time you’re dying from it.
n°2010080
koskoz
They see me trollin they hatin
Posté le 19-07-2010 à 15:41:39  profilanswer
 

Shinuza a écrit :

Javascript aussi fait le sort in-place (mais renvoit le nouvel array). Suffit de faire arr.splice(0, arr.length) pour voir une copie :o


 

Shinuza a écrit :


:D
 
 

Code :
  1. /*
  2. Class: Button
  3.     Wrap an element with events and classes for creating a button.
  4.     The button support autoRepeat (with configurable speed and delay),toggle states and radio button groups.
  5.     The element gain a 'pressed' class when pressed, an 'active' class when active and a 'disabled' class when
  6.     disabled. Each of these classes can have a suffix specified through options.
  7.     Events are thrown by the button object AND by the element.
  8.     Toggle buttons can be set in an inconsistent state with setInconstent, you'll have an 'inconsistent'
  9.     class to be able to style it.
  10.  
  11. Syntax:
  12.     > new Button(element, [options]);
  13.     or:
  14.     > $(element).makeButton([options]);
  15.  
  16. Options:
  17.     repeat: boolean, enable repeated onPress event, defaults to false.
  18.     repeatDelay: the delay in ms before onPress events are repeated, defaults to 300ms.
  19.     repeatInterval: the interval in ms between each onPress events, defaults to 50ms.
  20.     toggle: boolean, enable toggle states and events, defaults to false.
  21.     toggleGroup: array of buttons or buttonized elements to deactivate when this is activated (radio buttons), defaults to [].
  22.     allowNone: boolean, allow deactivating the current element when used as radio buttons, defaults to false.
  23.     classSuffix: string, suffix appended to all the class added to the element, defaults to ''.
  24.  
  25. Events:
  26.     onPress:
  27.         When the button is pressed, this event is repeated if the repeat option is set to true.
  28.     onRelease:
  29.         When the button isn't pressed anymore.
  30.     onActivate:
  31.         When the button is clicked (press and release with mouse over the button, or scripted activation).
  32.     onDeactivate:
  33.         When the button is deactivated (only toggle buttons).
  34.     onEnable:
  35.         When the button is enabled (sensitive to click).
  36.     onDisable:
  37.         When the button is disabled (insensitive to click).
  38.  
  39. */
  40. Button = new Class({    
  41.     options: {
  42.         repeat: false,
  43.         repeatDelay: 300,
  44.         repeatInterval: 50,
  45.         toggle: false,
  46.         toggleGroup: null,
  47.         classSuffix: 'Button'
  48.     },
  49.     initialize: function(element, options) {
  50.         this.setOptions(options);
  51.         this.element = $(element);
  52.         this.element.$tmp.button = this;
  53.         ['disable', 'enable', 'activate', 'deactivate', 'setInconsistent'].each(
  54.             function(name) {
  55.                 this.element[name] = function() {
  56.                     return this[name].apply(this, arguments).element;
  57.                 }.bind(this);
  58.             },
  59.             this
  60.         );
  61.         this.element.addEvent(
  62.             'mousedown',
  63.             this.mousedown.bindWithEvent(this)
  64.         );
  65.         this.element.addEvent(
  66.             'click',
  67.             this.click.bindWithEvent(this)
  68.         );
  69.         this.bound = {
  70.             mouseup: this.mouseup.bindWithEvent(this),
  71.             mouseleave: this.mouseleave.bind(this),
  72.             mouseenter: this.mouseenter.bind(this)
  73.         };
  74.         this.enabled = true;
  75.         if(this.options.toggle) {
  76.             this.inconsistent = false;
  77.             this.active = false;
  78.             if(!this.options.toggleGroup) {
  79.                 this.options.toggleGroup = [];
  80.             }
  81.             this.options.toggleGroup.push(this);
  82.         }
  83.         this.clickable = false;
  84.     },
  85.     mouseleave: function(event) {
  86.         if(event)
  87.             new Event(event).stop();
  88.         this.element.removeClass('pressed' + this.options.classSuffix);
  89.         this.clickable = false;
  90.     },
  91.     mouseenter: function(event) {
  92.         if(event)
  93.             new Event(event).stop();
  94.         this.element.addClass('pressed' + this.options.classSuffix);
  95.         this.clickable = true;
  96.     },
  97.     mousedown: function(event) {
  98.         if(event)
  99.             new Event(event).stop();
  100.         if(this.enabled) {
  101.             this.fireEvent('onPress');
  102.             this.element.fireEvent('onPress');
  103.             if(this.options.repeat) {
  104.                 this.timer = this.startRepeat.delay(
  105.                     this.options.repeatDelay,
  106.                     this
  107.                 );
  108.             }
  109.             this.element.addClass('pressed' + this.options.classSuffix);
  110.             this.allowReleaseClick();
  111.             this.clickable = true;
  112.             // not very elegant antiselection hack
  113.             document.ondragstart = function() {
  114.                 return false;
  115.             };
  116.         }
  117.     },
  118.     mouseup: function(event) {
  119.         if(event)
  120.             new Event(event).stop();
  121.         document.removeEvent(
  122.             'mouseup',
  123.             this.bound.mouseup
  124.         );
  125.         $clear(this.timer);
  126.         if(this.enabled) {
  127.             this.fireEvent('onRelease');
  128.             this.element.fireEvent('onRelease');
  129.             this.element.removeEvent(
  130.                 'mouseenter',
  131.                 this.bound.mouseenter
  132.             ).removeEvent(
  133.                 'mouseleave',
  134.                 this.bound.mouseleave
  135.             ).removeClass('pressed' + this.options.classSuffix);
  136.             if(this.clickable) {
  137.                 if(!this.active) {
  138.                     this.activate();        
  139.                 }
  140.                 else if(this.options.allowNone || this.options.toggleGroup.length <= 1) {
  141.                     this.deactivate();
  142.                 }
  143.             }
  144.         }
  145.         this.clickable = false;
  146.     },
  147.     allowReleaseClick: function() {
  148.         if(this.enabled) {
  149.             document.addEvent(
  150.                 'mouseup',
  151.                 this.bound.mouseup
  152.             );
  153.             this.element.addEvent(
  154.                 'mouseleave',
  155.                 this.bound.mouseleave
  156.             ).addEvent(
  157.                 'mouseenter',
  158.                 this.bound.mouseenter
  159.             );
  160.         }
  161.     },
  162.     click: function(event) {
  163.         if(event)
  164.             new Event(event).stop();
  165.     },
  166.     activate: function() {
  167.         if(this.options.toggle) {
  168.             if(!this.active) {
  169.                 this.active = true;
  170.                 this.element.addClass('active' + this.options.classSuffix);
  171.                 this.options.toggleGroup.each(
  172.                     function(item) {
  173.                         if(item != this.element && item != this && $type(item.deactivate) == 'function') {
  174.                             item.deactivate();
  175.                         }
  176.                     }.bind(this)
  177.                 );
  178.                 this.inconsistent = false;
  179.                 this.element.removeClass('inconsistent' + this.options.classSuffix);
  180.                 this.fireEvent('onActivate');
  181.                 this.element.fireEvent('onActivate');
  182.             }
  183.         }
  184.         else {
  185.             this.fireEvent('onActivate');
  186.             this.element.fireEvent('onActivate');
  187.         }
  188.         return this;
  189.     },
  190.     deactivate: function() {
  191.         if(this.options.toggle && (this.active || this.inconsistent)) {
  192.             this.inconsistent = false;
  193.             this.active = false;
  194.             this.element.removeClass('inconsistent' + this.options.classSuffix);
  195.             this.element.removeClass('active' + this.options.classSuffix);
  196.             this.fireEvent('onDeactivate');
  197.             this.element.fireEvent('onDeactivate');
  198.         }
  199.         return this;
  200.     },
  201.     setInconsistent: function() {
  202.         if(this.options.toggle && !this.inconsistent) {
  203.             this.active = false;
  204.             this.inconsistent = true;
  205.             this.element.removeClass('active' + this.options.classSuffix);
  206.             this.element.addClass('inconsistent' + this.options.classSuffix);
  207.             this.fireEvent('onInconsistent');
  208.             this.element.fireEvent('onInconsistent');
  209.         }
  210.         return this;
  211.     },
  212.     enable: function() {
  213.         if(!this.enabled) {
  214.             this.enabled = true;
  215.             this.element.removeClass('disabled' + this.options.classSuffix);
  216.             this.fireEvent('onEnable');
  217.             this.element.fireEvent('onEnable');
  218.         }
  219.         return this;
  220.     },
  221.     disable: function() {
  222.         if(this.enabled) {
  223.             this.enabled = false;
  224.             this.element.addClass('disabled' + this.options.classSuffix);
  225.             this.fireEvent('onDisable');
  226.             this.element.fireEvent('onDisable');
  227.         }
  228.         return this;
  229.     },
  230.     startRepeat: function() {
  231.         this.timer = function() {
  232.             this.fireEvent('onPress');
  233.             this.element.fireEvent('onPress');
  234.         }.periodical(
  235.             this.options.repeatInterval,
  236.             this
  237.         );
  238.     }
  239.  
  240. });
  241. Button.implement(new Events, new Options);
  242. Element.extend({
  243.     makeButton: function(options) {
  244.         new Button(this, options);
  245.         return this;
  246.     }
  247. });
  248.  
  249.  
  250. Scrollable = new Class({
  251.     options:{
  252.         repeatDelay: 300,
  253.         repeatInterval: 20,
  254.         scrollStep: 50,
  255.         fastRatio: 3,
  256.         thumbMinHeight: 14,
  257.         clipTargets: []
  258.     },
  259.  
  260.     initialize:function(element, options) {
  261.         this.element = $(element);
  262.         this.setOptions(options);
  263.         this.install(this.element);
  264.         this.targetHeight = Infinity;
  265.         this.minHeight = 0;
  266.     },
  267.  
  268.     install: function(element) {
  269.         var styles = element.getStyles(
  270.             'borderColor',
  271.             'borderWidth',
  272.             'borderStyle',
  273.             'backgroundColor',
  274.             'backgroundImage',
  275.             'backgroundPosition',
  276.             'backgroundRepeat'
  277.         );
  278.         /* Fix a bug in mootools/IE where backgroundPosition is undefined */
  279.         styles.backgroundPosition = $pick(
  280.             styles.backgroundPosition,
  281.             "0 0"
  282.         );
  283.         element.setStyles("overflow:hidden;border:none;background:none" );
  284.         this.wrapper = new Element(
  285.             'div',
  286.             {
  287.                 'styles': $extend(
  288.                     styles,
  289.                     {
  290.                         zoom: 1
  291.                     }
  292.                 ),
  293.                 'class': 'scrollWrapper'
  294.             }
  295.         ).injectAfter(element).adopt(element);
  296.         this.scrollbar = new Element(
  297.             'div',
  298.             {
  299.                 'class': 'scrollbar',
  300.                 'styles': {
  301.                     'float': 'right'
  302.                 }
  303.             }
  304.         ).injectTop(this.wrapper);
  305.         this.wrapper.addEvent(
  306.             'mousewheel',
  307.             function(event) {
  308.                 event = new Event(event);
  309.                 if((this.canScrollUp && event.wheel > 0) || (this.canScrollDown && event.wheel < 0)) {
  310.                     event.stop();
  311.                     this.scrollBy(this.options.scrollStep * -event.wheel);
  312.                 }
  313.             }.bind(this)
  314.         );
  315.         this.parts = {
  316.             upButton: new Button(
  317.                 new Element(
  318.                     'div',
  319.                     {
  320.                         'class':'scrollUpButton'
  321.                     }
  322.                 ).inject(this.scrollbar),
  323.                 {
  324.                     repeat:true,
  325.                     repeatDelay:300,
  326.                     repeatInterval:50
  327.                 }
  328.             ).addEvent(
  329.                 'onPress',
  330.                 this.scrollBy.bind(
  331.                     this,
  332.                     [-this.options.scrollStep]
  333.                 )
  334.             ),
  335.             scrollBackground: new Element(
  336.                 'div',
  337.                 {
  338.                     'class': 'scrollBackground',
  339.                     'styles': {
  340.                         position:'relative'
  341.                     }
  342.                 }
  343.             ).inject(this.scrollbar).addEvent(
  344.                 'mousedown',
  345.                 function(event) {
  346.                     event = new Event(event);
  347.                     var position = Math.floor(event.page.y - this.parts.scrollBackground.getTop() - this.parts.scrollThumb.element.offsetHeight / 2);
  348.                     position = Math.min(
  349.                         position,
  350.                         this.parts.scrollBackground.offsetHeight - this.parts.scrollThumb.element.offsetHeight
  351.                     );
  352.                     this.parts.scrollThumb.element.setStyle(
  353.                         'top',
  354.                         Math.max(
  355.                             0,
  356.                             position
  357.                         )
  358.                     );
  359.                     this.drag.fireEvent(
  360.                         'onDrag',
  361.                         this.parts.scrollThumb.element,
  362.                         true
  363.                     );
  364.                     this.drag.start(event);
  365.                 }.bind(this)
  366.             )
  367.         };
  368.         this.parts.scrollThumb = new Button(
  369.             new Element(
  370.                 'div',
  371.                 {
  372.                     'class': 'scrollThumb',
  373.                     'styles': {
  374.                         position: 'relative'
  375.                     }
  376.                 }
  377.             ).inject(this.parts.scrollBackground)
  378.         );
  379.         this.parts.scrollThumbInner = new Element(
  380.             'div',
  381.             {
  382.                 'class': 'scrollThumbInner'
  383.             }
  384.         ).inject(this.parts.scrollThumb.element);
  385.         this.parts.downButton = new Button(
  386.             new Element(
  387.                 'div',
  388.                 {
  389.                     'class': 'scrollDownButton'
  390.                 }
  391.             ).inject(this.scrollbar),
  392.             {
  393.                 repeat: true,
  394.                 repeatDelay: 300,
  395.                 repeatInterval: 50
  396.             }
  397.         ).addEvent(
  398.             'onPress',
  399.             this.scrollBy.bind(
  400.                 this,
  401.                 [
  402.                     this.options.scrollStep
  403.                 ]
  404.             )
  405.         );
  406.         this.drag = new Drag.Move(
  407.             this.parts.scrollThumb.element,
  408.             {
  409.                 container: this.parts.scrollBackground,
  410.                 onDrag: function(el, animated) {
  411.                     var offset = el.offsetTop;
  412.                     var buttonsHeight = this.parts.upButton.element.offsetHeight + this.parts.downButton.element.offsetHeight;
  413.                     var scrollbarHeight = this.wrapper.offsetHeight - buttonsHeight;
  414.                     this.scrollTo(
  415.                         Math.round(offset / scrollbarHeight * element.scrollHeight),
  416.                         animated ? false : true
  417.                     );
  418.                 }.bind(this)
  419.             }
  420.         );
  421.         element.setHeight = this.setHeight.bind(this);
  422.         this.scrollFx = new Fx.Scroll(
  423.             element,
  424.             {
  425.                 wait:false,
  426.                 transition:Fx.Transitions.Sine.easeOut,
  427.                 duration:300
  428.             }
  429.         );
  430.         var boundUpdate = this.updateLayout.bind(this);
  431.         this.scrollFx.step = function(old) {
  432.             return function() {
  433.                 boundUpdate();
  434.                 old.apply(this, arguments);
  435.             };
  436.         }(this.scrollFx.step);
  437.         this.scrollTargetPos = element.scrollTop;
  438.         return this;
  439.     },
  440.  
  441.     freeze: function() {
  442.         this.freezed = true;
  443.     },
  444.  
  445.     thaw: function() {
  446.         this.freezed = false;
  447.         this.updateLayout();
  448.     },
  449.  
  450.   updateLayout:function() {
  451.         if (this.freezed)
  452.             return;
  453.         var newHeight = Math.max(
  454.             this.minHeight,
  455.             Math.min(
  456.                 this.targetHeight,
  457.                 this.element.scrollHeight
  458.             )
  459.         );
  460.         //this.element.setStyle('height', newHeight);
  461.         if (this.element.scrollHeight <= this.targetHeight || this.targetHeight == 0) {
  462.             this.element.scrollTop = 0;
  463.             this.wrapper.removeClass('scrolling');
  464.         } else {
  465.             this.wrapper.addClass('scrolling');
  466.             var buttonsHeight = this.parts.upButton.element.offsetHeight + this.parts.downButton.element.offsetHeight;
  467.             var scrollbarHeight = Math.max(
  468.                 0,
  469.                 this.element.offsetHeight - buttonsHeight - 1
  470.             );
  471.             this.parts.scrollBackground.setStyle(
  472.                 'height',
  473.                 scrollbarHeight
  474.             );
  475.             var thumbHeight = Math.round(
  476.                 Math.max(
  477.                     this.options.thumbMinHeight,
  478.                     scrollbarHeight * this.element.offsetHeight / this.element.scrollHeight
  479.                 )
  480.             );
  481.             var thumbOffset = Math.round(
  482.                 Math.max(
  483.                     0,
  484.                     scrollbarHeight * this.element.scrollTop / this.element.scrollHeight
  485.                 )
  486.             );
  487.             thumbOffset = Math.min(
  488.                 thumbOffset,
  489.                 scrollbarHeight - thumbHeight
  490.             );
  491.             this.parts.scrollThumb.element.setStyle(
  492.                 'height',
  493.                 thumbHeight
  494.             );
  495.             this.parts.scrollThumb.element.setStyle(
  496.                 'top',
  497.                 thumbOffset
  498.             );
  499.             this.canScrollUp = (thumbOffset != 0);
  500.             this.canScrollDown = (thumbOffset + thumbHeight != scrollbarHeight);
  501.             this.wrapper.setClassIf(
  502.                 'canScrollUp',
  503.                 this.canScrollUp
  504.             );
  505.             this.wrapper.setClassIf(
  506.                 'canScrollDown',
  507.                 this.canScrollDown
  508.             );
  509.         }
  510.         var clipRect = {
  511.             top: this.element.scrollTop,
  512.             left: this.element.scrollLeft,
  513.             height: this.targetHeight,
  514.             width: this.element.offsetWidth
  515.         };
  516.         this.options.clipTargets.each(
  517.             function(target) {
  518.                 target.setClipRect(clipRect);
  519.             }
  520.         );
  521.         return this;
  522.   },
  523.  
  524.     setHeight: function(height, noForce) {
  525.         if(!noForce) {
  526.             this.element.setStyle(
  527.                 'height',
  528.                 Math.max(
  529.                     0,
  530.                     height - this.element.getStyle('padding-top').toInt() - this.element.getStyle('padding-bottom').toInt()
  531.                 )
  532.             );
  533.         }
  534.         this.minHeight = this.element.getParent().offsetHeight;//65;
  535.         this.targetHeight = height;
  536.         this.updateLayout();
  537.         return this;
  538.     },
  539.  
  540.     scrollBy: function(amount) {
  541.         this.scrollTo(this.scrollTargetPos + amount);
  542.     },
  543.  
  544.     scrollTo: function(position) {
  545.         this.scrollTargetPos = Math.max(
  546.             0,
  547.             Math.min(
  548.                 this.element.scrollHeight - this.element.offsetHeight,
  549.                 position
  550.             )
  551.         );
  552.         this.element.scrollTop = this.scrollTargetPos;
  553.         this.updateLayout();
  554.     }
  555.  
  556. });


 
A lire le code c'est du 1.11, y'a un outils pour faire la conversion sur le site de MooTools.
 


 

Shinuza a écrit :

Ouais j'évite de tout mélanger quand même. Sur pas mal d'aspect ça force à beaucoup réfléchir pour pondre une logique slim et simple coté "vue". Avant hier j'ai réglé un probleme qui m'a saoulé depuis presque une semaine en rajoutant une simple propriété json à mes objets :-/
 
Donc oui, c'est d'une MVC si on veut, mais pas intégralement coté client, je trouve ça inutile, le client reste une simple vue pour moi. C et M n'ont rien à y faire.


 
Moi aussi je veux jouer :o


---------------
Twitter
n°2010084
Shinuza
This is unexecpected
Posté le 19-07-2010 à 15:45:47  profilanswer
 

Spoiler + Code == fail


---------------
Mains power can kill, and it will hurt the entire time you’re dying from it.
n°2010087
masklinn
í dag viðrar vel til loftárása
Posté le 19-07-2010 à 15:51:32  profilanswer
 

Shinuza a écrit :

Javascript aussi fait le sort in-place (mais renvoit le nouvel array). Suffit de faire arr.splice(0, arr.length) pour voir une copie :o


.slice() :o
 
Mais reste qu'il te faut 2 appels pour avoir ton array trié (et encore, bol que sort() renvoie this):

Code :
  1. var b = a.slice().sort()


au lieu de juste

Code :
  1. b = a.sort


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
n°2010091
theredled
● REC
Posté le 19-07-2010 à 15:55:11  profilanswer
 


 

Shinuza a écrit :


Code :
  1. /*
  2. Class: Button
  3.     Wrap an element with events and classes for creating a button.
  4.     The button support autoRepeat (with configurable speed and delay),toggle states and radio button groups.
  5.     The element gain a 'pressed' class when pressed, an 'active' class when active and a 'disabled' class when
  6.     disabled. Each of these classes can have a suffix specified through options.
  7.     Events are thrown by the button object AND by the element.
  8.     Toggle buttons can be set in an inconsistent state with setInconstent, you'll have an 'inconsistent'
  9.     class to be able to style it.
  10.  
  11. Syntax:
  12.     > new Button(element, [options]);
  13.     or:
  14.     > $(element).makeButton([options]);
  15.  
  16. Options:
  17.     repeat: boolean, enable repeated onPress event, defaults to false.
  18.     repeatDelay: the delay in ms before onPress events are repeated, defaults to 300ms.
  19.     repeatInterval: the interval in ms between each onPress events, defaults to 50ms.
  20.     toggle: boolean, enable toggle states and events, defaults to false.
  21.     toggleGroup: array of buttons or buttonized elements to deactivate when this is activated (radio buttons), defaults to [].
  22.     allowNone: boolean, allow deactivating the current element when used as radio buttons, defaults to false.
  23.     classSuffix: string, suffix appended to all the class added to the element, defaults to ''.
  24.  
  25. Events:
  26.     onPress:
  27.         When the button is pressed, this event is repeated if the repeat option is set to true.
  28.     onRelease:
  29.         When the button isn't pressed anymore.
  30.     onActivate:
  31.         When the button is clicked (press and release with mouse over the button, or scripted activation).
  32.     onDeactivate:
  33.         When the button is deactivated (only toggle buttons).
  34.     onEnable:
  35.         When the button is enabled (sensitive to click).
  36.     onDisable:
  37.         When the button is disabled (insensitive to click).
  38.  
  39. */
  40. Button = new Class({    
  41.     options: {
  42.         repeat: false,
  43.         repeatDelay: 300,
  44.         repeatInterval: 50,
  45.         toggle: false,
  46.         toggleGroup: null,
  47.         classSuffix: 'Button'
  48.     },
  49.     initialize: function(element, options) {
  50.         this.setOptions(options);
  51.         this.element = $(element);
  52.         this.element.$tmp.button = this;
  53.         ['disable', 'enable', 'activate', 'deactivate', 'setInconsistent'].each(
  54.             function(name) {
  55.                 this.element[name] = function() {
  56.                     return this[name].apply(this, arguments).element;
  57.                 }.bind(this);
  58.             },
  59.             this
  60.         );
  61.         this.element.addEvent(
  62.             'mousedown',
  63.             this.mousedown.bindWithEvent(this)
  64.         );
  65.         this.element.addEvent(
  66.             'click',
  67.             this.click.bindWithEvent(this)
  68.         );
  69.         this.bound = {
  70.             mouseup: this.mouseup.bindWithEvent(this),
  71.             mouseleave: this.mouseleave.bind(this),
  72.             mouseenter: this.mouseenter.bind(this)
  73.         };
  74.         this.enabled = true;
  75.         if(this.options.toggle) {
  76.             this.inconsistent = false;
  77.             this.active = false;
  78.             if(!this.options.toggleGroup) {
  79.                 this.options.toggleGroup = [];
  80.             }
  81.             this.options.toggleGroup.push(this);
  82.         }
  83.         this.clickable = false;
  84.     },
  85.     mouseleave: function(event) {
  86.         if(event)
  87.             new Event(event).stop();
  88.         this.element.removeClass('pressed' + this.options.classSuffix);
  89.         this.clickable = false;
  90.     },
  91.     mouseenter: function(event) {
  92.         if(event)
  93.             new Event(event).stop();
  94.         this.element.addClass('pressed' + this.options.classSuffix);
  95.         this.clickable = true;
  96.     },
  97.     mousedown: function(event) {
  98.         if(event)
  99.             new Event(event).stop();
  100.         if(this.enabled) {
  101.             this.fireEvent('onPress');
  102.             this.element.fireEvent('onPress');
  103.             if(this.options.repeat) {
  104.                 this.timer = this.startRepeat.delay(
  105.                     this.options.repeatDelay,
  106.                     this
  107.                 );
  108.             }
  109.             this.element.addClass('pressed' + this.options.classSuffix);
  110.             this.allowReleaseClick();
  111.             this.clickable = true;
  112.             // not very elegant antiselection hack
  113.             document.ondragstart = function() {
  114.                 return false;
  115.             };
  116.         }
  117.     },
  118.     mouseup: function(event) {
  119.         if(event)
  120.             new Event(event).stop();
  121.         document.removeEvent(
  122.             'mouseup',
  123.             this.bound.mouseup
  124.         );
  125.         $clear(this.timer);
  126.         if(this.enabled) {
  127.             this.fireEvent('onRelease');
  128.             this.element.fireEvent('onRelease');
  129.             this.element.removeEvent(
  130.                 'mouseenter',
  131.                 this.bound.mouseenter
  132.             ).removeEvent(
  133.                 'mouseleave',
  134.                 this.bound.mouseleave
  135.             ).removeClass('pressed' + this.options.classSuffix);
  136.             if(this.clickable) {
  137.                 if(!this.active) {
  138.                     this.activate();        
  139.                 }
  140.                 else if(this.options.allowNone || this.options.toggleGroup.length <= 1) {
  141.                     this.deactivate();
  142.                 }
  143.             }
  144.         }
  145.         this.clickable = false;
  146.     },
  147.     allowReleaseClick: function() {
  148.         if(this.enabled) {
  149.             document.addEvent(
  150.                 'mouseup',
  151.                 this.bound.mouseup
  152.             );
  153.             this.element.addEvent(
  154.                 'mouseleave',
  155.                 this.bound.mouseleave
  156.             ).addEvent(
  157.                 'mouseenter',
  158.                 this.bound.mouseenter
  159.             );
  160.         }
  161.     },
  162.     click: function(event) {
  163.         if(event)
  164.             new Event(event).stop();
  165.     },
  166.     activate: function() {
  167.         if(this.options.toggle) {
  168.             if(!this.active) {
  169.                 this.active = true;
  170.                 this.element.addClass('active' + this.options.classSuffix);
  171.                 this.options.toggleGroup.each(
  172.                     function(item) {
  173.                         if(item != this.element && item != this && $type(item.deactivate) == 'function') {
  174.                             item.deactivate();
  175.                         }
  176.                     }.bind(this)
  177.                 );
  178.                 this.inconsistent = false;
  179.                 this.element.removeClass('inconsistent' + this.options.classSuffix);
  180.                 this.fireEvent('onActivate');
  181.                 this.element.fireEvent('onActivate');
  182.             }
  183.         }
  184.         else {
  185.             this.fireEvent('onActivate');
  186.             this.element.fireEvent('onActivate');
  187.         }
  188.         return this;
  189.     },
  190.     deactivate: function() {
  191.         if(this.options.toggle && (this.active || this.inconsistent)) {
  192.             this.inconsistent = false;
  193.             this.active = false;
  194.             this.element.removeClass('inconsistent' + this.options.classSuffix);
  195.             this.element.removeClass('active' + this.options.classSuffix);
  196.             this.fireEvent('onDeactivate');
  197.             this.element.fireEvent('onDeactivate');
  198.         }
  199.         return this;
  200.     },
  201.     setInconsistent: function() {
  202.         if(this.options.toggle && !this.inconsistent) {
  203.             this.active = false;
  204.             this.inconsistent = true;
  205.             this.element.removeClass('active' + this.options.classSuffix);
  206.             this.element.addClass('inconsistent' + this.options.classSuffix);
  207.             this.fireEvent('onInconsistent');
  208.             this.element.fireEvent('onInconsistent');
  209.         }
  210.         return this;
  211.     },
  212.     enable: function() {
  213.         if(!this.enabled) {
  214.             this.enabled = true;
  215.             this.element.removeClass('disabled' + this.options.classSuffix);
  216.             this.fireEvent('onEnable');
  217.             this.element.fireEvent('onEnable');
  218.         }
  219.         return this;
  220.     },
  221.     disable: function() {
  222.         if(this.enabled) {
  223.             this.enabled = false;
  224.             this.element.addClass('disabled' + this.options.classSuffix);
  225.             this.fireEvent('onDisable');
  226.             this.element.fireEvent('onDisable');
  227.         }
  228.         return this;
  229.     },
  230.     startRepeat: function() {
  231.         this.timer = function() {
  232.             this.fireEvent('onPress');
  233.             this.element.fireEvent('onPress');
  234.         }.periodical(
  235.             this.options.repeatInterval,
  236.             this
  237.         );
  238.     }
  239.  
  240. });
  241. Button.implement(new Events, new Options);
  242. Element.extend({
  243.     makeButton: function(options) {
  244.         new Button(this, options);
  245.         return this;
  246.     }
  247. });
  248.  
  249.  
  250. Scrollable = new Class({
  251.     options:{
  252.         repeatDelay: 300,
  253.         repeatInterval: 20,
  254.         scrollStep: 50,
  255.         fastRatio: 3,
  256.         thumbMinHeight: 14,
  257.         clipTargets: []
  258.     },
  259.  
  260.     initialize:function(element, options) {
  261.         this.element = $(element);
  262.         this.setOptions(options);
  263.         this.install(this.element);
  264.         this.targetHeight = Infinity;
  265.         this.minHeight = 0;
  266.     },
  267.  
  268.     install: function(element) {
  269.         var styles = element.getStyles(
  270.             'borderColor',
  271.             'borderWidth',
  272.             'borderStyle',
  273.             'backgroundColor',
  274.             'backgroundImage',
  275.             'backgroundPosition',
  276.             'backgroundRepeat'
  277.         );
  278.         /* Fix a bug in mootools/IE where backgroundPosition is undefined */
  279.         styles.backgroundPosition = $pick(
  280.             styles.backgroundPosition,
  281.             "0 0"
  282.         );
  283.         element.setStyles("overflow:hidden;border:none;background:none" );
  284.         this.wrapper = new Element(
  285.             'div',
  286.             {
  287.                 'styles': $extend(
  288.                     styles,
  289.                     {
  290.                         zoom: 1
  291.                     }
  292.                 ),
  293.                 'class': 'scrollWrapper'
  294.             }
  295.         ).injectAfter(element).adopt(element);
  296.         this.scrollbar = new Element(
  297.             'div',
  298.             {
  299.                 'class': 'scrollbar',
  300.                 'styles': {
  301.                     'float': 'right'
  302.                 }
  303.             }
  304.         ).injectTop(this.wrapper);
  305.         this.wrapper.addEvent(
  306.             'mousewheel',
  307.             function(event) {
  308.                 event = new Event(event);
  309.                 if((this.canScrollUp && event.wheel > 0) || (this.canScrollDown && event.wheel < 0)) {
  310.                     event.stop();
  311.                     this.scrollBy(this.options.scrollStep * -event.wheel);
  312.                 }
  313.             }.bind(this)
  314.         );
  315.         this.parts = {
  316.             upButton: new Button(
  317.                 new Element(
  318.                     'div',
  319.                     {
  320.                         'class':'scrollUpButton'
  321.                     }
  322.                 ).inject(this.scrollbar),
  323.                 {
  324.                     repeat:true,
  325.                     repeatDelay:300,
  326.                     repeatInterval:50
  327.                 }
  328.             ).addEvent(
  329.                 'onPress',
  330.                 this.scrollBy.bind(
  331.                     this,
  332.                     [-this.options.scrollStep]
  333.                 )
  334.             ),
  335.             scrollBackground: new Element(
  336.                 'div',
  337.                 {
  338.                     'class': 'scrollBackground',
  339.                     'styles': {
  340.                         position:'relative'
  341.                     }
  342.                 }
  343.             ).inject(this.scrollbar).addEvent(
  344.                 'mousedown',
  345.                 function(event) {
  346.                     event = new Event(event);
  347.                     var position = Math.floor(event.page.y - this.parts.scrollBackground.getTop() - this.parts.scrollThumb.element.offsetHeight / 2);
  348.                     position = Math.min(
  349.                         position,
  350.                         this.parts.scrollBackground.offsetHeight - this.parts.scrollThumb.element.offsetHeight
  351.                     );
  352.                     this.parts.scrollThumb.element.setStyle(
  353.                         'top',
  354.                         Math.max(
  355.                             0,
  356.                             position
  357.                         )
  358.                     );
  359.                     this.drag.fireEvent(
  360.                         'onDrag',
  361.                         this.parts.scrollThumb.element,
  362.                         true
  363.                     );
  364.                     this.drag.start(event);
  365.                 }.bind(this)
  366.             )
  367.         };
  368.         this.parts.scrollThumb = new Button(
  369.             new Element(
  370.                 'div',
  371.                 {
  372.                     'class': 'scrollThumb',
  373.                     'styles': {
  374.                         position: 'relative'
  375.                     }
  376.                 }
  377.             ).inject(this.parts.scrollBackground)
  378.         );
  379.         this.parts.scrollThumbInner = new Element(
  380.             'div',
  381.             {
  382.                 'class': 'scrollThumbInner'
  383.             }
  384.         ).inject(this.parts.scrollThumb.element);
  385.         this.parts.downButton = new Button(
  386.             new Element(
  387.                 'div',
  388.                 {
  389.                     'class': 'scrollDownButton'
  390.                 }
  391.             ).inject(this.scrollbar),
  392.             {
  393.                 repeat: true,
  394.                 repeatDelay: 300,
  395.                 repeatInterval: 50
  396.             }
  397.         ).addEvent(
  398.             'onPress',
  399.             this.scrollBy.bind(
  400.                 this,
  401.                 [
  402.                     this.options.scrollStep
  403.                 ]
  404.             )
  405.         );
  406.         this.drag = new Drag.Move(
  407.             this.parts.scrollThumb.element,
  408.             {
  409.                 container: this.parts.scrollBackground,
  410.                 onDrag: function(el, animated) {
  411.                     var offset = el.offsetTop;
  412.                     var buttonsHeight = this.parts.upButton.element.offsetHeight + this.parts.downButton.element.offsetHeight;
  413.                     var scrollbarHeight = this.wrapper.offsetHeight - buttonsHeight;
  414.                     this.scrollTo(
  415.                         Math.round(offset / scrollbarHeight * element.scrollHeight),
  416.                         animated ? false : true
  417.                     );
  418.                 }.bind(this)
  419.             }
  420.         );
  421.         element.setHeight = this.setHeight.bind(this);
  422.         this.scrollFx = new Fx.Scroll(
  423.             element,
  424.             {
  425.                 wait:false,
  426.                 transition:Fx.Transitions.Sine.easeOut,
  427.                 duration:300
  428.             }
  429.         );
  430.         var boundUpdate = this.updateLayout.bind(this);
  431.         this.scrollFx.step = function(old) {
  432.             return function() {
  433.                 boundUpdate();
  434.                 old.apply(this, arguments);
  435.             };
  436.         }(this.scrollFx.step);
  437.         this.scrollTargetPos = element.scrollTop;
  438.         return this;
  439.     },
  440.  
  441.     freeze: function() {
  442.         this.freezed = true;
  443.     },
  444.  
  445.     thaw: function() {
  446.         this.freezed = false;
  447.         this.updateLayout();
  448.     },
  449.  
  450.   updateLayout:function() {
  451.         if (this.freezed)
  452.             return;
  453.         var newHeight = Math.max(
  454.             this.minHeight,
  455.             Math.min(
  456.                 this.targetHeight,
  457.                 this.element.scrollHeight
  458.             )
  459.         );
  460.         //this.element.setStyle('height', newHeight);
  461.         if (this.element.scrollHeight <= this.targetHeight || this.targetHeight == 0) {
  462.             this.element.scrollTop = 0;
  463.             this.wrapper.removeClass('scrolling');
  464.         } else {
  465.             this.wrapper.addClass('scrolling');
  466.             var buttonsHeight = this.parts.upButton.element.offsetHeight + this.parts.downButton.element.offsetHeight;
  467.             var scrollbarHeight = Math.max(
  468.                 0,
  469.                 this.element.offsetHeight - buttonsHeight - 1
  470.             );
  471.             this.parts.scrollBackground.setStyle(
  472.                 'height',
  473.                 scrollbarHeight
  474.             );
  475.             var thumbHeight = Math.round(
  476.                 Math.max(
  477.                     this.options.thumbMinHeight,
  478.                     scrollbarHeight * this.element.offsetHeight / this.element.scrollHeight
  479.                 )
  480.             );
  481.             var thumbOffset = Math.round(
  482.                 Math.max(
  483.                     0,
  484.                     scrollbarHeight * this.element.scrollTop / this.element.scrollHeight
  485.                 )
  486.             );
  487.             thumbOffset = Math.min(
  488.                 thumbOffset,
  489.                 scrollbarHeight - thumbHeight
  490.             );
  491.             this.parts.scrollThumb.element.setStyle(
  492.                 'height',
  493.                 thumbHeight
  494.             );
  495.             this.parts.scrollThumb.element.setStyle(
  496.                 'top',
  497.                 thumbOffset
  498.             );
  499.             this.canScrollUp = (thumbOffset != 0);
  500.             this.canScrollDown = (thumbOffset + thumbHeight != scrollbarHeight);
  501.             this.wrapper.setClassIf(
  502.                 'canScrollUp',
  503.                 this.canScrollUp
  504.             );
  505.             this.wrapper.setClassIf(
  506.                 'canScrollDown',
  507.                 this.canScrollDown
  508.             );
  509.         }
  510.         var clipRect = {
  511.             top: this.element.scrollTop,
  512.             left: this.element.scrollLeft,
  513.             height: this.targetHeight,
  514.             width: this.element.offsetWidth
  515.         };
  516.         this.options.clipTargets.each(
  517.             function(target) {
  518.                 target.setClipRect(clipRect);
  519.             }
  520.         );
  521.         return this;
  522.   },
  523.  
  524.     setHeight: function(height, noForce) {
  525.         if(!noForce) {
  526.             this.element.setStyle(
  527.                 'height',
  528.                 Math.max(
  529.                     0,
  530.                     height - this.element.getStyle('padding-top').toInt() - this.element.getStyle('padding-bottom').toInt()
  531.                 )
  532.             );
  533.         }
  534.         this.minHeight = this.element.getParent().offsetHeight;//65;
  535.         this.targetHeight = height;
  536.         this.updateLayout();
  537.         return this;
  538.     },
  539.  
  540.     scrollBy: function(amount) {
  541.         this.scrollTo(this.scrollTargetPos + amount);
  542.     },
  543.  
  544.     scrollTo: function(position) {
  545.         this.scrollTargetPos = Math.max(
  546.             0,
  547.             Math.min(
  548.                 this.element.scrollHeight - this.element.offsetHeight,
  549.                 position
  550.             )
  551.         );
  552.         this.element.scrollTop = this.scrollTargetPos;
  553.         this.updateLayout();
  554.     }
  555.  
  556. });




Merci :o :o :o
 


---------------
Contes de fées en yaourt --- --- zed, souviens-toi de ma dernière lettre. --- Rate ta musique
n°2010151
theredled
● REC
Posté le 19-07-2010 à 18:04:34  profilanswer
 


Comment ça marche ? [:joce]
Je suis sous mootools 1.11, je fais "new Scrollable($$('.maclasse')[0]);" au domready et ça fait rien.

Message cité 2 fois
Message édité par theredled le 19-07-2010 à 18:04:46

---------------
Contes de fées en yaourt --- --- zed, souviens-toi de ma dernière lettre. --- Rate ta musique
n°2010163
Shinuza
This is unexecpected
Posté le 19-07-2010 à 18:51:57  profilanswer
 

masklinn a écrit :


.slice() :o
 
Mais reste qu'il te faut 2 appels pour avoir ton array trié (et encore, bol que sort() renvoie this):

Code :
  1. var b = a.slice().sort()


au lieu de juste

Code :
  1. b = a.sort


Je me disais "c'est slice pas splice" et j'écris splice [:prozac]
Ouais c'est tout pourri, t'es obligé de faire une copie quoi. C'est pas non plus la mort si c'est pas bas-niveau :D
 

theredled a écrit :


Comment ça marche ? [:joce]
Je suis sous mootools 1.11, je fais "new Scrollable($$('.maclasse')[0]);" au domready et ça fait rien.

Il manque p'tet un bout [:dawa]
Je regarde :o


---------------
Mains power can kill, and it will hurt the entire time you’re dying from it.
n°2010176
Skateinmar​s
Posté le 19-07-2010 à 20:40:25  profilanswer
 

theredled a écrit :

Un bon plugin JS de scrollbar redessinnée (mootools de préf), ça existe ? Avec molette prise en compte, curseur proportionnel etc...
 
Ou faut que jle fasse :o


 
http://www.kelvinluck.com/assets/j [...] lPane.html pour jquery


---------------
Feedback HAV
n°2010178
theredled
● REC
Posté le 19-07-2010 à 20:46:12  profilanswer
 


Pas mal, même si la molette est foireuse.


---------------
Contes de fées en yaourt --- --- zed, souviens-toi de ma dernière lettre. --- Rate ta musique
n°2010181
Skateinmar​s
Posté le 19-07-2010 à 21:28:08  profilanswer
 

theredled a écrit :


Pas mal, même si la molette est foireuse.


J'ai pas eu de soucis avec le plugin molette en plus  :??:


---------------
Feedback HAV
n°2010183
Dj YeLL
$question = $to_be || !$to_be;
Posté le 19-07-2010 à 21:34:19  profilanswer
 

Je crois que ça avait déjà été dis ici même, mais quand même, à chaque fois que je lis ça :
 

Citation :


more_entropy
If set to TRUE, uniqid() will add additional entropy (using the combined linear congruential generator) at the end of the return value, which should make the results more unique.


 
[:rofl]


---------------
Gamertag: CoteBlack YeLL
n°2010189
Dj YeLL
$question = $to_be || !$to_be;
Posté le 19-07-2010 à 22:10:16  profilanswer
 

Dites, je suis en train de dev la partie "connexion" des utilisateurs d'un site.
 
Habituellement, je stocke le username + password hash dans le cookie. Et quand l'user revient, j'utilise ces params pour le connecter.
 
Je ne trouve pas terrible d'avoir le pass hash directement dans le cookie.
 
Donc je fais différemment cette fois (d'autant qu'il faut vraiment que ce soit sécurisé compte tenu du type de site).
 
Donc à la connexion, si l'user s'est connecté avec succès, je génère un code unique, que je stocke dans une table "user_connection" qui contient l'ID de l'user et le code unique.
 
Comme ça, je ne stocke plus que ce code unique dans le cookie.
 
Par contre, pour éviter le vol de cookie, j'aimerais stocker en plus dans "user_connection", l'adresse IP du client.
 
Un commentaire ?


---------------
Gamertag: CoteBlack YeLL
n°2010198
theredled
● REC
Posté le 19-07-2010 à 22:35:28  profilanswer
 

Skateinmars a écrit :


J'ai pas eu de soucis avec le plugin molette en plus  :??:


Au trackpad en tout cas :
http://www.kelvinluck.com/assets/j [...] tions.html


---------------
Contes de fées en yaourt --- --- zed, souviens-toi de ma dernière lettre. --- Rate ta musique
n°2010203
Shinuza
This is unexecpected
Posté le 20-07-2010 à 00:05:16  profilanswer
 

theredled a écrit :


Comment ça marche ? [:joce]
Je suis sous mootools 1.11, je fais "new Scrollable($$('.maclasse')[0]);" au domready et ça fait rien.

J'ai pas eu le temps de tester, mais juste comme ça. Si tu fais new Scrollable(element).install()?


---------------
Mains power can kill, and it will hurt the entire time you’re dying from it.
n°2010204
theredled
● REC
Posté le 20-07-2010 à 00:10:17  profilanswer
 

Shinuza a écrit :

J'ai pas eu le temps de tester, mais juste comme ça. Si tu fais new Scrollable(element).install()?


Peut pas tester là, mais le initialize() inclue le install() de ce que j'ai vu.


---------------
Contes de fées en yaourt --- --- zed, souviens-toi de ma dernière lettre. --- Rate ta musique
n°2010205
Shinuza
This is unexecpected
Posté le 20-07-2010 à 00:15:07  profilanswer
 

Ah le con [:joce]
Ouais bon, je mate ça demain matin :o


---------------
Mains power can kill, and it will hurt the entire time you’re dying from it.
n°2010290
___alt
Posté le 20-07-2010 à 10:36:58  profilanswer
 

Dj YeLL a écrit :

Dites, je suis en train de dev la partie "connexion" des utilisateurs d'un site.

 

Habituellement, je stocke le username + password hash dans le cookie. Et quand l'user revient, j'utilise ces params pour le connecter.

 

Je ne trouve pas terrible d'avoir le pass hash directement dans le cookie.


Effectivement, c'est pas bien, même si en salant le hash et en utilisant un algo robuste c'est moins un problème.

 

Donc je fais différemment cette fois (d'autant qu'il faut vraiment que ce soit sécurisé compte tenu du type de site).

 
Dj YeLL a écrit :

Donc à la connexion, si l'user s'est connecté avec succès, je génère un code unique, que je stocke dans une table "user_connection" qui contient l'ID de l'user et le code unique.

 

Comme ça, je ne stocke plus que ce code unique dans le cookie.

 

Par contre, pour éviter le vol de cookie, j'aimerais stocker en plus dans "user_connection", l'adresse IP du client.

 

Un commentaire ?

 

Ça peut ajouter un léger plus, mais ça ne sera pas forcément suffisant.
Le plus important, c'est d'avoir un couple cookie persistant/token (ton code unique) qui ne dure pas des années : si la sécurité est vraiment un point critique, il ne devrait même pas y avoir persistance, i.e. dans un temps très court après la dernière action de l'utilisateur sur le site ou après fermeture du navigateur : poubelle.


Message édité par ___alt le 20-07-2010 à 10:37:46

---------------
TRIPS RIGHT BUNCH F SHUTTLE TOM AND JERRY RIGHT YELLOW
n°2010333
___alt
Posté le 20-07-2010 à 11:45:01  profilanswer
 

http://perishablepress.com/press/2 [...] -bad-bots/
 
Technique pour blacklister les bots qui ne respectent pas robots.txt


---------------
TRIPS RIGHT BUNCH F SHUTTLE TOM AND JERRY RIGHT YELLOW
n°2010351
Shinuza
This is unexecpected
Posté le 20-07-2010 à 12:14:46  profilanswer
 

http://imgur.com/zh4qk.png


---------------
Mains power can kill, and it will hurt the entire time you’re dying from it.
n°2010362
theredled
● REC
Posté le 20-07-2010 à 12:43:22  profilanswer
 

Le nommage en CSS, c'est encore plus dur qu'en dev normal, en fait :o


Message édité par theredled le 20-07-2010 à 12:43:34

---------------
Contes de fées en yaourt --- --- zed, souviens-toi de ma dernière lettre. --- Rate ta musique
mood
Publicité
Posté le   profilanswer
 

 Page :   1  2  3  4  5  ..  991  992  993  ..  1454  1455  1456  1457  1458  1459

Aller à :
Ajouter une réponse
 

Sujets relatifs
blabla 3blabla 2
PUTAIN HARKO TU AS FERM2 BLABLA ![Beaucoup de blabla pour rien : post à effacer] Compiler .bat
variable1="blabla + variable2 +blala : c'est possible ??[PHP & regex] "blabla blabla file.ext?point=444 blabla" Recupérer 444
mail("celine@hotmail.com"," sujet","blabla"); pose une err ! Help[MySQL] WHERE 'blabla' compris dans le champ truc
[blabla@olympe] Le topic du modo, dieu de la fibre et du monde[PHP / BlaBla - limite]
Plus de sujets relatifs à : blabla@web


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)