Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

testing

  • Loading branch information...
commit bcebea7d822ddbbb75aa38d9df5ad32d254295a0 1 parent 735be49
@gregory80 authored
Showing with 136 additions and 24 deletions.
  1. +65 −16 js/fraglet.js
  2. +8 −8 tests/test_fraglet.html
  3. +63 −0 tests/test_fraglet_2.html
View
81 js/fraglet.js
@@ -15,12 +15,43 @@
(function(global_frame) {
var fraglet,F,_F,__ns; // declare, don't set
+
+ /*
+ A single template, stored at __ns is an F object
+
+ Fraglet tracks the combination of all template
+ */
Fraglet=function() {
// essentially on script load
__ns={};
}
Fraglet.prototype = {
+
+ lnk : function( href, txt ) {
+ return {
+ 'type' : 'a',
+ 'attr' : {
+ 'href' : href
+ },
+ 'c' : txt || href
+ }
+ },
+ inpt : function( opts ) {
+ return [{
+ 'type' : 'label',
+ 'c' : opts.label_text || ""
+ },{
+ 'type' : "input",
+ 'attr' : {
+ 'type' : opts.type || "text",
+ 'name' : opts.name || null,
+ 'value' : opts.value || null
+ }
+ }]
+ },
+
+ // do stuff to the general management of templates
all : function( key ) {
return __ns;
},
@@ -32,10 +63,12 @@
// direct access
return this.__create(key);
},
- t : function( key, action, payload ) {
- var ns=this.__create(key), type=(typeof payload).toLowerCase();
- if(type==="string") { payload=[payload] }
- ns[action].apply( ns, payload );
+ // args (key, action, p,a,y,l,o,a,d) where p,a,y,l,o,a,d is N args needs for the fn_method
+ t : function( key, fn_method ) {
+ var payload=[], ns=this.__create(key);
+ if(!key && !action) { throw("Name and method required"); }
+ if(arguments.length > 2) { payload=Array.prototype.slice.call(arguments, 2); }
+ ns[fn_method].apply( ns, payload );
},
r : function( key, el ) {
var ns=this.__create(key);
@@ -44,7 +77,6 @@
}
ns.draw(el);
},
-
render : function(key, el, frag ) {
var type = typeof el, ns=this.__create(key), item;
if( type.toLowerCase === "object" ) {
@@ -75,12 +107,18 @@
this.__t=[];
this.ns=ns;
this.__active_dom=[];
- this.__root=null;
+ this.__root=null;
+ this.dom_reference=true;
};
F.prototype={
- // commands?? like a string of things to do??
- //
+ /*
+ Holds data representation for fastFrag
+ */
+ // JS method overloading? sorta
+ event : function( fn ) {
+ fn.apply(this, Array.prototype.slice.call(arguments, 1) || [] );
+ },
add_root : function( clss, opts ) {
// basically take the current list at __t
// and make a new content node and put it in an array
@@ -114,9 +152,6 @@
},
css : function( opts, set ) {
var type=typeof opts;
- // if(type.toLowerCase() === "string") {
- //
- // }
},
extend : function() {
// which element to extend??
@@ -129,15 +164,25 @@
}
},
draw : function( el ) {
- this.__active_dom.push( el.appendChild( fastFrag.create( this.__t ) ) );
- },
- iterator : function( list, fn ) {
+ el.appendChild( fastFrag.create( this.__t ) );
+ if(this.dom_reference) this.__active_dom.push( el );
+ },
+ iterator : function( list, fn, opts ) {
+ // 'event'ish methods
+ /*
+ opts = {
+ before : function()
+ complete : function()
+ }
+ */
var i=0;
+ if(opts && opts.before && (typeof opts.before).toLowerCase() === "function") opts.before.call(this);
for(; i<list.length; i+=1) {
- fn( list[i] );
+ fn.apply( this, [list[i]] );
}
+ if(opts && opts.complete && (typeof opts.complete).toLowerCase() === "function") opts.complete.call(this);
},
- /// this is neat..
+ // a basic list
list_basic : function( type, data, opts ) {
var frag, i=0, items=[], f_items=[], wrapper_type="ul", t=(typeof data).toLowerCase();
if(t === "object" && t.length) {
@@ -170,6 +215,10 @@
return this;
},
+ list_links : function(type, data, opts) {
+
+ },
+
find : function( opts ) {
var key = opts && opts.key || null,
value=opts && opts.value || null;
View
16 tests/test_fraglet.html
@@ -54,10 +54,10 @@
my_item.list_basic("div", ["alpha", "bravo", "cat"]);
my_item.draw( mid_elem )
console.log(fraglet.all());
- fraglet.t("son.bro", "list_basic", ["li", ["five towns", "borrows"], {
+ fraglet.t("son.bro", "list_basic", "li", ["five towns", "borrows"], {
css : "oops_item"
- }]);
- fraglet.t("son.bro", "list_basic", ["li", ["son", "brooklyn"]]);
+ });
+ fraglet.t("son.bro", "list_basic", "li", ["son", "brooklyn"]);
fraglet.t("son.bro", "add_root", "grat_again");
@@ -66,21 +66,21 @@
fraglet.r("son.bro", mid_elem);
- fraglet.t("blah.blah.blah", "list_basic", ["li", ["ha", "ho"]]);
+ fraglet.t("blah.blah.blah", "list_basic", "li", ["ha", "ho"]);
fraglet.r("blah.blah.blah", mid_elem)
- fraglet.t( "foo", "list_basic", ["li", ["one", "two", "three"]] );
+ fraglet.t( "foo", "list_basic", "li", ["one", "two", "three"] );
- fraglet.t( "foo", "list_basic", ["li", 5] );
+ fraglet.t( "foo", "list_basic", "li", 5 );
fraglet.d("foo").list_basic("li", ["a", "b", "c"])
- fraglet.t( "foo", "list_basic", ["li", ["one", "two", "three"], {
+ fraglet.t( "foo", "list_basic", "li", ["one", "two", "three"], {
css : "party"
- }] );
+ } );
fraglet.r("foo", mid_elem );
View
63 tests/test_fraglet_2.html
@@ -0,0 +1,63 @@
+<!DOCTYPE HTML>
+<html>
+
+<!--
+ http://unlicense.org/
+ author: gregory tomlinson
+-->
+
+<!-- MIME TYPE Guidlines and references: http://hixie.ch/advocacy/xhtml -->
+ <head>
+ <title>Fraglet Test 2</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <meta name="keywords" content="awesome" />
+ <meta name="description" content="" />
+
+ </head>
+ <body>
+ <div id="container">
+
+ <div id="top">
+
+ </div> <!-- end #top -->
+
+ <div id="middle">
+
+ </div> <!-- END #middle -->
+
+ <div id="bottom">
+
+ </div> <!-- end #bottom -->
+
+ </div> <!-- end #container -->
+
+
+ <script type="text/javascript" src="../js/fastFrag.js"></script>
+ <script type="text/javascript" src="../js/fraglet.js"></script>
+ <script type="text/javascript" charset="utf-8">
+ fraglet.t("bar", "list_basic", "li", ["one", "two"]);
+ fraglet.t("bar", "iterator", ["foo", "bar", "bam", "bom", "ping", "pong"], function( item ){
+ console.log("item", this, item);
+ this.append({
+ 'c' : item
+ })
+ },{
+ before : function() {
+ console.log("yey, first")
+ },
+ complete : function() {
+ console.log("done!", this)
+ }
+ });
+
+ fraglet.inpt({
+ label_text : "party"
+ });
+
+ fraglet.r("bar", document.getElementById("middle"));
+
+ console.log(fraglet.d("bar"));
+ </script>
+
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.