/** * Commonly used functions * based on jQuery * */ /** * Extends the jQuery element set to provide new methods (jQuery plugins) */ jQuery.fn.extend({ /** * Sets the attribute 'value' of a passed Object to the maximum result of a * passed function applied to all jQuery-objects * * Arguments: * - maxvar: object with attribute 'value' set to a start-value * - func: string, jQuery-function * * Usage (e.g.): * - this will set maxw.value to the maximum width of all div-elements: * // create an object and set its attribute 'value' to 0 * var maxw = new valueObject(0); * // set maxw.value * $('div').maxVal(maxw,'width()'); */ maxVal: function ( maxvar, func ) { return this.each(function() { maxvar.value = Math.max(maxvar.value, eval('$(this).'+func)); }); } }); /** * Creates an object and sets the attribute 'value' to a passed value * (to enable passing by pointer) * * Arguments: * - val: value */ function valueObject ( val ) { this.value = val; } /** * Sets the width of grouped HTML-elements to the maximum width of the elements * * Use this function e.g. to unify the width of labels in a form. * * Usage: * - in the HTML code * - group the elements to by unified by setting the class of a parent * element to 'f_unify' * - set the class of the elements to by unified to 'f_unify-width' * * E.g.: *
* - call adjust_unifyElements() */ function adjust_unifyElements () { var maxw = new valueObject(0); $('.f_unify .f_unify-width').maxVal(maxw,'width()').width(maxw.value); } /** * Initialise HTML elements to handle expansions * * Use this function if you want elements on the page to be shown/hidden * dynamically by the user on click. * * Usage: * An expansion-object consists of * - a container: encapsulating the object * - an expander (= the element to click) * - a body: the area to be hidden/shown * Expansion-objects can be nested * * - in the HTML code * - define the expansion container by setting the class to 'f_expandContainer' * - define the expander * - define the expander buttons (to click for expansion and reduction): * [ to maximise usability and accessibility, the contents for all expanders * must be defined in a seperate element with the class 'f_expansionElements' * and are inserted at the appropriate places at runtime (-> if javaScript is * disabled, the expansion-functionalities are not displayed in the code); * the element with the class 'f_expansionElements' will be removed from * the DOM at runtime ] * - inside the element with the class 'f_expansionElements' create an * element with the class 'SOME_CLASSNAME'; SOME_CLASSNAME should be * unique; the element will be referenced at runtime by SOME_CLASSNAME * and inserted at the appropriate places * - this element should have 2 div-childnodes with the classes set to * - 'f_expand' for the expansion-button and * - 'f_reduce' for the reduction-button respectively * - within those child-nodes define your "buttons" (preferably using * the a-tag) * - you can define variables in the HTML code of the buttons, which * will be replaced by some part of the content of the expansion * container at runtime (this is usefull if e.g. the title-attribute * has a value, dependant on the content; e.g. title="Open X" and X * is the title, shown in the head): * To insert an element: * - define an element with the class 'f_expandVar_SOMETHING' within * the button (this element will be replaced) * - set the class of the replacement element to * 'f_expandVarSet_SOMETHING' * To replace a value in the title or alt attribute: * - insert 'f_expandVar_SOMETHING' in the value * - set the class of the element, whos value should be used as # * replacement to 'f_expandVarSet_SOMETHING' * - define an expander placeholder: add an empty element with the classes * 'f_expander' and 'SOME_CLASSNAME' to your layout where the expander * should be; 'SOME_CLASSNAME' must be the last set class; the element * '.f_expansionElements SOME_CLASSNAME' will be inserted here at runtime * - define the body by setting the class to 'f_expandBody' * - if the body should be hidden on start, set its class to * 'f_expandStartClosed' * * E.g. * *