Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

0.0.2 - removed fidel dependancy, added startPoint

  • Loading branch information...
commit 3c43ed48b825033f566dfc83470e66728622624b 1 parent bc0a6cf
@jgallen23 jgallen23 authored
View
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "vendor/aug"]
+ path = vendor/aug
+ url = git@github.com:jgallen23/aug.git
View
1  Makefile
@@ -1,4 +1,5 @@
boosh:
+ git submodule update --init
smoosh make ./build.json
clean:
View
6 README.md
@@ -1 +1,5 @@
-# Fidel Floater
+# Floater
+
+## Usage
+
+ var floater = new Floater({ el: $(".floater"), stopPoint: 800, startPoint: 150 });
View
12 build.json
@@ -1,14 +1,12 @@
{
"JAVASCRIPT": {
"DIST_DIR": "./dist/",
- "fidel.floater": [
+ "floater": [
"./lib/copyright.js",
- "./lib/floater.js"
- ],
- "fidel.floater.full": [
- "./lib/copyright.js",
- "./vendor/fidel.js",
- "./lib/floater.js"
+ "./lib/amd-top.js",
+ "./vendor/aug/lib/aug.js",
+ "./lib/floater.js",
+ "./lib/amd-bottom.js"
]
},
"JSHINT_OPTS": {
View
291 dist/fidel.floater.full.js
@@ -1,291 +0,0 @@
-/*!
- * Fidel Floater
- * v0.0.1
- * https://github.com/jgallen23/fidel-floater
- * copyright JGA 2011
- * MIT License
- */
-
-/*!
- * Fidel - A javascript controller
- * v1.2.2
- * https://github.com/jgallen23/fidel
- * copyright JGA 2011
- * MIT License
- */
-
-!function(obj) {
-
- var Fidel = {};
- Fidel.guid = function(){
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
- var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
- return v.toString(16);
- }).toUpperCase();
- };
- Fidel.extend = function() {
- throw new Error("Fidel.extend is deprecated, please use Fidel.ViewController.extend");
- };
-
- var o = obj.Fidel;
- Fidel.noConflict = function() {
- obj.Fidel = o;
- return this;
- };
- obj.Fidel = Fidel;
-}(this);
-
-!function(f) {
- var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
- // The base Class implementation (does nothing)
- f.Class = function(){};
-
- // Create a new Class that inherits from this class
- f.Class.extend = function(prop) {
- var _super = this.prototype;
-
- // Instantiate a base class (but only create the instance,
- // don't run the init constructor)
- initializing = true;
- var prototype = new this();
- initializing = false;
-
- // Copy the properties over onto the new prototype
- for (var name in prop) {
- // Check if we're overwriting an existing function
- prototype[name] = typeof prop[name] == "function" &&
- typeof _super[name] == "function" && fnTest.test(prop[name]) ?
- (function(name, fn){
- return function() {
- var tmp = this._super;
-
- // Add a new ._super() method that is the same method
- // but on the super-class
- this._super = _super[name];
-
- // The method only need to be bound temporarily, so we
- // remove it when we're done executing
- var ret = fn.apply(this, arguments);
- this._super = tmp;
-
- return ret;
- };
- })(name, prop[name]) :
- prop[name];
- }
-
- // The dummy class constructor
- function Class(opt) {
- // All construction is actually done in the init method
- if (!initializing) {
- if (this.defaults) {
- for (var key in this.defaults) {
- if (typeof opt !== 'object' || !opt[key]) this[key] = this.defaults[key];
- }
- }
- if (typeof opt === 'object') {
- for (var okey in opt) {
- this[okey] = opt[okey];
- }
- }
- if (!this.guid) this.guid = f.guid();
- if (this._initialize) this._initialize.apply(this, arguments);
- if (this.init) this.init.apply(this, arguments);
- }
- }
-
- // Populate our constructed prototype object
- Class.prototype = prototype;
- Class.prototype.proxy = function(func) {
- var thisObject = this;
- return(function(){
- if (!func) return;
- return func.apply(thisObject, arguments);
- });
- };
-
- // Enforce the constructor to be what we expect
- Class.constructor = Class;
-
- // And make this class extendable
- Class.extend = arguments.callee;
-
- return Class;
- };
-}(Fidel || this);
-
-!function(f) {
- var cache = {}; //check for "c_" cache for unit testing
- //publish("/some/topic", ["a","b","c"]);
- f.publish = function(topic, args){
-
- var subs = cache[topic], len = subs ? subs.length : 0;
-
- //can change loop or reverse array if the order matters
- while(len--){
- subs[len].apply(this, args || []);
- }
- };
- //subscribe("/some/topic", function(a, b, c){ /* handle data */ });
- f.subscribe = function(topic, callback){
- if(!cache[topic]){
- cache[topic] = [];
- }
- cache[topic].push(callback);
- return [topic, callback]; // Array
- };
- //var handle = subscribe("/some/topic", function(){});
- //unsubscribe(handle);
- f.unsubscribe = function(handle){
- var subs = cache[handle[0]],
- callback = handle[1],
- len = subs ? subs.length : 0;
-
- while(len--){
- if(subs[len] === callback){
- subs.splice(len, 1);
- }
- }
- };
-
-
- f.Class.prototype.on = f.Class.prototype.bind = function(name, callback) {
- return f.subscribe(this.guid+"."+name, this.proxy(callback));
- };
- f.Class.prototype.emit = f.Class.prototype.trigger = function(name, data) {
- f.publish(this.guid+"."+name, data);
- f.publish(name, data);
- };
- f.Class.prototype.removeListener = f.Class.prototype.unbind = function(handle) {
- f.unsubscribe(handle);
- };
-
-}(Fidel || this);
-
-(function(f) {
- var eventSplitter = /^(\w+)\s*(.*)$/;
-
- var ViewController = f.Class.extend({
- _initialize: function(options) {
-
- if (!this.el) throw "el is required";
-
- this._subscribeHandles = {};
- if (this.events) this.delegateEvents();
- if (this.elements) this.refreshElements();
- if (this.templates) this.loadTemplates();
- if (!this.actionEvent) this.actionEvent = "click";
- if (this.subscribe) this.bindSubscriptions();
- this.delegateActions();
- this.getDataElements();
- },
- template: (window.str)?window.str.template:null,
- delegateEvents: function() {
- for (var key in this.events) {
- var methodName = this.events[key];
- var match = key.match(eventSplitter);
- var eventName = match[1], selector = match[2];
-
- var method = this.proxy(this[methodName]);
-
- if (selector === '') {
- this.el.bind(eventName, method);
- } else {
- this.el.delegate(selector, eventName, method);
- }
- }
- },
- delegateActions: function() {
- var self = this;
- this.el.delegate('[data-action]', this.actionEvent, function(e) {
- var el = $(this);
- var methodName = el.attr('data-action');
- if (self[methodName]) self[methodName].call(self, el);
- });
- },
- refreshElements: function() {
- for (var key in this.elements) {
- this[key] = this.find(this.elements[key]);
- }
- },
- getDataElements: function() {
- var self = this;
- var elements = this.find("[data-element]");
- for (var i = 0, c = elements.length; i < c; i++) {
- var name = elements[i].getAttribute('data-element');
- if (!self[name]) {
- var elem = this.find('[data-element="'+name+'"]');
- self[name] = elem;
- }
- }
- },
- bindSubscriptions: function() {
- for (var key in this.subscribe) {
- this._subscribeHandles[key] = Fidel.subscribe(key, this.proxy(this[this.subscribe[key]]));
- }
- },
- loadTemplates: function() {
- for (var name in this.templates) {
- this.templates[name] = $(this.templates[name]).html();
- }
- },
- find: function(selector) {
- return $(selector, this.el[0]);
- },
- render: function(template, data, selector) {
- var tmp = this.template(template, data);
- selector = (selector)?$(selector):this.el;
- selector.html(tmp);
- },
- destroy: function() {
- for (var key in this._subscribeHandles) {
- Fidel.unsubscribe(this._subscribeHandles[key]);
- }
- this.el.undelegate('[data-action]', this.actionEvent);
- this.el = null;
- }
- });
- f.ViewController = ViewController;
-})(Fidel || this);
-
-Fidel.Floater = Fidel.ViewController.extend({
- defaults: {
- topPadding: 10,
- stopPoint: -1
- },
- init: function() {
- $(window).scroll(this.proxy(this.onScroll));
-
- console.log(this.el.offset().top);
- this._top = this.el.offset().top;
- this._floating = false;
- },
- startFloat: function() {
- var self = this;
- this._floating = true;
- this.el.css({
- position: 'fixed',
- top: self.topPadding
- });
- },
- stopFloat: function(posY) {
- var self = this;
- this._floating = false;
- this.el.css({
- position: 'absolute',
- top: posY
- });
- },
- onScroll: function(e) {
- var scrollY = $(window).scrollTop();
- if (scrollY > this._top) {
- if (this.stopPoint != -1 && scrollY > this.stopPoint) {
- this.stopFloat(this.el.offset().top);
- } else if (!this._floating) {
- this.startFloat();
- }
- } else if (scrollY < this._top && this._floating) {
- this.stopFloat(this._top);
- }
- }
-});
View
14 dist/fidel.floater.full.min.js
@@ -1,14 +0,0 @@
-/*!
- * Fidel Floater
- * v0.0.1
- * https://github.com/jgallen23/fidel-floater
- * copyright JGA 2011
- * MIT License
- *//*!
- * Fidel - A javascript controller
- * v1.2.2
- * https://github.com/jgallen23/fidel
- * copyright JGA 2011
- * MIT License
- */
-!function(a){var b={};b.guid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=Math.random()*16|0,c=a==="x"?b:b&3|8;return c.toString(16)}).toUpperCase()},b.extend=function(){throw new Error("Fidel.extend is deprecated, please use Fidel.ViewController.extend")};var c=a.Fidel;b.noConflict=function(){return a.Fidel=c,this},a.Fidel=b}(this),!function(a){var b=!1,c=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;a.Class=function(){},a.Class.extend=function(d){function i(c){if(!b){if(this.defaults)for(var d in this.defaults)if(typeof c!="object"||!c[d])this[d]=this.defaults[d];if(typeof c=="object")for(var e in c)this[e]=c[e];this.guid||(this.guid=a.guid()),this._initialize&&this._initialize.apply(this,arguments),this.init&&this.init.apply(this,arguments)}}var e=this.prototype;b=!0;var g=new this;b=!1;for(var h in d)g[h]=typeof d[h]=="function"&&typeof e[h]=="function"&&c.test(d[h])?function(a,b){return function(){var c=this._super;this._super=e[a];var d=b.apply(this,arguments);return this._super=c,d}}(h,d[h]):d[h];return i.prototype=g,i.prototype.proxy=function(a){var b=this;return function(){if(!a)return;return a.apply(b,arguments)}},i.constructor=i,i.extend=arguments.callee,i}}(Fidel||this),!function(a){var b={};a.publish=function(a,c){var d=b[a],e=d?d.length:0;while(e--)d[e].apply(this,c||[])},a.subscribe=function(a,c){return b[a]||(b[a]=[]),b[a].push(c),[a,c]},a.unsubscribe=function(a){var c=b[a[0]],d=a[1],e=c?c.length:0;while(e--)c[e]===d&&c.splice(e,1)},a.Class.prototype.on=a.Class.prototype.bind=function(b,c){return a.subscribe(this.guid+"."+b,this.proxy(c))},a.Class.prototype.emit=a.Class.prototype.trigger=function(b,c){a.publish(this.guid+"."+b,c),a.publish(b,c)},a.Class.prototype.removeListener=a.Class.prototype.unbind=function(b){a.unsubscribe(b)}}(Fidel||this),function(a){var b=/^(\w+)\s*(.*)$/,c=a.Class.extend({_initialize:function(a){if(!this.el)throw"el is required";this._subscribeHandles={},this.events&&this.delegateEvents(),this.elements&&this.refreshElements(),this.templates&&this.loadTemplates(),this.actionEvent||(this.actionEvent="click"),this.subscribe&&this.bindSubscriptions(),this.delegateActions(),this.getDataElements()},template:window.str?window.str.template:null,delegateEvents:function(){for(var a in this.events){var c=this.events[a],d=a.match(b),e=d[1],f=d[2],g=this.proxy(this[c]);f===""?this.el.bind(e,g):this.el.delegate(f,e,g)}},delegateActions:function(){var a=this;this.el.delegate("[data-action]",this.actionEvent,function(b){var c=$(this),d=c.attr("data-action");a[d]&&a[d].call(a,c)})},refreshElements:function(){for(var a in this.elements)this[a]=this.find(this.elements[a])},getDataElements:function(){var a=this,b=this.find("[data-element]");for(var c=0,d=b.length;c<d;c++){var e=b[c].getAttribute("data-element");if(!a[e]){var f=this.find('[data-element="'+e+'"]');a[e]=f}}},bindSubscriptions:function(){for(var a in this.subscribe)this._subscribeHandles[a]=Fidel.subscribe(a,this.proxy(this[this.subscribe[a]]))},loadTemplates:function(){for(var a in this.templates)this.templates[a]=$(this.templates[a]).html()},find:function(a){return $(a,this.el[0])},render:function(a,b,c){var d=this.template(a,b);c=c?$(c):this.el,c.html(d)},destroy:function(){for(var a in this._subscribeHandles)Fidel.unsubscribe(this._subscribeHandles[a]);this.el.undelegate("[data-action]",this.actionEvent),this.el=null}});a.ViewController=c}(Fidel||this),Fidel.Floater=Fidel.ViewController.extend({defaults:{topPadding:10,stopPoint:-1},init:function(){$(window).scroll(this.proxy(this.onScroll)),console.log(this.el.offset().top),this._top=this.el.offset().top,this._floating=!1},startFloat:function(){var a=this;this._floating=!0,this.el.css({position:"fixed",top:a.topPadding})},stopFloat:function(a){var b=this;this._floating=!1,this.el.css({position:"absolute",top:a})},onScroll:function(a){var b=$(window).scrollTop();b>this._top?this.stopPoint!=-1&&b>this.stopPoint?this.stopFloat(this.el.offset().top):this._floating||this.startFloat():b<this._top&&this._floating&&this.stopFloat(this._top)}})
View
49 dist/fidel.floater.js
@@ -1,49 +0,0 @@
-/*!
- * Fidel Floater
- * v0.0.1
- * https://github.com/jgallen23/fidel-floater
- * copyright JGA 2011
- * MIT License
- */
-
-Fidel.Floater = Fidel.ViewController.extend({
- defaults: {
- topPadding: 10,
- stopPoint: -1
- },
- init: function() {
- $(window).scroll(this.proxy(this.onScroll));
-
- console.log(this.el.offset().top);
- this._top = this.el.offset().top;
- this._floating = false;
- },
- startFloat: function() {
- var self = this;
- this._floating = true;
- this.el.css({
- position: 'fixed',
- top: self.topPadding
- });
- },
- stopFloat: function(posY) {
- var self = this;
- this._floating = false;
- this.el.css({
- position: 'absolute',
- top: posY
- });
- },
- onScroll: function(e) {
- var scrollY = $(window).scrollTop();
- if (scrollY > this._top) {
- if (this.stopPoint != -1 && scrollY > this.stopPoint) {
- this.stopFloat(this.el.offset().top);
- } else if (!this._floating) {
- this.startFloat();
- }
- } else if (scrollY < this._top && this._floating) {
- this.stopFloat(this._top);
- }
- }
-});
View
8 dist/fidel.floater.min.js
@@ -1,8 +0,0 @@
-/*!
- * Fidel Floater
- * v0.0.1
- * https://github.com/jgallen23/fidel-floater
- * copyright JGA 2011
- * MIT License
- */
-Fidel.Floater=Fidel.ViewController.extend({defaults:{topPadding:10,stopPoint:-1},init:function(){$(window).scroll(this.proxy(this.onScroll)),console.log(this.el.offset().top),this._top=this.el.offset().top,this._floating=!1},startFloat:function(){var a=this;this._floating=!0,this.el.css({position:"fixed",top:a.topPadding})},stopFloat:function(a){var b=this;this._floating=!1,this.el.css({position:"absolute",top:a})},onScroll:function(a){var b=$(window).scrollTop();b>this._top?this.stopPoint!=-1&&b>this.stopPoint?this.stopFloat(this.el.offset().top):this._floating||this.startFloat():b<this._top&&this._floating&&this.stopFloat(this._top)}})
View
71 dist/floater.js
@@ -0,0 +1,71 @@
+/*!
+ * Floater - a javascript library to make an element float
+ * v0.0.2
+ * https://github.com/jgallen23/floater
+ * copyright JGA 2011
+ * MIT License
+ */
+
+!function (name, definition) {
+ if (typeof module != 'undefined' && module.exports) module.exports = definition();
+ else if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
+ else this[name] = definition();
+}('Floater', function() {
+
+var aug = function() {
+ var args = Array.prototype.slice.call(arguments);
+ var org = args.shift();
+ if (typeof org === "function") org = org.prototype;
+ for (var i = 0, c = args.length; i < c; i++) {
+ var prop = args[i];
+ for (var name in prop) {
+ org[name] = prop[name];
+ }
+ }
+ return org;
+};
+
+var Floater = function(options) {
+ var defaults = {
+ topPadding: 10,
+ stopPoint: -1,
+ startPoint: 0
+ };
+ var opts = aug({}, defaults, options);
+ if (!opts.el)
+ throw "el is required";
+
+ opts.el.css('top', opts.startPoint).fadeIn();
+ var floating = false;
+
+ var startFloat = function() {
+ floating = true;
+ opts.el.css({
+ position: 'fixed',
+ top: opts.topPadding
+ });
+ };
+ var stopFloat = function(posY) {
+ floating = false;
+ opts.el.css({
+ position: 'absolute',
+ top: posY
+ });
+ };
+ var onScroll = function(e) {
+ var scrollY = $(window).scrollTop();
+ if (scrollY > opts.startPoint) {
+ if (opts.stopPoint != -1 && scrollY > opts.stopPoint) {
+ stopFloat(opts.el.offset().top);
+ } else if (!floating) {
+ startFloat();
+ }
+ } else if (scrollY < opts.startPoint && floating) {
+ stopFloat(opts.startPoint);
+ }
+ };
+ $(window).scroll(onScroll);
+};
+
+return Floater;
+});
View
8 dist/floater.min.js
@@ -0,0 +1,8 @@
+/*!
+ * Floater - a javascript library to make an element float
+ * v0.0.2
+ * https://github.com/jgallen23/floater
+ * copyright JGA 2011
+ * MIT License
+ */
+!function(a,b){typeof module!="undefined"&&module.exports?module.exports=b():typeof define=="function"&&typeof define.amd=="object"?define(b):this[a]=b()}("Floater",function(){var a=function(){var a=Array.prototype.slice.call(arguments),b=a.shift();typeof b=="function"&&(b=b.prototype);for(var c=0,d=a.length;c<d;c++){var e=a[c];for(var f in e)b[f]=e[f]}return b},b=function(b){var c={topPadding:10,stopPoint:-1,startPoint:0},d=a({},c,b);if(!d.el)throw"el is required";d.el.css("top",d.startPoint).fadeIn();var e=!1,f=function(){e=!0,d.el.css({position:"fixed",top:d.topPadding})},g=function(a){e=!1,d.el.css({position:"absolute",top:a})},h=function(a){var b=$(window).scrollTop();b>d.startPoint?d.stopPoint!=-1&&b>d.stopPoint?g(d.el.offset().top):e||f():b<d.startPoint&&e&&g(d.startPoint)};$(window).scroll(h)};return b})
View
19 example/index.html
@@ -1,15 +1,17 @@
<html>
<head>
- <title>Fidel Module Example</title>
+ <title>Floater Module Example</title>
<script src="live.js"></script>
<script src="jquery.min.js"></script>
- <script src="../vendor/fidel.js"></script>
- <script src="../lib/floater.js"></script>
+ <!--<script src="../vendor/aug/dist/aug.js"></script>-->
+ <!--<script src="../lib/floater.js"></script>-->
+ <script src="../dist/floater.js"></script>
<style>
body { margin: 0; padding: 0; }
.wrapper { width: 980px; margin: 0 auto; position: relative; }
.header, .footer { height: 150px; background: #ccc; }
- .floater { position: absolute; background: #f0f0f0; height: 300px; width: 100px; margin-left: -120px; top: 150px }
+ .floater { position: absolute; background: #f0f0f0; height: 300px; width: 100px; margin-left: -120px; display: none;}
+ .floater2 { position: absolute; background: #f0f0f0; height: 300px; width: 100px; margin-left: 1000px; display: none;}
.content { height: 2000px; }
</style>
</head>
@@ -18,6 +20,9 @@
<div class="floater">
I Float
</div>
+ <div class="floater2">
+ I Float
+ </div>
<div class="header">header</div>
<div class="content">
<p>hey, I'm content</p>
@@ -25,10 +30,8 @@
<div class="footer">footer</div>
</div>
<script>
- var floater = new Fidel.Floater({ el: $(".floater"), stopPoint: 600 });
- setTimeout(function() {
- //window.scrollTo(0, 200);
- });
+ var floater = new Floater({ el: $(".floater"), stopPoint: 800, startPoint: 150 });
+ var floater2 = new Floater({ el: $(".floater2") });
</script>
</body>
</html>
View
2  lib/amd-bottom.js
@@ -0,0 +1,2 @@
+return Floater;
+});
View
5 lib/amd-top.js
@@ -0,0 +1,5 @@
+!function (name, definition) {
+ if (typeof module != 'undefined' && module.exports) module.exports = definition();
+ else if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
+ else this[name] = definition();
+}('Floater', function() {
View
6 lib/copyright.js
@@ -1,7 +1,7 @@
/*!
- * Fidel Floater
- * v0.0.1
- * https://github.com/jgallen23/fidel-floater
+ * Floater - a javascript library to make an element float
+ * v0.0.2
+ * https://github.com/jgallen23/floater
* copyright JGA 2011
* MIT License
*/
View
62 lib/floater.js
@@ -1,41 +1,41 @@
-Fidel.Floater = Fidel.ViewController.extend({
- defaults: {
+var Floater = function(options) {
+ var defaults = {
topPadding: 10,
- stopPoint: -1
- },
- init: function() {
- $(window).scroll(this.proxy(this.onScroll));
+ stopPoint: -1,
+ startPoint: 0
+ };
+ var opts = aug({}, defaults, options);
+ if (!opts.el)
+ throw "el is required";
- console.log(this.el.offset().top);
- this._top = this.el.offset().top;
- this._floating = false;
- },
- startFloat: function() {
- var self = this;
- this._floating = true;
- this.el.css({
+ opts.el.css('top', opts.startPoint).fadeIn();
+ var floating = false;
+
+ var startFloat = function() {
+ floating = true;
+ opts.el.css({
position: 'fixed',
- top: self.topPadding
+ top: opts.topPadding
});
- },
- stopFloat: function(posY) {
- var self = this;
- this._floating = false;
- this.el.css({
+ };
+ var stopFloat = function(posY) {
+ floating = false;
+ opts.el.css({
position: 'absolute',
top: posY
});
- },
- onScroll: function(e) {
+ };
+ var onScroll = function(e) {
var scrollY = $(window).scrollTop();
- if (scrollY > this._top) {
- if (this.stopPoint != -1 && scrollY > this.stopPoint) {
- this.stopFloat(this.el.offset().top);
- } else if (!this._floating) {
- this.startFloat();
+ if (scrollY > opts.startPoint) {
+ if (opts.stopPoint != -1 && scrollY > opts.stopPoint) {
+ stopFloat(opts.el.offset().top);
+ } else if (!floating) {
+ startFloat();
}
- } else if (scrollY < this._top && this._floating) {
- this.stopFloat(this._top);
+ } else if (scrollY < opts.startPoint && floating) {
+ stopFloat(opts.startPoint);
}
- }
-});
+ };
+ $(window).scroll(onScroll);
+};
1  vendor/aug
@@ -0,0 +1 @@
+Subproject commit c374e0b7cce19bf25441e677d1cd84089eee76c2
View
241 vendor/fidel.js
@@ -1,241 +0,0 @@
-/*!
- * Fidel - A javascript controller
- * v1.2.2
- * https://github.com/jgallen23/fidel
- * copyright JGA 2011
- * MIT License
- */
-
-!function(obj) {
-
- var Fidel = {};
- Fidel.guid = function(){
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
- var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
- return v.toString(16);
- }).toUpperCase();
- };
- Fidel.extend = function() {
- throw new Error("Fidel.extend is deprecated, please use Fidel.ViewController.extend");
- };
-
- var o = obj.Fidel;
- Fidel.noConflict = function() {
- obj.Fidel = o;
- return this;
- };
- obj.Fidel = Fidel;
-}(this);
-
-!function(f) {
- var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
- // The base Class implementation (does nothing)
- f.Class = function(){};
-
- // Create a new Class that inherits from this class
- f.Class.extend = function(prop) {
- var _super = this.prototype;
-
- // Instantiate a base class (but only create the instance,
- // don't run the init constructor)
- initializing = true;
- var prototype = new this();
- initializing = false;
-
- // Copy the properties over onto the new prototype
- for (var name in prop) {
- // Check if we're overwriting an existing function
- prototype[name] = typeof prop[name] == "function" &&
- typeof _super[name] == "function" && fnTest.test(prop[name]) ?
- (function(name, fn){
- return function() {
- var tmp = this._super;
-
- // Add a new ._super() method that is the same method
- // but on the super-class
- this._super = _super[name];
-
- // The method only need to be bound temporarily, so we
- // remove it when we're done executing
- var ret = fn.apply(this, arguments);
- this._super = tmp;
-
- return ret;
- };
- })(name, prop[name]) :
- prop[name];
- }
-
- // The dummy class constructor
- function Class(opt) {
- // All construction is actually done in the init method
- if (!initializing) {
- if (this.defaults) {
- for (var key in this.defaults) {
- if (typeof opt !== 'object' || !opt[key]) this[key] = this.defaults[key];
- }
- }
- if (typeof opt === 'object') {
- for (var okey in opt) {
- this[okey] = opt[okey];
- }
- }
- if (!this.guid) this.guid = f.guid();
- if (this._initialize) this._initialize.apply(this, arguments);
- if (this.init) this.init.apply(this, arguments);
- }
- }
-
- // Populate our constructed prototype object
- Class.prototype = prototype;
- Class.prototype.proxy = function(func) {
- var thisObject = this;
- return(function(){
- if (!func) return;
- return func.apply(thisObject, arguments);
- });
- };
-
- // Enforce the constructor to be what we expect
- Class.constructor = Class;
-
- // And make this class extendable
- Class.extend = arguments.callee;
-
- return Class;
- };
-}(Fidel || this);
-
-!function(f) {
- var cache = {}; //check for "c_" cache for unit testing
- //publish("/some/topic", ["a","b","c"]);
- f.publish = function(topic, args){
-
- var subs = cache[topic], len = subs ? subs.length : 0;
-
- //can change loop or reverse array if the order matters
- while(len--){
- subs[len].apply(this, args || []);
- }
- };
- //subscribe("/some/topic", function(a, b, c){ /* handle data */ });
- f.subscribe = function(topic, callback){
- if(!cache[topic]){
- cache[topic] = [];
- }
- cache[topic].push(callback);
- return [topic, callback]; // Array
- };
- //var handle = subscribe("/some/topic", function(){});
- //unsubscribe(handle);
- f.unsubscribe = function(handle){
- var subs = cache[handle[0]],
- callback = handle[1],
- len = subs ? subs.length : 0;
-
- while(len--){
- if(subs[len] === callback){
- subs.splice(len, 1);
- }
- }
- };
-
-
- f.Class.prototype.on = f.Class.prototype.bind = function(name, callback) {
- return f.subscribe(this.guid+"."+name, this.proxy(callback));
- };
- f.Class.prototype.emit = f.Class.prototype.trigger = function(name, data) {
- f.publish(this.guid+"."+name, data);
- f.publish(name, data);
- };
- f.Class.prototype.removeListener = f.Class.prototype.unbind = function(handle) {
- f.unsubscribe(handle);
- };
-
-}(Fidel || this);
-
-(function(f) {
- var eventSplitter = /^(\w+)\s*(.*)$/;
-
- var ViewController = f.Class.extend({
- _initialize: function(options) {
-
- if (!this.el) throw "el is required";
-
- this._subscribeHandles = {};
- if (this.events) this.delegateEvents();
- if (this.elements) this.refreshElements();
- if (this.templates) this.loadTemplates();
- if (!this.actionEvent) this.actionEvent = "click";
- if (this.subscribe) this.bindSubscriptions();
- this.delegateActions();
- this.getDataElements();
- },
- template: (window.str)?window.str.template:null,
- delegateEvents: function() {
- for (var key in this.events) {
- var methodName = this.events[key];
- var match = key.match(eventSplitter);
- var eventName = match[1], selector = match[2];
-
- var method = this.proxy(this[methodName]);
-
- if (selector === '') {
- this.el.bind(eventName, method);
- } else {
- this.el.delegate(selector, eventName, method);
- }
- }
- },
- delegateActions: function() {
- var self = this;
- this.el.delegate('[data-action]', this.actionEvent, function(e) {
- var el = $(this);
- var methodName = el.attr('data-action');
- if (self[methodName]) self[methodName].call(self, el);
- });
- },
- refreshElements: function() {
- for (var key in this.elements) {
- this[key] = this.find(this.elements[key]);
- }
- },
- getDataElements: function() {
- var self = this;
- var elements = this.find("[data-element]");
- for (var i = 0, c = elements.length; i < c; i++) {
- var name = elements[i].getAttribute('data-element');
- if (!self[name]) {
- var elem = this.find('[data-element="'+name+'"]');
- self[name] = elem;
- }
- }
- },
- bindSubscriptions: function() {
- for (var key in this.subscribe) {
- this._subscribeHandles[key] = Fidel.subscribe(key, this.proxy(this[this.subscribe[key]]));
- }
- },
- loadTemplates: function() {
- for (var name in this.templates) {
- this.templates[name] = $(this.templates[name]).html();
- }
- },
- find: function(selector) {
- return $(selector, this.el[0]);
- },
- render: function(template, data, selector) {
- var tmp = this.template(template, data);
- selector = (selector)?$(selector):this.el;
- selector.html(tmp);
- },
- destroy: function() {
- for (var key in this._subscribeHandles) {
- Fidel.unsubscribe(this._subscribeHandles[key]);
- }
- this.el.undelegate('[data-action]', this.actionEvent);
- this.el = null;
- }
- });
- f.ViewController = ViewController;
-})(Fidel || this);
Please sign in to comment.
Something went wrong with that request. Please try again.