Alien-GvaScript

 view release on metacpan or  search on metacpan

doc/html/Form.html  view on Meta::CPAN


    </div>
  </div>
  <div class="TN_node" id="to_tree">
    <h3 class="TN_label">to_tree</h3>
    <div class="TN_content">
      <pre>  var tree = GvaScript.Form.to_tree(form);</pre>

<p>Inspects the contents of all fields in <code>form</code> and 
returns a data tree, were dotted names in form names
are expanded into sub-arrays or sub-hashes. So for example 
if the form looks like</p>
<pre>  &lt;input name="father.firstname"&gt; &lt;input name="father.lastname"&gt;&lt;br&gt;
  &lt;input name="mother.firstname"&gt; &lt;input name="mother.lastname"&gt;&lt;br&gt;
  &lt;div repeat="child" repeat-start="1"&gt;
    &lt;input name="#{child.path}.firstname"&gt;&lt;br&gt;
  &lt;/div&gt;</pre>

<p>and if that form has been expanded with 3 repetition blocks
for children, the resulting tree would be</p>
<pre>  { "father" : {"firstname" : ..., "lastname": ...},
    "mother" : {"firstname" : ..., "lastname": ...},
    "child"  : [ {"firstname": ...},
                 {"firstname": ...},
                 {"firstname": ...} ] }</pre>

<p>[<i>This method can be called either as an instance method or as a generic method. If calling as a generic, pass the form HTMLElement/id in as the first argument.</i>]</p>

    </div>

doc/html/ProtoExtensions.html  view on Meta::CPAN

  <a class="TN_label" href="#Events_delegation">Events delegation</a>
  <div class="TN_content"></div>
</div>
<div class="TN_leaf">
  <a class="TN_label" href="#Prototype_getJSON">Prototype.getJSON</a>
  <div class="TN_content"></div>
</div>
<div class="TN_node">
  <a class="TN_label" href="#Hash_utilities">Hash utilities</a>
  <div class="TN_content"><div class="TN_leaf">
  <a class="TN_label" href="#Hash_expand">Hash.expand</a>
  <div class="TN_content"></div>
</div>
<div class="TN_leaf">
  <a class="TN_label" href="#Hash_flatten">Hash.flatten</a>
  <div class="TN_content"></div>
</div>
</div>
</div>
<div class="TN_node">
  <a class="TN_label" href="#String_extensions">String extensions</a>

doc/html/ProtoExtensions.html  view on Meta::CPAN

      <pre>  Prototype.getJSON(url, callback)</pre>

<p>based on: getJSON function by Juriy Zaytsev <a href="http://github.com/kangax/protolicious/tree/master/get_json.js">http://github.com/kangax/protolicious/tree/master/get_json.js</a></p>
<p>A method to temporarily load JSON data (ideally hosted on a different domain and accessible via JSONP service) and send it over to callback method when ready.</p>

    </div>
  </div>
  <div class="TN_node" id="Hash_utilities">
    <h3 class="TN_label">Hash utilities</h3>
    <div class="TN_content">
        <div class="TN_node" id="Hash_expand">
    <h4 class="TN_label">Hash.expand</h4>
    <div class="TN_content">
      <pre>  var tree = Hash.expand(flat_hash);</pre>

<p>Transforms a flat structure of key-value pairs into a nested tree
structure, by splitting keys on dots.
The idea and algorithm come from <i>CGI::Expand/expand_hash</i>.</p>
<pre>  Hash.expand({a: '...', b.0.x: '...', b.0.y: '...', b.1.x: '...', b.1.y: '...'}) =&gt;
  {a: '...', b: [{x: '...', y: '...'}, {x: '...', y: '...'}]}</pre>


    </div>
  </div>
  <div class="TN_node" id="Hash_flatten">
    <h4 class="TN_label">Hash.flatten</h4>
    <div class="TN_content">
      <p>The exact opposite of Hash.expand</p>
<p>Transforms a nested tree structure into a flat hash of key-value pairs
where nested keys are joined by a dot.</p>

    </div>
  </div>

    </div>
  </div>
  <div class="TN_node" id="String_extensions">
    <h3 class="TN_label">String extensions</h3>

lib/Alien/GvaScript/Form.pod  view on Meta::CPAN

returns a flat hash of pairs (key-value).

[I<This method can be called either as an instance method or as a generic method. If calling as a generic, pass the form HTMLElement/id in as the first argument.>]

=head2 to_tree

  var tree = GvaScript.Form.to_tree(form);

Inspects the contents of all fields in C<form> and 
returns a data tree, were dotted names in form names
are expanded into sub-arrays or sub-hashes. So for example 
if the form looks like

  <input name="father.firstname"> <input name="father.lastname"><br>
  <input name="mother.firstname"> <input name="mother.lastname"><br>
  <div repeat="child" repeat-start="1">
    <input name="#{child.path}.firstname"><br>
  </div>

