www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 55eb53e7d7d702ebf6732567c97bce167a6432fe
parent 2cc991a4757836cc65bef632b46ba3c65a3e990a
Author: gduperon <gduperon@5d9ba3ac-444b-4713-9fb3-0b58e79229a2>
Date:   Sun,  9 May 2010 18:17:26 +0000

Séparation des définitions des widgets dans plein de fichiers, nettoyage, etc.

git-svn-id: https://projetud.info-ufr.univ-montp2.fr/svn/flin607-2009-gduperon@37 5d9ba3ac-444b-4713-9fb3-0b58e79229a2

Diffstat:
Mjside2/index.html | 23+++++++++++++++++++----
Djside2/test.css | 119-------------------------------------------------------------------------------
Ajside2/theme.css | 11+++++++++++
Ajside2/tk/bloc.js | 13+++++++++++++
Ajside2/tk/boutons.js | 21+++++++++++++++++++++
Djside2/tk/box.js | 0
Ajside2/tk/conteneurs.js | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajside2/tk/exemple.js | 5+++++
Ajside2/tk/fenetre.js | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Ajside2/tk/html.js | 17+++++++++++++++++
Mjside2/tk/test.js | 25++++++++-----------------
Ajside2/tk/tk.css | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajside2/tk/tk.hack-options.js | 18++++++++++++++++++
Mjside2/tk/tk.js | 402+++++++++++++++++++++++--------------------------------------------------------
Djside2/tk/win.js | 0
15 files changed, 443 insertions(+), 424 deletions(-)

