This repository has been archived by the owner on Jun 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.mvc.min.js
20 lines (20 loc) · 4.67 KB
/
jquery.mvc.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*!
* jQuery MVC
* A simple MVC framework for the jQuery JavaScript Library
* http://github.com/rjgotten/jquery-mvc
*
* Copyright 2011, Ron Otten
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://github.com/rjgotten/jquery-mvc/licenses
*/
(function(a){a.mvc=a.mvc||{};a.mvc.version="0.9.0";a.mvc.module=function(e,f,g){var b,c,d;b=e.split(".");e=b[1]||b[0];c=b[0]===e?"":b[0];b=b.join("-");b=new f;b.options=a.extend(true,{},b.options);d=c?a.mvc[c]=a.mvc[c]||{}:{};d[e]=function(){arguments.length&&this._createModule.apply(this,arguments)};d[e].prototype=a.extend(true,b,{name:e,namespace:c,base:f.prototype,constructor:d[e]},g);a.each(d[e].prototype,function(h,j){if(h==="constructor")return true;var i=f.prototype[h];if(j!==i&&a.isFunction(j)&&
a.isFunction(i))j.__super=i});return d[e]};a.mvc.Module=function(){arguments.length>0&&this._createModule.apply(this,arguments)};a.mvc.Module.prototype={name:"module",options:{},_createModule:function(e,f){this.name=e;this.options=a.extend(true,{},this.options,f)},_super:function(){var e=arguments.callee.caller;if(e&&a.isFunction(e.__super))return e.__super.apply(this,arguments);else throw"_super: No super-implementation available for this function.";},getName:function(){return this.name},_notify:function(e,
f){var g=a.mvc.Notification(e,f);a.mvc.notifier.notify(g)}}})(jQuery);
(function(a,e){var f={},g=0;a.mvc.model={has:function(b){return f[b]!==e},get:function(b){return a.mvc.model.has(b)?f[b]:null},register:function(b,c,d,h){if(typeof b!=="string"){h=d;d=c;c=b;b="proxy-"+ ++g}if(a.mvc.model.has(b))throw"jQuery.mvc.model: A proxy named '"+b+"' already exists.";c=f[b]=new c(b,d,h);c._register();return c},remove:function(b){if(typeof b==="object")b=b.getName();b=f[b];if(b!==e){delete f[b.getName()];b._remove()}}};a.mvc.proxy=function(b,c,d){if(typeof d==="undefined"){d=
c;c=a.mvc.Proxy}return a.mvc.module(b,c,d)};a.mvc.Proxy=a.mvc.module("Proxy",a.mvc.Module,{data:null,getData:function(){return this.data},_createModule:function(b,c,d){this.name=b;this.data=d;this.options=a.extend(true,{},this.options,c)},_register:function(){},_remove:function(){}})})(jQuery);
(function(a,e){var f={},g=0;a.mvc.view={has:function(b){return f[b]!==e},register:function(b,c,d,h){if(typeof b!=="string"){h=d;d=c;c=b;b="mediator-"+ ++g}if(a.mvc.view.has(b))throw"jQuery.mvc.view: A mediator named '"+b+"' already exists.";c=f[b]=new c(b,d,h);a.each(c.notificationInterests,function(j,i){if(a.isFunction(i=c[i]))a.mvc.notifier.register(j,a.mvc.Observer(i,c))});c._register();return c},remove:function(b){if(typeof b==="object")b=b.getName();b=f[b];if(b!==e){a.each(b.notificationInterests,
function(c){a.mvc.notifier.remove(c,b)});delete f[b.getName()];b._remove()}}};a.mvc.mediator=function(b,c,d){if(typeof d==="undefined"){d=c;c=a.mvc.Mediator}return a.mvc.module(b,c,d)};a.mvc.Mediator=a.mvc.module("Mediator",a.mvc.Module,{element:a([]),notificationInterests:{},_createModule:function(b,c,d){d=d||a([]);this.name=b;this.options=a.extend(true,{},this.options,c);this.element=d.jquery===e?a(d):d},_register:function(){},_remove:function(){}})})(jQuery);
(function(a,e){var f={};a.mvc.controller={has:function(g){return f[g]!==e},get:function(g){return a.mvc.controller.has(g)?f[g]:null},register:function(g,b,c){var d;if(a.mvc.controller.has(g))throw"jQuery.mvc.controller: A command is already registered for notifications named '"+name+"'.";d=f[g]=a.mvc.Observer(function(h){(new b(c)).execute(h)},a.mvc.controller);a.mvc.notifier.register(g,d)},remove:function(g){if(f[g]!==e){a.mvc.notifier.remove(g,a.mvc.controller);delete f[g]}}};a.mvc.command=function(g,
b,c){if(typeof c==="undefined"){c=b;b=a.mvc.Command}return a.mvc.module(g,b,c)};a.mvc.Command=a.mvc.module("Command",a.mvc.Module,{execute:function(){}})})(jQuery);
(function(a,e){var f={},g=a({}),b=0;a.mvc.notifier={options:{maxSync:5,delay:10},register:function(c,d){var h=f[c];if(h!==e)h.push(d);else f[c]=[d]},remove:function(c,d){var h=f[c];if(h!==e){for(var j=0,i=h.length;j<i;++j)if(h[j].context==d){h[j]=h[i-1];i-=1;j-=1}if(i===0)delete f[c];else h.length=i}},notify:function(c){var d=f[c.name],h=a.mvc.notifier.options;d!==e&&a.each(d.slice(),function(j,i){g.queue(function(k){i.notify(c);b+=1;if(b>h.maxSync){b=0;setTimeout(k,h.delay)}else k()})})}};a.mvc.Notification=
function(c,d){if(!(this&&this.hasOwnProperty&&this instanceof a.mvc.Notification))return new a.mvc.Notification(c,d);this.name=c;this.body=d};a.mvc.Notification.prototype={name:"notification",body:{}};a.mvc.Observer=function(c,d){if(!(this&&this.hasOwnProperty&&this instanceof a.mvc.Observer))return new a.mvc.Observer(c,d);this.fn=c;this.context=d};a.mvc.Observer.prototype={fn:a.noop,context:{},notify:function(c){this.fn.call(this.context,c)}}})(jQuery);