and if that form has been expanded with 3 repetition blocks
for children, the resulting tree would be

  { "father" : {"firstname" : ..., "lastname": ...},
    "mother" : {"firstname" : ..., "lastname": ...},
    "child"  : [ {"firstname": ...},
                 {"firstname": ...},
                 {"firstname": ...} ] }

[I<This method can be called either as an instance method or as a generic method. If calling as a generic, pass the form HTMLElement/id in as the first argument.>]

lib/Alien/GvaScript/ProtoExtensions.pod  view on Meta::CPAN


  Prototype.getJSON(url, callback)

based on: getJSON function by Juriy Zaytsev L<http://github.com/kangax/protolicious/tree/master/get_json.js>

A method to temporarily load JSON data (ideally hosted on a different domain and accessible via JSONP service) and send it over to callback method when ready.


=head2 Hash utilities

=head3 Hash.expand

  var tree = Hash.expand(flat_hash);

Transforms a flat structure of key-value pairs into a nested tree
structure, by splitting keys on dots.
The idea and algorithm come from L<CGI::Expand/expand_hash>.

  Hash.expand({a: '...', b.0.x: '...', b.0.y: '...', b.1.x: '...', b.1.y: '...'}) =>
  {a: '...', b: [{x: '...', y: '...'}, {x: '...', y: '...'}]}

=head3 Hash.flatten

The exact opposite of Hash.expand

Transforms a nested tree structure into a flat hash of key-value pairs
where nested keys are joined by a dot.

=head2 String extensions

=head3 chomp

Strips any trailing line breaks (\r\n) from a String.

lib/Alien/GvaScript/lib/GvaScript.js  view on Meta::CPAN

            this._IS_FLASHING = false;
        };

        element.addClassName(classname);
        setTimeout(endFlash.bind(element), duration);
    }
});

// utilities for hash

// expands flat hash into a multi-level deep hash
// javascript version of Perl  CGI::Expand::expand_hash
Hash.expand = function(flat_hash) {
  var tree = {};

  // iterate on keys in the flat hash
  for (var k in flat_hash) {
    var parts = k.split(/\./);
    var loop = {tree: tree, key: "root"};

    // iterate on path parts within the key
    for (var i = 0 ; i < parts.length; i++) {
      var part = parts[i];

lib/Alien/GvaScript/lib/GvaScript.js  view on Meta::CPAN


  to_hash: function(form) {
    form = $(form);

    return form.serialize({hash:true});
  },

  to_tree: function(form) {
    form = $(form);

    return Hash.expand(GvaScript.Form.to_hash(form));
  },

  fill_from_tree : (function() {

    var doc = document; // local variable is faster than global 'document'

    // IMPLEMENTATION NOTE : Form.Element.setValue() is quite similar,
    // but our treatment of arrays is different, so we have to reimplement
    var _fill_from_value = function(form, elem, val, is_init) {

src/form.js  view on Meta::CPAN


  to_hash: function(form) {
    form = $(form);

    return form.serialize({hash:true});
  },

  to_tree: function(form) {
    form = $(form);

    return Hash.expand(GvaScript.Form.to_hash(form));
  },

  fill_from_tree : (function() {

    var doc = document; // local variable is faster than global 'document'

    // IMPLEMENTATION NOTE : Form.Element.setValue() is quite similar,
    // but our treatment of arrays is different, so we have to reimplement
    var _fill_from_value = function(form, elem, val, is_init) {

src/protoExtensions.js  view on Meta::CPAN

            this._IS_FLASHING = false;
        };

        element.addClassName(classname);
        setTimeout(endFlash.bind(element), duration);
    }
});

// utilities for hash

// expands flat hash into a multi-level deep hash
// javascript version of Perl  CGI::Expand::expand_hash
Hash.expand = function(flat_hash) {
  var tree = {};

  // iterate on keys in the flat hash
  for (var k in flat_hash) {
    var parts = k.split(/\./);
    var loop = {tree: tree, key: "root"};

    // iterate on path parts within the key
    for (var i = 0 ; i < parts.length; i++) {
      var part = parts[i];

test/functional/form/effects.js  view on Meta::CPAN

        (effect.dims[0] - effect.element.clientHeight) + 'px' });
    },
    afterFinishInternal: function(effect) {
      effect.element.hide().undoClipping().undoPositioned();
      effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom});
    }
   }, arguments[1] || { })
  );
};

// Bug in opera makes the TD containing this element expand for a instance after finish 
Effect.Squish = function(element) {
  return new Effect.Scale(element, window.opera ? 1 : 0, { 
    restoreAfterFinish: true,
    beforeSetup: function(effect) {
      effect.element.makeClipping(); 
    },  
    afterFinishInternal: function(effect) {
      effect.element.hide().undoClipping(); 
    }
  });



( run in 0.571 second using v1.01-cache-2.11-cpan-5b529ec07f3 )