start-moksha
by Luke Macken
start-moksha | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit 9861e10af4d200ca70135adaf201321a541ae11e
Author: Luke Macken <lmacken(a)redhat.com>
Date: Mon May 11 10:03:02 2009 -0400
Have 'start-moksha' pull down the TurboGears 2.0 final bootstrapper
diff --git a/start-moksha b/start-moksha
index 8fbfbde..7db3e70 100755
--- a/start-moksha
+++ b/start-moksha
@@ -5,7 +5,7 @@ if [ ! $VIRTUAL_ENV ]; then
if [ ! -d tg2env ]; then
echo "Initializing a TurboGears2 virtual environment"
if [ ! -f tg2-bootstrap.py ]; then
- wget http://www.turbogears.org/2.0/downloads/current/tg2-bootstrap.py
+ wget http://www.turbogears.org/2.0/downloads/2.0final/tg2-bootstrap.py
fi
python tg2-bootstrap.py --no-site-packages tg2env
source tg2env/bin/activate
15 years
setup.cfg
by Luke Macken
setup.cfg | 3 +++
1 file changed, 3 insertions(+)
New commits:
commit 0b1e3b8ef3b796ee48f0f9794e9802bb7b103470
Author: Luke Macken <lmacken(a)redhat.com>
Date: Mon May 11 10:02:24 2009 -0400
Add the 'with-pylons' nose configuration back in, because it seems to be crucial.
diff --git a/setup.cfg b/setup.cfg
index 6d798d1..40f0ca8 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -2,6 +2,9 @@
tag_build = dev
tag_svn_revision = true
+[nosetests]
+with-pylons=test.ini
+
[easy_install]
find_links = http://www.pylonshq.com/download/
15 years
3 commits - moksha/lib moksha/middleware moksha/streams moksha/wsgiapp.py setup.cfg
by Luke Macken
moksha/lib/helpers.py | 17 ++++++++++++++++-
moksha/middleware/middleware.py | 27 ++-------------------------
moksha/streams/demo/demostream.py | 7 +++++--
moksha/wsgiapp.py | 16 ++++++++++++++--
setup.cfg | 3 ---
5 files changed, 37 insertions(+), 33 deletions(-)
New commits:
commit e0528280793047005ff0e61edde1af4f2cec3d8b
Author: Luke Macken <lmacken(a)redhat.com>
Date: Mon May 11 09:42:04 2009 -0400
Make all requests go through our MokshaAppDispatcher(PylonsApp).
This ensures that Pylons will setup all of the proper globals,
such as the pylons.request object, etc. This will allow connectors
to utilize the global Beaker cache, instead of creating their own.
It will also allow connectors to utilize other connectors.
diff --git a/moksha/middleware/middleware.py b/moksha/middleware/middleware.py
index 730c5e4..d11b23a 100644
--- a/moksha/middleware/middleware.py
+++ b/moksha/middleware/middleware.py
@@ -51,7 +51,7 @@ class MokshaMiddleware(object):
def __init__(self, application):
log.info('Creating Moksha Middleware')
self.application = application
- self.mokshaapp = MokshaAppDispatcher()
+ self.mokshaapp = MokshaAppDispatcher(application)
moksha.apps = {} # {'app name': tg.TGController/tg.WSGIAppController}
moksha._widgets = {} # {'widget name': tw.api.Widget}
@@ -72,17 +72,7 @@ class MokshaMiddleware(object):
def __call__(self, environ, start_response):
self.register_stomp(environ)
- request = Request(environ)
-
- path = self.strip_script(environ, request.path)
- if path.startswith('/apps/') or \
- path.startswith('/widget') or \
- path.startswith('/docs/') or \
- path.startswith('/moksha_admin/'):
- response = request.get_response(self.mokshaapp)
- else:
- response = request.get_response(self.application)
- return response(environ, start_response)
+ return self.mokshaapp(environ, start_response)
def register_stomp(self, environ):
environ['paste.registry'].register(moksha.stomp, {
diff --git a/moksha/wsgiapp.py b/moksha/wsgiapp.py
index e52be49..4047d4f 100644
--- a/moksha/wsgiapp.py
+++ b/moksha/wsgiapp.py
@@ -16,8 +16,11 @@
#
# Authors: Luke Macken <lmacken(a)redhat.com>
+from pylons import request
from pylons.wsgiapp import PylonsApp
+from moksha.lib.helpers import strip_script
+
class MokshaAppDispatcher(PylonsApp):
""" Moksha WSGI Application Dispatcher.
@@ -27,10 +30,11 @@ class MokshaAppDispatcher(PylonsApp):
"""
root = None
- def __init__(self):
+ def __init__(self, application):
super(MokshaAppDispatcher, self).__init__()
from moksha.controllers.root import RootController
self.root = RootController
+ self.application = application
def resolve(self, environ, start_response):
""" Uses dispatching information found in
@@ -40,4 +44,12 @@ class MokshaAppDispatcher(PylonsApp):
"""
environ['pylons.routes_dict'] = environ['wsgiorg.routing_args'][1]
- return self.root()
+ path = strip_script(environ)
+ if path.startswith('/apps/') or \
+ path.startswith('/widget') or \
+ path.startswith('/docs/') or \
+ path.startswith('/moksha_admin/'):
+ return self.root()
+ else:
+ return self.application
+
commit a2aaa3ad9ee137865da2db0e5f4a880207dab02f
Author: Luke Macken <lmacken(a)redhat.com>
Date: Mon May 11 09:41:26 2009 -0400
Move the strip_script method to moksha.lib.helpers.
Also, remove the request argument, as we can obtain that data
from the environ['PATH_INFO']
diff --git a/moksha/lib/helpers.py b/moksha/lib/helpers.py
index 18ddb2f..757c8b7 100644
--- a/moksha/lib/helpers.py
+++ b/moksha/lib/helpers.py
@@ -875,4 +875,19 @@ class EnumGroup(object):
def __getitem__(self, key):
(category, enum_id) = key.rsplit('.', 1)
enum = self._enums[category]
- return enum.get_data(key)
\ No newline at end of file
+ return enum.get_data(key)
+
+
+def strip_script(environ):
+ """
+ Strips the script portion of a url path so the middleware works even
+ when mounted under a path other than root.
+ """
+ path = environ['PATH_INFO']
+ if path.startswith('/') and 'SCRIPT_NAME' in environ:
+ prefix = environ.get('SCRIPT_NAME')
+ if prefix.endswith('/'):
+ prefix = prefix[:-1]
+ if path.startswith(prefix):
+ path = path[len(prefix):]
+ return path
diff --git a/moksha/middleware/middleware.py b/moksha/middleware/middleware.py
index 5638d86..730c5e4 100644
--- a/moksha/middleware/middleware.py
+++ b/moksha/middleware/middleware.py
@@ -70,19 +70,6 @@ class MokshaMiddleware(object):
moksha.feed_storage = Shove(config['feed_cache'], compress=True)
moksha.feed_cache = Cache(moksha.feed_storage)
- def strip_script(self, environ, path):
- # Strips the script portion of a url path so the middleware works even
- # when mounted under a path other than root
- if path.startswith('/') and 'SCRIPT_NAME' in environ:
- prefix = environ.get('SCRIPT_NAME')
- if prefix.endswith('/'):
- prefix = prefix[:-1]
-
- if path.startswith(prefix):
- path = path[len(prefix):]
-
- return path
-
def __call__(self, environ, start_response):
self.register_stomp(environ)
request = Request(environ)
commit 9166cdc9a76b870cb546d75e2d206d60f88f6435
Author: Luke Macken <lmacken(a)redhat.com>
Date: Mon May 11 05:51:28 2009 -0400
Move our demo's feed initialization into __init__
diff --git a/moksha/streams/demo/demostream.py b/moksha/streams/demo/demostream.py
index e0a2d63..0ed742e 100644
--- a/moksha/streams/demo/demostream.py
+++ b/moksha/streams/demo/demostream.py
@@ -35,10 +35,13 @@ class MokshaDemoDataStream(PollingDataStream):
n = 0
# Feed demo specific variables
- feed = Feed(url='http://doggdot.us/rss')
- feed_entries = feed.entries()
i = 0
+ def __init__(self, *args, **kw):
+ self.feed = Feed(url='http://doggdot.us/rss')
+ self.feed_entries = self.feed.entries()
+ super(MokshaDemoDataStream, self).__init__(*args, **kw)
+
def poll(self):
self.n += 1
diff --git a/setup.cfg b/setup.cfg
index 08503a6..6d798d1 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -5,9 +5,6 @@ tag_svn_revision = true
[easy_install]
find_links = http://www.pylonshq.com/download/
-[nosetests]
-with-pylons=test.ini
-
# Babel configuration
[compile_catalog]
domain = moksha
15 years
moksha/public
by John (J5) Palmieri
moksha/public/javascript/ui/moksha.ui.grid.js | 3 +++
1 file changed, 3 insertions(+)
New commits:
commit fe6df2ae090810133d675882df7c866ee5a02ab1
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Fri May 8 18:31:17 2009 -0400
return an empty string in the numeric pager if there is only one page showing
diff --git a/moksha/public/javascript/ui/moksha.ui.grid.js b/moksha/public/javascript/ui/moksha.ui.grid.js
index 3607526..fa4f2a1 100644
--- a/moksha/public/javascript/ui/moksha.ui.grid.js
+++ b/moksha/public/javascript/ui/moksha.ui.grid.js
@@ -748,6 +748,9 @@
if (total_rows != total_pages * rows_per_page)
total_pages += 1;
+ if (total_pages == 1)
+ return "";
+
var curr_page = parseInt((start_row + 0.5) / rows_per_page) + 1;
var next_page = curr_page + 1;
var pager = $('<ul />');
15 years
moksha/connector
by John (J5) Palmieri
moksha/connector/utils.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
New commits:
commit c0f972bdcd2d24dad8b16a2cc93683837245f077
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Thu May 7 23:19:03 2009 -0400
fixed parameter polution
diff --git a/moksha/connector/utils.py b/moksha/connector/utils.py
index 35c8c6d..0de0b90 100644
--- a/moksha/connector/utils.py
+++ b/moksha/connector/utils.py
@@ -193,7 +193,10 @@ class ParamFilter(object):
self._translation_table = {}
self._param_table = {}
- def add_filter(self, param, args=[], cast=None, allow_none=True, filter_func=None):
+ def add_filter(self, param, args=None, cast=None, allow_none=True, filter_func=None):
+ if args == None:
+ args = []
+
pf = {}
if cast:
assert(isinstance(cast, type),
@@ -205,6 +208,7 @@ class ParamFilter(object):
pf['filter_func'] = filter_func
self._param_table[param] = pf
+
args.append(param)
for a in args:
assert(not(a in self._translation_table),
15 years
moksha/public
by John (J5) Palmieri
moksha/public/javascript/moksha.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit a14b4b1fddd57e14a19de6ce006bcb73a751de01
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Thu May 7 20:19:47 2009 -0400
fix regex
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js
index 6708b23..c2b749a 100644
--- a/moksha/public/javascript/moksha.js
+++ b/moksha/public/javascript/moksha.js
@@ -281,7 +281,7 @@ moksha = {
if(!tag_list.length)
return fragment;
- var body_re = /<(\/)?\s*body.*?>/ig;
+ var body_re = /<\s*body.*?>/ig;
var match = body_re.exec(fragment);
var pos = body_re.lastIndex;
15 years
3 commits - moksha/api start-moksha
by Luke Macken
moksha/api/menus/default.py | 2 +-
start-moksha | 8 +++++---
2 files changed, 6 insertions(+), 4 deletions(-)
New commits:
commit c5c27d6b4181b9cb441c0f36b4f33ac16d3ff36d
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 7 14:59:32 2009 -0400
Use moksha.url in our menu widget
diff --git a/moksha/api/menus/default.py b/moksha/api/menus/default.py
index 5b8f7c8..6b1664b 100644
--- a/moksha/api/menus/default.py
+++ b/moksha/api/menus/default.py
@@ -56,7 +56,7 @@ class MokshaDefaultMenu(MokshaMenu):
.append($('<div/>')
.attr('id', '%(id)s_loader'));
$.ajax({
- url: moksha.csrf_rewrite_url('/widgets/%(id)s?chrome=True'),
+ url: moksha.url('/widgets/%(id)s?chrome=True'),
success: function(r, s) {
var $panel = $('#%(id)s_loader');
var $stripped = moksha.filter_resources(r);
commit 9582fc4b8b56dd4c0a1c0b8eade1071b742cd9f5
Merge: 1474f4e... 7e477ca...
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 7 14:31:40 2009 -0400
Merge branch 'master' of git+ssh://git.fedorahosted.org/git/moksha
commit 1474f4eb21623005753068b727e288f619bec1e8
Author: Luke Macken <lmacken(a)redhat.com>
Date: Wed May 6 21:27:32 2009 -0400
Use TG2's bootstrapping script to setup the virtualenv.
This should make things Just Work for more people, however there are still
dependency issues with Shove & SQLAlchemy. Ideally, we need to get
this whole stack packaged properly: http://fedoraproject.org/wiki/TurboGears2
diff --git a/start-moksha b/start-moksha
index 7667b07..8fbfbde 100755
--- a/start-moksha
+++ b/start-moksha
@@ -4,11 +4,13 @@
if [ ! $VIRTUAL_ENV ]; then
if [ ! -d tg2env ]; then
echo "Initializing a TurboGears2 virtual environment"
- virtualenv --no-site-packages tg2env
+ if [ ! -f tg2-bootstrap.py ]; then
+ wget http://www.turbogears.org/2.0/downloads/current/tg2-bootstrap.py
+ fi
+ python tg2-bootstrap.py --no-site-packages tg2env
source tg2env/bin/activate
- #easy_install -U setuptools
#./pip.py install -E tg2env -r normal-reqs.txt --extra-index-url=http://www.turbogears.org/2.0/downloads/current/index
- easy_install -i http://www.turbogears.org/2.0/downloads/current/index tg.devtools
+ #easy_install -i http://www.turbogears.org/2.0/downloads/current/index tg.devtools
pushd moksha/widgetbrowser; python setup.py develop; popd
else
source tg2env/bin/activate
15 years
moksha/public
by John (J5) Palmieri
moksha/public/javascript/moksha.js | 218 ++++++++++++++++++++++++++-----------
1 file changed, 155 insertions(+), 63 deletions(-)
New commits:
commit 7e477ca9529004322f5ad36e3b27104f8094ae05
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Thu May 7 14:22:36 2009 -0400
fix support for webkit (fedoracommunity bug #136)
* https://fedorahosted.org/fedoracommunity/ticket/136
* moved resource parsing to one method w/ the old scripts and links methods
becoming convinience functions
* resources in HEAD elements are now moved to BODY elements so that we know
for sure they get parsed (resources elsewhere say where they are)
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js
index a93fa54..6708b23 100644
--- a/moksha/public/javascript/moksha.js
+++ b/moksha/public/javascript/moksha.js
@@ -26,8 +26,8 @@ False = false
if (!(typeof(moksha) === 'undefined'))
return;
-var _moksha_page_scripts_cache = {};
-var _moksha_page_links_cache = {};
+var _moksha_resource_cache = {'scripts':{},
+ 'links':{}};
var _moksha_init = false;
// preload cache
@@ -42,8 +42,8 @@ $(document).ready(function(){
var src = $a.attr('src');
// for right now just compare exact source values
// later we will want to be a bit smarter
- if(!_moksha_page_scripts_cache[src]) {
- _moksha_page_scripts_cache[src] = true;
+ if(!_moksha_resource_cache['scripts'][src]) {
+ _moksha_resource_cache['scripts'][src] = true;
}
}
);
@@ -53,8 +53,8 @@ $(document).ready(function(){
var href = $a.attr('href');
// for right now just compare exact source values
// later we will want to be a bit smarter
- if(!_moksha_page_links_cache[href]) {
- _moksha_page_links_cache[href] = true;
+ if(!_moksha_resource_cache['links'][href]) {
+ _moksha_resource_cache['links'][href] = true;
}
}
);
@@ -62,43 +62,115 @@ $(document).ready(function(){
moksha = {
/******************************************************************
- * Filter the script tags in a fragment of HTML so that they aren't
- * double loaded.
+ * Generic method for filtering out resources which have already
+ * been loaded.
+ *
+ * fragment - fragment of HTML text to be filtered ,
+ * tag - the HTML tag you are looking for
+ * resource_attr - the attribute which holds the resource locater
+ * cache_name - the name of the cache to lookup to see if the resource was
+ * loaded
+ *
+ * Since the browser loads the resources we don't actually cache
+ * the contents. We only cache the resource locater. If the same
+ * resource has been loaded already we remove the tag from the
+ * HTML fragment so it is never loaded more than once.
+ *
+ * To work around browser incompatibilities, any resource found
+ * inside the head tag is placed in the body tag to make sure
+ * they are loaded.
******************************************************************/
- filter_scripts: function(fragment) {
- var find_scripts = /<(\/)?\s*script((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/)?>/gmi;
- var find_src_attr = /\s*src\s*=("|')(.*)\1/i;
+ filter_and_cache_resource: function(fragment, tag, resource_attr, cache_name) {
+ var head_pos = moksha.find_head_tags(fragment);
+ function in_head(pos) {
+ for(i in head_pos) {
+ low = head_pos[i][0];
+ high = head_pos[i][1];
+
+ if ((pos > low) && (pos < high))
+ return i;
+ }
+
+ // -1 = not inside of the head tag
+ return -1;
+ }
+
+ function offset_head(index, length) {
+ head_pos[index][1] -= length;
+ for(i=index + 1; i < head_pos.length; i++) {
+ head_pos[index][0] -= length;
+ head_pos[index][1] -= length;
+ }
+ }
+
+ var find_tag = new RegExp("<(/)?\\s*" + tag +
+ "((\\s+\\w+(\\s*=\\s*(?:\".*?\"|'.*?'|[^'\">\\s]+))?)+\\s*|\\s*)(/)?>","gmi");
+ var find_attr = new RegExp("\\s*" + resource_attr +
+ "\\s*=(\"|')(.*)\\1", "i");
+
var find_end_tag_state = null; // if !null then = start tag index
+ var relocate_tag_state = false; // used for relocating resources
+ // from the head to the body
+ var relocate_tag_list = []; // list of tags to relocate
- while ((match = find_scripts.exec(fragment))!=null) {
- var is_self_closing_tag = (match[-1] == '/');
+ while ((match = find_tag.exec(fragment))!=null) {
+ var is_self_closing_tag = (match[match.length-1] == '/');
var is_close_tag = (match[1] == '/') || is_self_closing_tag;
if (is_close_tag && find_end_tag_state) {
+ if (relocate_tag_state)
+ relocate_tag_list.push(fragment.substring(find_end_tag_state,
+ find_tag.lastIndex)
+ );
+
+ var head_index = in_head(find_end_tag_state);
+ if (head_index != -1)
+ offset_head(head_index, find_tag.lastIndex - find_end_tag_state);
+
fragment = (fragment.substring(0, find_end_tag_state) +
- fragment.substring(find_scripts.lastIndex));
+ fragment.substring(find_tag.lastIndex));
- find_scripts.lastIndex = find_end_tag_state;
+ find_tag.lastIndex = find_end_tag_state;
find_end_tag_state = null;
continue;
}
var attrs = match[2];
- var src = attrs.match(find_src_attr);
- if (src){
+ var resource = attrs.match(find_attr);
+ if (resource){
//strip query string
- src = src[2].split('?')[0];
+ resource = resource[2].split('?')[0];
- if(!_moksha_page_scripts_cache[src]) {
+ if(!_moksha_resource_cache[cache_name][resource]) {
// we can add more attributes later
// right now just set to true
- _moksha_page_scripts_cache[src] = true;
+ _moksha_resource_cache[cache_name][resource] = true;
+
+ var head_index = in_head(match.index);
+ if (head_index) {
+ relocate_tag_state = true;
+
+ if (is_self_closing_tag) {
+ offset_head(head_index, find_tag.lastIndex - match.index);
+ fragment = (fragment.substring(0, match.index) +
+ fragment.substring(find_tag.lastIndex));
+ find_tag.lastIndex = match.index;
+
+ relocate_tag_list.push(match[0]);
+ } else {
+ find_end_tag_state = match.index;
+ }
+ }
} else {
if (is_self_closing_tag) {
+ var head_index = in_head(match.index);
+ if (head_index != -1)
+ offset_head(head_index, find_tag.lastIndex - match.index);
+
fragment = (fragment.substring(0, match.index) +
- fragment.substring(find_scripts.lastIndex));
- find_scripts.lastIndex = match.index;
+ fragment.substring(find_tag.lastIndex));
+ find_tag.lastIndex = match.index;
} else {
find_end_tag_state = match.index;
}
@@ -106,55 +178,30 @@ moksha = {
}
}
+ fragment = moksha.relocate_tags_to_body(fragment, relocate_tag_list);
return fragment;
},
/******************************************************************
+ * Filter the script tags in a fragment of HTML so that they aren't
+ * double loaded.
+ ******************************************************************/
+ filter_scripts: function(fragment) {
+ return moksha.filter_and_cache_resource(fragment,
+ 'script',
+ 'src',
+ 'scripts');
+ },
+
+ /******************************************************************
* Filter the link tags in a fragment of HTML so they aren't
* double loaded.
******************************************************************/
filter_links: function(fragment) {
- var find_links = /<(\/)?\s*link((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/)?>/gmi;
- var find_href_attr = /\s*href\s*=("|')(.*)\1/i;
- var find_end_tag_state = null; // if !null then = start tag index
-
- while ((match = find_links.exec(fragment))!=null) {
- var is_self_closing_tag = (match[-1] == '/');
- var is_close_tag = (match[1] == '/') || is_self_closing_tag;
-
- if (is_close_tag && (find_end_tag_state != null)) {
- fragment = (fragment.substring(0, find_end_tag_state) +
- fragment.substring(find_links.lastIndex));
-
- find_links.lastIndex = find_end_tag_state;
- find_end_tag_state = null;
-
- continue;
- }
-
- var attrs = match[2];
- var href = attrs.match(find_href_attr);
- if (href){
- //strip query string
- href = href[2].split('?')[0];
-
- if(!_moksha_page_links_cache[href]) {
- // we can add more attributes later
- // right now just set to true
- _moksha_page_links_cache[href] = true;
- } else {
- if (is_self_closing_tag) {
- fragment = (fragment.substring(0, match.index) +
- fragment.substring(find_links.lastIndex));
- find_links.lastIndex = match.index;
- } else {
- find_end_tag_state = match.index;
- }
- }
- }
- }
-
- return fragment;
+ return moksha.filter_and_cache_resource(fragment,
+ 'link',
+ 'href',
+ 'links');
},
/******************************************************************
@@ -222,10 +269,55 @@ moksha = {
// now we can convert this to a DOM
$f = $(f);
$f = moksha.update_marked_anchors($f);
+
return $f;
},
/********************************************************************
+ * Find the body tag in a fragment and inject the tags in the tag
+ * list there
+ ********************************************************************/
+ relocate_tags_to_body: function(fragment, tag_list) {
+ if(!tag_list.length)
+ return fragment;
+
+ var body_re = /<(\/)?\s*body.*?>/ig;
+ var match = body_re.exec(fragment);
+ var pos = body_re.lastIndex;
+
+ var tag_string = "";
+ for(i in tag_list)
+ tag_string += tag_list[i]
+
+ fragment = fragment.substring(0,pos) + tag_string + fragment.substring(pos);
+
+ return fragment;
+ },
+
+ /********************************************************************
+ * Find the position of all head tags and return them as a list of
+ * two element tuples
+ ********************************************************************/
+ find_head_tags: function(fragment) {
+ var head_re = /<(\/)?\s*head.*?>/ig
+ var results = [];
+ var index = null;
+
+ while((match = head_re.exec(fragment)) != null) {
+ is_closing_tag = (match[1]=='/');
+ if (!is_closing_tag) {
+ index = [match.index,0];
+ } else {
+ index[1] = match.index + match[0].length;
+ results.push(index);
+ index = null;
+ }
+ }
+
+ return results;
+ },
+
+ /********************************************************************
* Take a url and attach the csrf hash if available
********************************************************************/
csrf_rewrite_url: function(url, params) {
15 years
moksha/public
by John (J5) Palmieri
moksha/public/javascript/moksha.js | 119 +++++++++++++++++++++++--------------
1 file changed, 74 insertions(+), 45 deletions(-)
New commits:
commit 029b35f90f4363d8d75f442aac37df65f4c95a57
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Wed May 6 13:07:21 2009 -0400
moved resource stripping to use regex instead of jQuery dom
* resources sometimes load when being placed in a DOM depending on the browser
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js
index e381146..a93fa54 100644
--- a/moksha/public/javascript/moksha.js
+++ b/moksha/public/javascript/moksha.js
@@ -62,67 +62,99 @@ $(document).ready(function(){
moksha = {
/******************************************************************
- * Filter the script tags in a fragment of HTML or jQuery DOM
- * so that they aren't double loaded. You should send in HTML
- * if possible because placing script tags in a jQuery DOM can
- * cause them to load if not done correctly
+ * Filter the script tags in a fragment of HTML so that they aren't
+ * double loaded.
******************************************************************/
filter_scripts: function(fragment) {
- // don't append to a tag, doing so will cause scripts to load
- if (!fragment.jquery)
- fragment = $(fragment);
+ var find_scripts = /<(\/)?\s*script((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/)?>/gmi;
+ var find_src_attr = /\s*src\s*=("|')(.*)\1/i;
+ var find_end_tag_state = null; // if !null then = start tag index
+
+ while ((match = find_scripts.exec(fragment))!=null) {
+ var is_self_closing_tag = (match[-1] == '/');
+ var is_close_tag = (match[1] == '/') || is_self_closing_tag;
+
+ if (is_close_tag && find_end_tag_state) {
+ fragment = (fragment.substring(0, find_end_tag_state) +
+ fragment.substring(find_scripts.lastIndex));
+
+ find_scripts.lastIndex = find_end_tag_state;
+ find_end_tag_state = null;
+
+ continue;
+ }
- var $stripped = [];
- $.each(fragment, function(i, s) {
- var $s = $(s)
- if ($s.is('script[src]')){
- var src = $s.attr('src');
+ var attrs = match[2];
+ var src = attrs.match(find_src_attr);
+ if (src){
//strip query string
- src = src.split('?')[0];
+ src = src[2].split('?')[0];
if(!_moksha_page_scripts_cache[src]) {
// we can add more attributes later
// right now just set to true
_moksha_page_scripts_cache[src] = true;
- $stripped.push(s);
+ } else {
+ if (is_self_closing_tag) {
+ fragment = (fragment.substring(0, match.index) +
+ fragment.substring(find_scripts.lastIndex));
+ find_scripts.lastIndex = match.index;
+ } else {
+ find_end_tag_state = match.index;
+ }
}
- } else {
- $stripped.push(s);
}
- });
+ }
- return $stripped;
+ return fragment;
},
/******************************************************************
- * Filter the link tags in a fragment of HTML or jQuery DOM
- * so that they aren't double loaded.
+ * Filter the link tags in a fragment of HTML so they aren't
+ * double loaded.
******************************************************************/
filter_links: function(fragment) {
- // don't append to a tag, doing so will cause scripts to load
- if (!fragment.jquery)
- fragment = $(fragment);
+ var find_links = /<(\/)?\s*link((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/)?>/gmi;
+ var find_href_attr = /\s*href\s*=("|')(.*)\1/i;
+ var find_end_tag_state = null; // if !null then = start tag index
+
+ while ((match = find_links.exec(fragment))!=null) {
+ var is_self_closing_tag = (match[-1] == '/');
+ var is_close_tag = (match[1] == '/') || is_self_closing_tag;
+
+ if (is_close_tag && (find_end_tag_state != null)) {
+ fragment = (fragment.substring(0, find_end_tag_state) +
+ fragment.substring(find_links.lastIndex));
+
+ find_links.lastIndex = find_end_tag_state;
+ find_end_tag_state = null;
- var $stripped = [];
- $.each(fragment, function(i, s) {
- var $s = $(s)
- if ($s.is('link[href]')){
- var href = $s.attr('href');
+ continue;
+ }
+
+ var attrs = match[2];
+ var href = attrs.match(find_href_attr);
+ if (href){
//strip query string
- href = href.split('?')[0];
+ href = href[2].split('?')[0];
if(!_moksha_page_links_cache[href]) {
// we can add more attributes later
// right now just set to true
_moksha_page_links_cache[href] = true;
- $stripped.push(s);
+ } else {
+ if (is_self_closing_tag) {
+ fragment = (fragment.substring(0, match.index) +
+ fragment.substring(find_links.lastIndex));
+ find_links.lastIndex = match.index;
+ } else {
+ find_end_tag_state = match.index;
+ }
}
- } else {
- $stripped.push(s);
}
- });
+ }
- return $stripped;
+ return fragment;
},
/******************************************************************
@@ -179,19 +211,16 @@ moksha = {
},
/******************************************************************
- * Filter resources in a fragment of HTML or jQuery DOM
- * so that they aren't double loaded. Right now this is only
- * scripts but could be expanded to css and other loaded
- * resource types. You should send in HTML
- * if possible since loading into a jQuery DOM can cause them
- * to load if not done correctly
+ * Filter resources in a fragment of HTML so that they aren't double
+ * loaded. You should send in HTML text since loading into a jQuery
+ * DOM can cause them to load depending on browser
******************************************************************/
filter_resources: function(fragment) {
- if (!fragment.jquery)
- fragment = $(fragment);
+ var f = moksha.filter_scripts(fragment);
+ f = moksha.filter_links(f);
- var $f = moksha.filter_scripts(fragment);
- $f = moksha.filter_links($f);
+ // now we can convert this to a DOM
+ $f = $(f);
$f = moksha.update_marked_anchors($f);
return $f;
},
@@ -292,7 +321,7 @@ moksha = {
*/
parseUri: function (str) {
var options = {
- strictMode: false,
+ strictMode: false,
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
q: {
name: "queryKey",
15 years, 1 month
moksha/public
by John (J5) Palmieri
moksha/public/javascript/ui/moksha.ui.grid.js | 33 +++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
New commits:
commit 31c345918ea28988506a2c506ffd06b85402fd3d
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Tue May 5 18:10:38 2009 -0400
allow controls to be placed outside the containing grid
* grid-control elements can now specify the attach and ancestor attributes
* attach specifies a jQuery selector relative to ancestor
* ancestor specifies an integer which determines how many iterations to walk up
the parent tree relative to the control element. If this is undefined
attach is relative to the whole document. If it is 0 then we are relative
to the grid element (which is pretty useless since you could have placed
the control element instead of having the code do it for you)
* Example:
<div id="second_ancestor">
<h4>title</h4>
<div id="first_ancestor">
<span id="grid-controls" attach="h4:first" ancestor="2">
...
</div>
</div>
this states that all controls inside this span will be moved to the first
H4 which is a child of the second ancestor.
diff --git a/moksha/public/javascript/ui/moksha.ui.grid.js b/moksha/public/javascript/ui/moksha.ui.grid.js
index 077379a..3607526 100644
--- a/moksha/public/javascript/ui/moksha.ui.grid.js
+++ b/moksha/public/javascript/ui/moksha.ui.grid.js
@@ -226,7 +226,7 @@
var self = this;
// get our controls
- var $controls = $('#grid-controls', this.element.parent());
+ var $controls = self._control_list;
// iterate through all of our control plugins
// and get any id that matches
@@ -240,15 +240,42 @@
_init_controls: function() {
var self = this;
+
+ $controls = $('#grid-controls', this.element.parent());
+ self._control_list = $controls;
+
+ $.each($controls, function(i, c) {
+ var $c = $(c);
+ var attach = $c.attr('attach');
+ if (attach) {
+ // attach is a jQuery selector relative to the ancestor
+ // ancestor is specified by an integer indicating how many
+ // levels we should traverse up the parent tree
+ parent_nest = $c.attr('ancestor');
+
+ $parent = $(document);
+ if (typeof(parent_nest) != 'undefined') {
+ $parent = $c;
+ for (var i=0; i<parent_nest; i++) {
+ $parent = $parent.parent();
+ }
+ }
+
+ var $attach_node = $(attach, $parent);
+ $attach_node.append($c);
+ }
+ });
+
var f = function(plugin, i, c) {
// for each matched control call the
// _init method of the plugin if it has one
+ $c = $(c);
+ $c.data('grid.moksha_grid', self);
- $(c).data('grid.moksha_grid', self);
if (plugin._init)
plugin._init.call(plugin,
self,
- $(c));
+ $c);
}
this._foreach_controls(f);
15 years, 1 month