diff --git a/jside2/index.html b/jside2/index.html @@ -3,15 +3,17 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"> <head> <title>IDE</title> - <link rel="stylesheet" type="text/css" href="jquery/themes/custom-theme/jquery.ui.all.css" /> - <link rel="stylesheet" type="text/css" href="test.css" /> + <!-- jQuery --> <script type="text/javascript" src="jquery/jquery-1.4.2.js"></script> + <!-- jQuery Plugins --> <script type="text/javascript" src="jquery/jquery.scrollTo.js"></script> <script type="text/javascript" src="jquery/jquery.jqote2.js"></script> <script type="text/javascript" src="jquery/jquery.my.enumerable.js"></script> + <!-- jQuery UI --> + <link rel="stylesheet" type="text/css" href="jquery/themes/custom-theme/jquery.ui.all.css" /> <script type="text/javascript" src="jquery/ui/jquery.ui.core.js"></script> <script type="text/javascript" src="jquery/ui/jquery.ui.widget.js"></script> <script type="text/javascript" src="jquery/ui/jquery.ui.mouse.js"></script> @@ -23,10 +25,23 @@ <script type="text/javascript" src="jquery/ui/jquery.effects.core.js"></script> <script type="text/javascript" src="jquery/jquery.layout.js"></script> + <!-- jQuery - mes extensions --> <script type="text/javascript" src="extensions-jQuery.js"></script> + + <!-- Toolkit - coeur --> + <link rel="stylesheet" type="text/css" href="tk/tk.css" /> <script type="text/javascript" src="tk/tk.js"></script> - <script type="text/javascript" src="tk/win.js"></script> - <script type="text/javascript" src="tk/box.js"></script> + <link rel="stylesheet" type="text/css" href="theme.css" /> + + <!-- Toolkit - widgets --> + <script type="text/javascript" src="tk/bloc.js"></script> + <script type="text/javascript" src="tk/boutons.js"></script> + <script type="text/javascript" src="tk/conteneurs.js"></script> + <script type="text/javascript" src="tk/exemple.js"></script> + <script type="text/javascript" src="tk/fenetre.js"></script> + <script type="text/javascript" src="tk/html.js"></script> + + <!-- Test --> <script type="text/javascript" src="tk/test.js"></script> </head> <body> diff --git a/jside2/test.css b/jside2/test.css @@ -1,119 +0,0 @@ -#test-table-layout { - left: 100px; -} - -#test-ui-layout { - left: 400px; -} - -#test-js-layout { - left: 700px; -} - -#test-tk-widget { - left: 1000px; -} - -#test-table-layout .tk.contenu .tk.box { - height: 100%; -} - - -/* Positions */ - -.tk.window { - position: absolute ! important; - width: 200px; - height: 300px; - top:100px; -} - -.tk.titre { - text-align: center; -} - -.tk.contenu { - height: 100%; - text-align: center; -} - -.tk.pied { - text-align: center; -} - -.tk.box-table { - height: 100%; - width: 100%; - border-collapse: collapse; -} - -.tk.box-td { - padding: 0; -} - -/* hcontainer */ -.tk.hcontainer-table { - width: 100%; - border-collapse: collapse; -} - -.tk.hcontainer-td { - padding: 0; - width: 1px; -} - -.tk.hcontainer-td.auto-width { - width: auto; -} - -/* vcontainer */ -.tk.vcontainer-table { - height: 100%; - border-collapse: collapse; -} - -.tk.vcontainer-td { - padding: 0; -} - -.tk.vcontainer-tr { - height: 0px; -} - -.tk.vcontainer-tr.auto-height { - height: auto; -} - -/* bouton */ -.tk.bouton { - text-align: center; - border: thin solid gray; - font-weight: bold; -} - -.tk.bouton:hover { - color: blue; - border-color: black; - cursor: default; -} - -/* Couleurs */ - -.tk.window { - border: thin solid red; -} - -.tk.barre-titre { - background-color: lightgreen; - border: thin solid green; -} - -.tk.contenu .tk.box { - background-color: lightblue; - border: thin solid blue; -} - -.tk.pied .tk.box { - //background-color: lightgray; - //border: thin solid gray; -} diff --git a/jside2/theme.css b/jside2/theme.css @@ -0,0 +1,11 @@ +/* Couleurs */ + +.tk.window { + border: medium solid gray; + background-color: white; +} + +.tk.barre-titre { + background-color: lightgray; + border-bottom: thin solid gray; +} diff --git a/jside2/tk/bloc.js b/jside2/tk/bloc.js @@ -0,0 +1,12 @@ +(function($) { + widget(tk, { + bloc: function(_) { + _.options( + 'nom', 'Exemple', + 'description', "Un bloc d'exemple" + ); + + _.window(this.nom, this.description); + } + }); +})(jQuery); +\ No newline at end of file diff --git a/jside2/tk/boutons.js b/jside2/tk/boutons.js @@ -0,0 +1,20 @@ +(function($) { + widget(tk, { + bouton: function(_) { + _.options('class', ''); + _.div(_, this, _('rest')); + + _().square(); + }, + boutonReduire: function(_) { + _.options('class', ''); + this['class'] += ' tk bouton fermer'; + _.bouton(_, this,'-'); + }, + boutonFermer: function(_) { + _.options('class', ''); + this['class'] += ' tk bouton reduire'; + _.bouton(_, this,'×'); + } + }); +})(jQuery); +\ No newline at end of file diff --git a/jside2/tk/box.js b/jside2/tk/box.js diff --git a/jside2/tk/conteneurs.js b/jside2/tk/conteneurs.js @@ -0,0 +1,63 @@ +(function($) { + widget(tk, { + hcontainer: function(_) { + _.options( + 'class', '', + 'autoWidth', [] + ); + + _(this.autoWidth).addClass('auto-width'); + this['class'] += ' tk hcontainer-table'; + + _.table(_, this, + _.tr('tk hcontainer-tr', + _('rest').remap(_.hcontainerCell, 'tk hcontainer-td'))); + }, + hcontainerCell: function(_) { + _.options('class', ''); + + if (_('rest').is('.auto-width')) + this['class'] += ' auto-width'; + + _.td(_, this, _('rest')) + }, + vcontainer: function(_) { + _.options( + 'class', '', + 'autoHeight', [] + ); + + _(this.autoHeight).addClass('auto-height'); + this['class'] += ' tk vcontainer-table'; + + _.table(_, this, + _('rest').remap(_.vcontainerCell, 'tk vcontainer-tr')); + }, + vcontainerCell: function(_) { + _.options('class', ''); + + if (_('rest').is('.auto-height')) + this['class'] += ' auto-height'; + + _.tr(_, this, + _.td('tk vcontainer-td', + _('rest'))); + }, + box: function(_) { + _.options( + null, + 'hpos', false, + 'vpos', false + ); + + css = {}; + if (this.hpos) { css['text-align'] = this.hpos; } + if (this.vpos) { css['vertical-align'] = this.vpos; } + + _.table('tk box-table', + _.tr('tk box-tr', + _.td(_, {class: 'tk box-td box', css: css }, + _('rest')))); + } + }); +})(jQuery); +\ No newline at end of file diff --git a/jside2/tk/exemple.js b/jside2/tk/exemple.js @@ -0,0 +1,4 @@ +(function($) { + widget(tk, { + }); +})(jQuery); +\ No newline at end of file diff --git a/jside2/tk/fenetre.js b/jside2/tk/fenetre.js @@ -0,0 +1,51 @@ +(function($) { + widget(tk, { + window: function(_) { + _.options( + 'titre', 'Titre', + 'contenu', 'Contenu', + 'pied', '', + null, + 'width', 300, + 'height', 150, + 'canReduce', true, + 'canClose', true, + 'canDock', true + ); + + _.vcontainer('tk window', [1], + _.barreTitre(this.titre, this.canClose, this.canReduce), + _.div('tk contenu', _.box(this.contenu)), + _.div('tk pied', _.box(this.pied))) + + .width(this.width) + .height(this.height) + .draggable() + .resizable({ + resize: function(i,e) { + return $(this) + .trigger('sizeChange') + .find('*') + .trigger('sizeChange') + .trigger('posChange'); + } + }); + + if (!this.canClose) { + fermer.hide(); + } + }, + barreTitre: function(_) { + _.options( + 'titre', 'Titre', + 'canClose', true, + 'canReduce', true + ); + + _.hcontainer('tk barre-titre', [1], + fermer = _.boutonFermer('tk fermer'), + titre = _.div('tk titre', this.titre), + reduire = _.boutonReduire('tk reduire')); + }, + }); +})(jQuery); diff --git a/jside2/tk/html.js b/jside2/tk/html.js @@ -0,0 +1,16 @@ +(function($) { + var htmlElements = [ + 'div', 'span', + 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'tfoot', + ]; + + $.each(htmlElements, function(i, elem) { + widget(tk, elem, function(_) { + _.options( + 'class', '' + ); + + return $('<' + elem + '/>', this).append(_('rest')); + }); + }); +})(jQuery); +\ No newline at end of file diff --git a/jside2/tk/test.js b/jside2/tk/test.js @@ -1,20 +1,11 @@ $(function () { - $('#test-ui-layout').layout({ applyDefaultStyles: true }); - $('#test-ui-layout').children('.ui-layout-north').draggable(); + tk.bloc('Un bloc') + .attr('id', 'test-tk-widget') + .topY(200) + .appendTo('body'); - /*var container = - $('#test-js-layout'); - var total = (container) - .innerHeight(); - var minus = (container) - .children(':not(.auto-height)') - .invoke('outerHeight', true) - .sum(); - var nbshares = (container) - .children('.auto-height') - .size(); - - (container) - .children('.auto-height') - .height((total - minus) / nbshares);*/ + tk.bloc('Un bloc') + .attr('id', 'test-tk-widget') + .leftX(200) + .appendTo('body'); }); diff --git a/jside2/tk/tk.css b/jside2/tk/tk.css @@ -0,0 +1,98 @@ +#test-table-layout { + left: 100px; +} + +#test-ui-layout { + left: 400px; +} + +#test-js-layout { + left: 700px; +} + +#test-tk-widget { + left: 1000px; +} + +#test-table-layout .tk.contenu .tk.box { + height: 100%; +} + + +/* Positions */ + +.tk.window { + position: absolute ! important; + width: 200px; + height: 300px; + top:100px; +} + +.tk.titre { + text-align: center; +} + +.tk.contenu { + height: 100%; + text-align: center; +} + +.tk.pied { + text-align: center; +} + +.tk.box-table { + height: 100%; + width: 100%; + border-collapse: collapse; +} + +.tk.box-td { + padding: 0; +} + +/* hcontainer */ +.tk.hcontainer-table { + width: 100%; + border-collapse: collapse; +} + +.tk.hcontainer-td { + padding: 0; + width: 1px; +} + +.tk.hcontainer-td.auto-width { + width: auto; +} + +/* vcontainer */ +.tk.vcontainer-table { + height: 100%; + border-collapse: collapse; +} + +.tk.vcontainer-td { + padding: 0; +} + +.tk.vcontainer-tr { + height: 0px; +} + +.tk.vcontainer-tr.auto-height { + height: auto; +} + +/* bouton */ +.tk.bouton { + text-align: center; + border: thin solid gray; + font-weight: bold; +} + +.tk.bouton:hover { + color: blue; + border-color: black; + cursor: default; +} diff --git a/jside2/tk/tk.hack-options.js b/jside2/tk/tk.hack-options.js @@ -0,0 +1,18 @@ +// Hack pour récupérer les options +/*var options; + +var hackOptions = { + options: function(opts) { + args = []; + for (i = 0; i < arguments.length; i++) + args.push(arguments[i]); + throw { hackOptions: args }; + } +}; +try { + def(hackOptions); +} catch (e) { + if ('hackOptions' in e) { options = e.hackOptions; } + else { throw e; } +}*/ +// Fin hack options. diff --git a/jside2/tk/tk.js b/jside2/tk/tk.js @@ -1,86 +1,112 @@ -// Hack pour récupérer les options -/*var options; +/* API : + * widget(définitions); // Renvoie une nouvelle famille avec plusieurs widgets + * widget(nom, définition); // Renvoie une nouvelle famille avec un seul widget + * widget(Famille, définitions); // Ajoute les widgets à la famille et la renvoie + * widget(Famille, nom, définition); // Ajoute un widget à la famille et la renvoie + * + * ******************************* + * * /!\ Attention /!\ * + * * Les formes 2 et 3 modifient * + * * la famille d'origine !!!! * + * ******************************* + * + * Famille := un objet renvoyé par widget(…). + * + * définitions := { + * définition0, + * définition1, + * …, + * définitionN + * } + * + * défintion := + * nomWidget1: function(_) { + * _.options( + * 'monOption', 'valeur par défaut 1', // option positionnelle 1 + * 'truc', 'valeur par défaut 2', // option positionnelle 2 + * 'etc', 'valeur par défaut n', // option positionnelle n + * null, // ou false + * 'uneOption', 'valeur par défaut A', // option nommée uneOption + * 'uneAutre', 'valeur par défaut B', // option nommée uneAutre + * ); + * // Chaque widget doit renvoyer un élément, créé par ex. avec $('<div/>'), + * // ou avec un autre widget. + * return _.autreWidget('Titre', 'Blabla', // On params positionnels de autreWidget + * // Mettre _ juste avant le hash d'options nommées. + * _.encoreUnAutreWidget(_, {sonOptionNommée: 3, sonTrucPositionnel: 5}), + * $("<div>un élément</div>"), + * // _('rest') contient le reste des options + * _('rest')); + * } + * + */ -var hackOptions = { - options: function(opts) { - args = []; - for (i = 0; i < arguments.length; i++) - args.push(arguments[i]); - throw { hackOptions: args }; - } -}; -try { - def(hackOptions); -} catch (e) { - if ('hackOptions' in e) { options = e.hackOptions; } - else { throw e; } -}*/ -// Fin hack options. - -/* Création du hash des options et +tk = {}; + +(function($) { + /* Création du hash des options et * du tableau des options positionnelles. */ -function makeOptionsHash(defpos) { - var positions = []; - var defauts = {}; - var positionnel = true; - - for (var i = 0; i < defpos.length; i += 2) { - var k = defpos[i]; - var v = defpos[i+1]; + function makeOptionsHash(defpos) { + var positions = []; + var defauts = {}; + var positionnel = true; - if (k === false || k === null) { - positionnel = false; - i--; // ne pas prendre la valeur - continue; + for (var i = 0; i < defpos.length; i += 2) { + var k = defpos[i]; + var v = defpos[i+1]; + + if (k === false || k === null) { + positionnel = false; + i--; // ne pas prendre la valeur + continue; + } + + if (positionnel) + positions.push(k); + + defauts[k] = v; } - if (positionnel) - positions.push(k); - - defauts[k] = v; + return { + positions: positions, + defauts: defauts + }; } - - return { - positions: positions, - defauts: defauts - }; -} -function _options(h, defpos) { - var defposhash = makeOptionsHash(defpos); - var positions = defposhash.positions; - var defauts = defposhash.defauts; - var params = {}; - var firstRest = 0; - - if (h.realArgs[0] && h.realArgs[0].singleton === h.singleton) { - // Hash de paramètres nommés dans realArgs[2] - params = h.realArgs[1]; - firstRest = 2; - } else { - // Paramètres positionnels - for (var i = 0; i < Math.min(h.realArgs.length, positions.length); i++) { - params[positions[i]] = h.realArgs[i]; + function _options(h, defpos) { + var defposhash = makeOptionsHash(defpos); + var positions = defposhash.positions; + var defauts = defposhash.defauts; + var params = {}; + var firstRest = 0; + + if (h.realArgs[0] && h.realArgs[0].singleton === h.singleton) { + // Hash de paramètres nommés dans realArgs[2] + params = h.realArgs[1]; + firstRest = 2; + } else { + // Paramètres positionnels + for (var i = 0; i < Math.min(h.realArgs.length, positions.length); i++) { + params[positions[i]] = h.realArgs[i]; + } + firstRest = i; } - firstRest = i; - } - - // Reste des arguments - for (var i = firstRest; i < h.realArgs.length; i++) { - elem = h.realArgs[i]; - if (elem === null || elem === false) { - continue; + + // Reste des arguments + for (var i = firstRest; i < h.realArgs.length; i++) { + elem = h.realArgs[i]; + if (elem === null || elem === false) { + continue; + } + if (typeof elem == "string") + elem = $('<span/>').text(elem); // $(document.createTextNode(elem)) ne marche pas + + h.rest = h.rest.add(elem); } - if (typeof elem == "string") - elem = $('<span/>').text(elem); // $(document.createTextNode(elem)) ne marche pas - h.rest = h.rest.add(elem); + $.extend(h.futurethis, defauts, params); } - - $.extend(h.futurethis, defauts, params); -} -(function() { var singleton = { ans: $() }; function _uscore(h, args) { @@ -127,217 +153,32 @@ function _options(h, defpos) { return ret; }; } -})() - -function _widget(famille, defs) { - $.each(defs, function(nom, def) { - __widget(famille, nom, def); - }); - - return famille; -} - -function paire(k,v) { - var r = {}; - r[k] = v; - return r; -} - -/* Usage : - * widget({définitions}); - * widget(nom, définition); - * widget(Famille, {définitions}); - * widget(Famille, nom, définition); - */ -function widget(a, b, c) { - var is_fn = (arguments[1] instanceof Function); - if (arguments.length == 1) return _widget({}, a); - if (arguments.length == 2) return _widget(is_fn ? {} : a, - is_fn ? paire(a,b) : b); - if (arguments.length == 3) return _widget(a, paire(b,c)); -} + function _widget(famille, defs) { + $.each(defs, function(nom, def) { + __widget(famille, nom, def); + }); + + return famille; + } -/* API : - * - * widget({ - * nomWidget1: function(_) { - * _.options( - * 'monOption', 'valeur par défaut 1', // option positionnelle 1 - * 'truc', 'valeur par défaut 2', // option positionnelle 2 - * 'etc', 'valeur par défaut n', // option positionnelle n - * null, // ou false - * 'uneOption', 'valeur par défaut A', // option nommée uneOption - * 'uneAutre', 'valeur par défaut B', // option nommée uneAutre - * ); - * // Chaque widget doit renvoyer un élément, créé par ex. avec $('<div/>'), - * // ou avec un autre widget. - * return _.autreWidget('Titre', 'Blabla', // On params positionnels de autreWidget - * // Mettre _ juste avant le hash d'options nommées. - * _.encoreUnAutreWidget(_, {sonOptionNommée: 3, sonTrucPositionnel: 5}), - * $("<div>un élément</div>"), - * // _('rest') contient le reste des options - * _('rest')); - * }, - * autreWidget: function(_) { - * ... - * } - * }); - * - */ + function paire(k,v) { + var r = {}; + r[k] = v; + return r; + } -(function ($) { - var w = widget({ - bloc: function(_) { - _.options( - 'nom', 'Exemple', - 'description', "Un bloc d'exemple" - ); - - _.window(this.nom, this.description); - }, - boutonReduire: function(_) { - _.options('class', ''); - this['class'] += ' tk bouton fermer'; - _.square(_, this,'-'); - }, - boutonFermer: function(_) { - _.options('class', ''); - this['class'] += ' tk bouton reduire'; - _.square(_, this,'×'); - }, - barreTitre: function(_) { - _.options( - 'titre', 'Titre', - 'canClose', true, - 'canReduce', true - ); - - _.hcontainer('tk barre-titre', [1], - fermer = _.boutonFermer('tk fermer'), - titre = _.div('tk titre', this.titre), - reduire = _.boutonReduire('tk reduire')); - }, - window: function(_) { - _.options( - 'titre', 'Titre', - 'contenu', 'Contenu', - 'pied', '', - null, - 'width', 300, - 'height', 150, - 'canReduce', true, - 'canClose', true, - 'canDock', true - ); - - _.vcontainer('tk window', [1], - _.barreTitre(this.titre, this.canClose, this.canReduce), - _.div('tk contenu', _.box(this.contenu)), - _.div('tk pied', _.box(this.pied))) - - .width(this.width) - .height(this.height) - .draggable() - .resizable({ - resize: function(i,e) { - return $(this) - .trigger('sizeChange') - .find('*') - .trigger('sizeChange') - .trigger('posChange'); - } - }); - - if (!this.canClose) { - fermer.hide(); - } - }, - square: function(_) { - _.options('class', ''); - _.div(_, this, _('rest')); + function fn_widget(a, b, c) { + var is_fn = (arguments[1] instanceof Function); + + if (arguments.length == 1) return _widget({}, a); + if (arguments.length == 2) return _widget(is_fn ? {} : a, + is_fn ? paire(a,b) : b); + if (arguments.length == 3) return _widget(a, paire(b,c)); + } - _().square(); - }, - hcontainer: function(_) { - _.options( - 'class', '', - 'autoWidth', [] - ); - - _(this.autoWidth).addClass('auto-width'); - this['class'] += ' tk hcontainer-table'; - - _.table(_, this, - _.tr('tk hcontainer-tr', - _('rest').remap(_.hcontainerCell, 'tk hcontainer-td'))); - }, - hcontainerCell: function(_) { - _.options('class', ''); - - if (_('rest').is('.auto-width')) - this['class'] += ' auto-width'; - - _.td(_, this, _('rest')) - }, - vcontainer: function(_) { - _.options( - 'class', '', - 'autoHeight', [] - ); - - _(this.autoHeight).addClass('auto-height'); - this['class'] += ' tk vcontainer-table'; - - _.table(_, this, - _('rest').remap(_.vcontainerCell, 'tk vcontainer-tr')); - }, - vcontainerCell: function(_) { - _.options('class', ''); - - if (_('rest').is('.auto-height')) - this['class'] += ' auto-height'; - - _.tr(_, this, - _.td('tk vcontainer-td', - _('rest'))); - }, - box: function(_) { - _.options( - null, - 'hpos', false, - 'vpos', false - ); - - css = {}; - if (this.hpos) { css['text-align'] = this.hpos; } - if (this.vpos) { css['vertical-align'] = this.vpos; } - - _.table('tk box-table', - _.tr('tk box-tr', - _.td(_, {class: 'tk box-td box', css: css }, - _('rest')))); - } - }); - - var htmlElements = [ - 'div', 'span', - 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'tfoot', - ]; - - $.each(htmlElements, function(i, elem) { - widget(w, elem, function(_) { - _.options( - 'class', '' - ); - - return $('<' + elem + '/>', this).append(_('rest')); - }); - }); - - tk = w; + widget = fn_widget; })(jQuery); - jQuery.fn.extend({ autoWidth: function() { @@ -391,10 +232,3 @@ jQuery.fn.extend({ return this; } }); - -$(function () { - tk.bloc('Un bloc') - .attr('id', 'test-tk-widget') - .appendTo('body'); -// .autoHeight(); -}); diff --git a/jside2/tk/win.js b/jside2/tk/win.js