mirror of https://github.com/apache/archiva.git
sammyjs 0.7.2
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1434425 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1daecccbdd
commit
18dfe3a475
|
@ -33,7 +33,7 @@
|
|||
|
||||
<script type="text/javascript" src="js/jquery-1.9.0.min.js"></script>
|
||||
<script type="text/javascript" src="js/jquery-ui-1.9.2.custom.min.js"></script>
|
||||
<script type="text/javascript" src="js/sammy.0.7.1.js"></script>
|
||||
<script type="text/javascript" src="js/sammy.0.7.2.js"></script>
|
||||
<script type="text/javascript" data-main="js/archiva/archiva.js" src="js/require.2.1.2.js"></script>
|
||||
|
||||
<title>Apache Archiva</title>
|
||||
|
|
|
@ -78,7 +78,7 @@ $.ajax({
|
|||
"tmpl": "tmpl.min",
|
||||
"purl": "purl-2.2.1",
|
||||
"prettify": "prettify",
|
||||
"sammy": "sammy.0.7.1",
|
||||
"sammy": "sammy.0.7.2",
|
||||
"select2": "select2.min-3.2",
|
||||
"jqueryFileTree": "jqueryFileTree-1.0.1",
|
||||
"redback": "redback/redback",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// name: sammy
|
||||
// version: 0.7.1
|
||||
// version: 0.7.2
|
||||
|
||||
// Sammy.js / http://sammyjs.org
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
|||
$.sammy = window.Sammy = factory($);
|
||||
}
|
||||
})(function($){
|
||||
|
||||
var Sammy,
|
||||
PATH_REPLACER = "([^\/]+)",
|
||||
PATH_NAME_MATCHER = /:([\w\d]+)/g,
|
||||
|
@ -30,7 +31,9 @@
|
|||
return String(s).replace(/&(?!\w+;)/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
},
|
||||
_routeWrapper = function(verb) {
|
||||
return function(path, callback) { return this.route.apply(this, [verb, path, callback]); };
|
||||
return function() {
|
||||
return this.route.apply(this, [verb].concat(Array.prototype.slice.call(arguments)));
|
||||
};
|
||||
},
|
||||
_template_cache = {},
|
||||
_has_history = !!(window.history && history.pushState),
|
||||
|
@ -84,7 +87,7 @@
|
|||
}
|
||||
};
|
||||
|
||||
Sammy.VERSION = '0.7.1';
|
||||
Sammy.VERSION = '0.7.2';
|
||||
|
||||
// Add to the global logger pool. Takes a function that accepts an
|
||||
// unknown number of arguments and should print them or send them somewhere
|
||||
|
@ -212,6 +215,17 @@
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
// Return whether the event targets this window.
|
||||
Sammy.targetIsThisWindow = function targetIsThisWindow(event) {
|
||||
var targetWindow = $(event.target).attr('target');
|
||||
if ( targetWindow === '_blank' ) { return false; }
|
||||
if ( targetWindow == null || targetWindow === window.name || targetWindow === '_self' ) { return true; }
|
||||
if ( targetWindow === 'top' && window === window.top ) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// The DefaultLocationProxy is the default location proxy for all Sammy applications.
|
||||
// A location proxy is a prototype that conforms to a simple interface. The purpose
|
||||
// of a location proxy is to notify the Sammy.Application its bound to when the location
|
||||
|
@ -262,6 +276,7 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
if (proxy.is_native === false && !non_native) {
|
||||
proxy.is_native = true;
|
||||
window.clearInterval(lp._interval);
|
||||
lp._interval = null;
|
||||
}
|
||||
app.trigger('location-changed');
|
||||
});
|
||||
|
@ -271,14 +286,14 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
app.trigger('location-changed');
|
||||
});
|
||||
// bind to link clicks that have routes
|
||||
$('a').live('click.history-' + this.app.eventNamespace(), function(e) {
|
||||
if (e.isDefaultPrevented() || e.metaKey || e.ctrlKey) {
|
||||
$(document).delegate('a', 'click.history-' + this.app.eventNamespace(), function (e) {
|
||||
if (e.isDefaultPrevented() || e.metaKey || e.ctrlKey) {
|
||||
return;
|
||||
}
|
||||
var full_path = lp.fullPath(this);
|
||||
if (this.hostname == window.location.hostname &&
|
||||
app.lookupRoute('get', full_path) &&
|
||||
this.target !== '_blank') {
|
||||
Sammy.targetIsThisWindow(e)) {
|
||||
e.preventDefault();
|
||||
proxy.setLocation(full_path);
|
||||
return false;
|
||||
|
@ -295,10 +310,11 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
unbind: function() {
|
||||
$(window).unbind('hashchange.' + this.app.eventNamespace());
|
||||
$(window).unbind('popstate.' + this.app.eventNamespace());
|
||||
$('a').die('click.history-' + this.app.eventNamespace());
|
||||
$(document).undelegate('a', 'click.history-' + this.app.eventNamespace());
|
||||
Sammy.DefaultLocationProxy._bindings--;
|
||||
if (Sammy.DefaultLocationProxy._bindings <= 0) {
|
||||
window.clearInterval(Sammy.DefaultLocationProxy._interval);
|
||||
Sammy.DefaultLocationProxy._interval = null;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -523,7 +539,7 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
}
|
||||
},
|
||||
|
||||
// provide log() override for inside an app that includes the relevant application element_selector
|
||||
// provide log() override for inside an app that includes the relevant application element_selector
|
||||
log: function() {
|
||||
Sammy.log.apply(Sammy, Array.prototype.concat.apply([this.element_selector],arguments));
|
||||
},
|
||||
|
@ -546,14 +562,14 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
// It is also possible to pass a string as the callback, which is looked up as the name
|
||||
// of a method on the application.
|
||||
//
|
||||
route: function(verb, path, callback) {
|
||||
var app = this, param_names = [], add_route, path_match;
|
||||
route: function(verb, path) {
|
||||
var app = this, param_names = [], add_route, path_match, callback = Array.prototype.slice.call(arguments,2);
|
||||
|
||||
// if the method signature is just (path, callback)
|
||||
// assume the verb is 'any'
|
||||
if (!callback && _isFunction(path)) {
|
||||
if (callback.length === 0 && _isFunction(path)) {
|
||||
path = verb;
|
||||
callback = path;
|
||||
callback = [path];
|
||||
verb = 'any';
|
||||
}
|
||||
|
||||
|
@ -574,10 +590,12 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
// replace with the path replacement
|
||||
path = new RegExp(path.replace(PATH_NAME_MATCHER, PATH_REPLACER) + "$");
|
||||
}
|
||||
// lookup callback
|
||||
if (typeof callback == 'string') {
|
||||
callback = app[callback];
|
||||
}
|
||||
// lookup callbacks
|
||||
$.each(callback,function(i,cb){
|
||||
if (typeof(cb) === 'string') {
|
||||
callback[i] = app[cb];
|
||||
}
|
||||
});
|
||||
|
||||
add_route = function(with_verb) {
|
||||
var r = {verb: with_verb, path: path, callback: callback, param_names: param_names};
|
||||
|
@ -799,6 +817,58 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
return this;
|
||||
},
|
||||
|
||||
// Adds a onComplete function to the application. onComplete functions are executed
|
||||
// at the end of a chain of route callbacks, if they call next(). Unlike after,
|
||||
// which is called as soon as the route is complete, onComplete is like a final next()
|
||||
// for all routes, and is thus run asynchronously
|
||||
//
|
||||
// ### Example
|
||||
//
|
||||
// app.get('/chain',function(context,next){
|
||||
// console.log('chain1');
|
||||
// next();
|
||||
// },function(context,next){
|
||||
// console.log('chain2');
|
||||
// next();
|
||||
// });
|
||||
// app.get('/link',function(context,next){
|
||||
// console.log('link1');
|
||||
// next();
|
||||
// },function(context,next){
|
||||
// console.log('link2');
|
||||
// next();
|
||||
// });
|
||||
// app.onComplete(function(){
|
||||
// console.log("Running finally")
|
||||
// });
|
||||
//
|
||||
// If you go to '/chain', you will get the following messages:
|
||||
// chain1
|
||||
// chain2
|
||||
// Running onComplete
|
||||
//
|
||||
//
|
||||
// If you go to /link, you will get the following messages:
|
||||
// link1
|
||||
// link2
|
||||
// Running onComplete
|
||||
//
|
||||
// It really comes to play when doing asynchronous:
|
||||
// app.get('/chain',function(context,next){
|
||||
// $.get('/my/url',function(){
|
||||
// console.log('chain1');
|
||||
// next();
|
||||
// })
|
||||
// },function(context,next){
|
||||
// console.log('chain2');
|
||||
// next();
|
||||
// });
|
||||
//
|
||||
onComplete: function(callback) {
|
||||
this._onComplete = callback;
|
||||
return this;
|
||||
},
|
||||
|
||||
// Returns `true` if the current application is running.
|
||||
isRunning: function() {
|
||||
return this._running;
|
||||
|
@ -906,6 +976,7 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
|
||||
// bind to submit to capture post/put/delete routes
|
||||
this.bind('submit', function(e) {
|
||||
if ( !Sammy.targetIsThisWindow(e) ) { return true; }
|
||||
var returned = app._checkFormSubmission($(e.target).closest('form'));
|
||||
return (returned === false) ? e.preventDefault() : false;
|
||||
});
|
||||
|
@ -940,6 +1011,13 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
return this;
|
||||
},
|
||||
|
||||
// Not only runs `unbind` but also destroys the app reference.
|
||||
destroy: function() {
|
||||
this.unload();
|
||||
delete Sammy.apps[this.element_selector];
|
||||
return this;
|
||||
},
|
||||
|
||||
// Will bind a single callback function to every event that is already
|
||||
// being listened to in the app. This includes all the `APP_EVENTS`
|
||||
// as well as any custom events defined with `bind()`.
|
||||
|
@ -1015,7 +1093,10 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
path_params,
|
||||
final_returned;
|
||||
|
||||
this.log('runRoute', [verb, path].join(' '));
|
||||
if (this.debug) {
|
||||
this.log('runRoute', [verb, path].join(' '));
|
||||
}
|
||||
|
||||
this.trigger('run-route', {verb: verb, path: path, params: params});
|
||||
if (typeof params == 'undefined') { params = {}; }
|
||||
|
||||
|
@ -1047,10 +1128,13 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
arounds = this.arounds.slice(0);
|
||||
befores = this.befores.slice(0);
|
||||
// set the callback args to the context + contents of the splat
|
||||
callback_args = [context].concat(params.splat);
|
||||
callback_args = [context];
|
||||
if (params.splat) {
|
||||
callback_args = callback_args.concat(params.splat);
|
||||
}
|
||||
// wrap the route up with the before filters
|
||||
wrapped_route = function() {
|
||||
var returned;
|
||||
var returned, i, nextRoute;
|
||||
while (befores.length > 0) {
|
||||
before = befores.shift();
|
||||
// check the options
|
||||
|
@ -1061,7 +1145,23 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
}
|
||||
app.last_route = route;
|
||||
context.trigger('event-context-before', {context: context});
|
||||
returned = route.callback.apply(context, callback_args);
|
||||
// run multiple callbacks
|
||||
if (typeof(route.callback) === "function") {
|
||||
route.callback = [route.callback];
|
||||
}
|
||||
if (route.callback && route.callback.length) {
|
||||
i = -1;
|
||||
nextRoute = function() {
|
||||
i++;
|
||||
if (route.callback[i]) {
|
||||
returned = route.callback[i].apply(context,callback_args);
|
||||
} else if (app._onComplete && typeof(app._onComplete === "function")) {
|
||||
app._onComplete(context);
|
||||
}
|
||||
};
|
||||
callback_args.push(nextRoute);
|
||||
nextRoute();
|
||||
}
|
||||
context.trigger('event-context-after', {context: context});
|
||||
return returned;
|
||||
};
|
||||
|
@ -1134,9 +1234,9 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
}
|
||||
// Do we have to match against multiple paths?
|
||||
if (_isArray(options.path)){
|
||||
var results, numopt, opts;
|
||||
var results, numopt, opts, len;
|
||||
results = [];
|
||||
for (numopt in options.path){
|
||||
for (numopt = 0, len = options.path.length; numopt < len; numopt += 1) {
|
||||
opts = $.extend({}, options, {path: options.path[numopt]});
|
||||
results.push(this.contextMatchesOptions(context, opts));
|
||||
}
|
||||
|
@ -1225,7 +1325,7 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
|
||||
// clear the templateCache
|
||||
clearTemplateCache: function() {
|
||||
return _template_cache = {};
|
||||
return (_template_cache = {});
|
||||
},
|
||||
|
||||
// This throws a '404 Not Found' error by invoking `error()`.
|
||||
|
@ -1272,7 +1372,7 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
$_method = $form.find('input[name="_method"]');
|
||||
if ($_method.length > 0) { verb = $_method.val(); }
|
||||
if (!verb) { verb = $form[0].getAttribute('method'); }
|
||||
if (!verb || verb == '') { verb = 'get'; }
|
||||
if (!verb || verb === '') { verb = 'get'; }
|
||||
return $.trim(verb.toString().toLowerCase());
|
||||
},
|
||||
|
||||
|
@ -1282,7 +1382,11 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
$form = $(form);
|
||||
path = $form.attr('action') || '';
|
||||
verb = this._getFormVerb($form);
|
||||
this.log('_checkFormSubmission', $form, path, verb);
|
||||
|
||||
if (this.debug) {
|
||||
this.log('_checkFormSubmission', $form, path, verb);
|
||||
}
|
||||
|
||||
if (verb === 'get') {
|
||||
params = this._serializeFormParams($form);
|
||||
if (params !== '') { path += '?' + params; }
|
||||
|
@ -1712,13 +1816,21 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
if (callback) {
|
||||
$.each(data, function(i, value) {
|
||||
var idata = {}, engine = this.next_engine || location;
|
||||
name ? (idata[name] = value) : (idata = value);
|
||||
if (name) {
|
||||
idata[name] = value;
|
||||
} else {
|
||||
idata = value;
|
||||
}
|
||||
callback(value, rctx.event_context.interpolate(content, idata, engine));
|
||||
});
|
||||
} else {
|
||||
return this.collect(data, function(i, value) {
|
||||
var idata = {}, engine = this.next_engine || location;
|
||||
name ? (idata[name] = value) : (idata = value);
|
||||
if (name) {
|
||||
idata[name] = value;
|
||||
} else {
|
||||
idata = value;
|
||||
}
|
||||
return this.event_context.interpolate(content, idata, engine);
|
||||
}, true);
|
||||
}
|
||||
|
@ -1908,6 +2020,11 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
return new Sammy.RenderContext(this).load(location, options, callback);
|
||||
},
|
||||
|
||||
// create a new `Sammy.RenderContext` calling `loadPartials()` with `partials`.
|
||||
loadPartials: function(partials) {
|
||||
return new Sammy.RenderContext(this).loadPartials(partials);
|
||||
},
|
||||
|
||||
// `render()` the `location` with `data` and then `swap()` the
|
||||
// app's `$element` with the rendered content.
|
||||
partial: function(location, data, callback, partials) {
|
||||
|
@ -2000,4 +2117,4 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
|
|||
|
||||
return Sammy;
|
||||
});
|
||||
})(jQuery, window);
|
||||
})(jQuery, window);
|
Loading…
Reference in New Issue