Permalink
Browse files

merged bluedynamics master

  • Loading branch information...
2 parents 91a0c38 + 93f8ed4 commit 04ace4dd7e8d6429eb33a53adf713d98e7ca955b @attilaolah committed Dec 20, 2010
Showing with 127 additions and 88 deletions.
  1. +29 −0 LICENSE.rst
  2. +2 −3 MANIFEST.in
  3. +38 −51 README.rst
  4. +4 −3 setup.py
  5. +54 −31 src/bdajax/resources/bdajax.js
View
@@ -0,0 +1,29 @@
+
+License
+=======
+
+Copyright (c) 2010, BlueDynamics Alliance, Austria
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this
+ list of conditions and the following disclaimer in the documentation and/or
+ other materials provided with the distribution.
+* Neither the name of the BlueDynamics Alliance nor the names of its
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY BlueDynamics Alliance ``AS IS`` AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL BlueDynamics Alliance BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -1,4 +1,3 @@
include *.rst
-include src/bdajax/*.pt
-include src/bdajax/*.zcml
-include src/bdajax/resources/*
+recursive-include src *
+recursive-exclude src *.pyc *.pyo
View
@@ -7,9 +7,7 @@ bdajax provides JavaScript helper functions and a simple dispatcher system
driven by XML-attributes. Attributes are defined in its own XML namespace,
placed in the XHTML markup.
-It provides basically three behaviors:
-
-- call functions
+The dispatcher basically provides two behaviors:
- trigger events
@@ -18,9 +16,10 @@ It provides basically three behaviors:
Each behavior is bound to a JavaScript event.
This package bundles required resources for the use of bdajax inside a
-``repoze.bfg`` or ``zope`` application. It does NOT include the required server
-implementations. bdajax can be used with other Python or non-Python server
-backends too.
+``repoze.bfg/pyramid`` or ``zope`` application. It does NOT include the
+required server implementations. bdajax can be used with other Python or
+non-Python server backends too as long as action performing code is implemented
+and available through browser URL.
Dispatching
-----------
@@ -49,13 +48,6 @@ ajax:bind="evt1 evt2"
Indicate bdajax behavior on DOM element and the event(s) triggering
it/them.
-WARNING: Calling functions appeared to be useless, will be removed in future!
-
-ajax:call="function1:selector1 function2:selector2"
- Call function(s). Each function gets passed a jQuery iterator of
- selector and target object. Target object provides ``url`` and
- ``params``.
-
ajax:event="evt1:sel1 evt2:sel2"
Trigger event(s) on selector. The triggered event gets the target
as additional parameter on event.ajaxtarget.
@@ -98,7 +90,7 @@ Load dependent JavaScripts and CSS in HTML header
<link href="http://fubar.com/++resource++bdajax/bdajax.css"
rel="stylesheet" type="text/css" media="screen" />
-Check if the contents of ``bdajax.pt`` is rendered.
+Make sure the contents of ``bdajax.pt`` are rendered.
Define namespace
----------------
@@ -125,33 +117,6 @@ Indicate bdajax behavior on DOM element.
Binds this element to events ``keydown`` and ``click``.
-
-Calling functions
------------------
-
-WARNING: Calling functions appeared to be useless, will be removed in future!
-
-Provide the function to be called.
-::
-
- somefunc = function(iter, target) {
- // do something
- }
-
-Bind call behavior to DOM element
-::
-
- <a href="http://fubar.com"
- ajax:bind="click"
- ajax:call="somefunc:.someclass"
- ajax:target="http://fubar.com">
- fubar
- </a>
-
-On click ``somefunction`` is called. It get an iterator passed, in this case
-``jQuery('.someclass')``, and a target object containing ``url`` and ``params``
-if ``ajax:target`` is set.
-
Trigger events
--------------
@@ -236,16 +201,14 @@ Bind multiple behaviors to the same DOM element
<a href="http://fubar.com/baz?a=a"
ajax:bind="click"
- ajax:call="somefunc:.someclass"
ajax:event="contextchanged:.contextsensitiv"
ajax:action="rendersomething:.#something:replace"
ajax:target="http://fubar.com/baz?a=a">
fubar
</a>
-In this example on click function ``somefunc`` is called. Event
-``contextchanged`` is triggered and action ``rendersomething`` is performed.
-
+In this example on click event ``contextchanged`` is triggered and action
+``rendersomething`` is performed.
JavaScript helpers
==================
@@ -370,6 +333,9 @@ Options:
``error`` (optional)
Callback if request fails.
+Success and error callback functions are wrapped in ``bdajax.request`` to
+consider ajax spinner handling automatically.
+
Perform action manually
-----------------------
@@ -434,15 +400,17 @@ results in a call every time bdajax hooks some markup.
Browsers
========
-bdajax is tested in:
+bdajax is tested with:
- - Firefox 3.5
+ - Firefox 3.5, 3.6
+
+ - IE 7, 8
- - IE 7
+ - Chome 7
- - to be continued...
+ - Safari 5
+
-
Contributors
============
@@ -452,6 +420,24 @@ Contributors
Changes
=======
+1.0.1
+-----
+
+ - add spinner handling
+ [rnix, 2010-12-13]
+
+ - return jquery context by ``jQuery.bdajax``
+ [rnix, 2010-12-13]
+
+1.0
+---
+
+ - remove call behaviour
+ [rnix, 2010-12-04]
+
+ - browser testing
+ [rnix, 2010-12-04]
+
1.0b4
-----
@@ -497,4 +483,5 @@ Changes
-----
- make it work
- [rnix]
+ [rnix]
+
View
@@ -1,19 +1,20 @@
from setuptools import setup, find_packages
import sys, os
-version = '1.0b4'
+version = '1.0.1'
shortdesc = 'Ajax convenience.'
longdesc = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
+longdesc += open(os.path.join(os.path.dirname(__file__), 'LICENSE.rst')).read()
setup(name='bdajax',
version=version,
description=shortdesc,
long_description=longdesc,
classifiers=[
- 'Development Status :: 4 - Beta',
+ 'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Operating System :: OS Independent',
- 'Programming Language :: Python',
+ 'Programming Language :: JavaScript',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
keywords='',
@@ -1,16 +1,13 @@
+/*
+ * bdajax
+ *
+ * Requires: jquery tools
+ */
+
(function($) {
$(document).ready(function() {
- var spinner = $('#ajax-spinner');
- spinner.hide();
- /*
- spinner.ajaxStart(function() {
- $(this).show();
- });
- spinner.ajaxStop(function() {
- $(this).hide();
- });
- */
+ bdajax.spinner.hide(true);
$(document).bdajax(document);
});
@@ -31,24 +28,55 @@
if (ajax.attr('ajax:event')) {
ajax.bind(events, bdajax._event_handler);
}
- // 'ajax:call' is deprecated
- if (ajax.attr('ajax:call')) {
- ajax.bind(events, bdajax._call_handler);
- }
-
}
}
}
});
for (var binder in bdajax.binders) {
bdajax.binders[binder](context);
}
+ return context;
}
bdajax = {
+ // object for 3rd party binders
binders: {},
+ // ajax spinner handling
+ spinner: {
+
+ _elem: null,
+ _request_count: 0,
+
+ elem: function() {
+ if (bdajax.spinner._elem == null) {
+ bdajax.spinner._elem = $('#ajax-spinner');
+ }
+ return bdajax.spinner._elem;
+ },
+
+ show: function() {
+ bdajax.spinner._request_count++;
+ if (bdajax.spinner._request_count > 1) {
+ return;
+ }
+ bdajax.spinner.elem().show();
+ },
+
+ hide: function(force) {
+ bdajax.spinner._request_count--;
+ if (force) {
+ bdajax.spinner._request_count = 0;
+ bdajax.spinner.elem().hide();
+ return;
+ } else if (bdajax.spinner._request_count <= 0) {
+ bdajax.spinner._request_count = 0;
+ bdajax.spinner.elem().hide();
+ }
+ }
+ },
+
ajaxerrors: {
timeout: 'The request has timed out. Pleasae try again.',
error: 'An error occoured while processing the request. Aborting.',
@@ -112,12 +140,21 @@
}
}
if (!config.cache) { config.cache = false; }
+ var wrapped_success = function(data, status, request) {
+ config.success(data, status, request);
+ bdajax.spinner.hide();
+ }
+ var wrapped_error = function(request, status, error) {
+ config.error(request, status, error);
+ bdajax.spinner.hide(true);
+ }
+ bdajax.spinner.show();
$.ajax({
url: config.url,
dataType: config.type,
data: config.params,
- success: config.success,
- error: config.error,
+ success: wrapped_success,
+ error: wrapped_error,
cache: config.cache
});
},
@@ -250,20 +287,6 @@
elem.data('overlay').load();
},
- // 'ajax:call' is deprecated
- _call_handler: function(event) {
- event.preventDefault();
- var elem = $(this);
- var target = bdajax.parsetarget(elem.attr('ajax:target'));
- var defs = bdajax._defs_to_array(elem.attr('ajax:call'));
- for (var i = 0; i < defs.length; i++) {
- var def = defs[i];
- def = def.split(':');
- func = eval(def[0]);
- func($(def[1]), target);
- }
- },
-
_event_handler: function(event) {
event.preventDefault();
var elem = $(this);

0 comments on commit 04ace4d

Please sign in to comment.