From 665e9f8d5b16665caf3c72fe435c55b23d08a49a Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 8 Nov 2013 10:14:04 +0100 Subject: [PATCH 01/30] [FIX] website snippet: image resizing with img-responsive and rte editor bzr revid: chm@openerp.com-20131108091404-uz42809mycr9cqy3 --- addons/website/views/snippets.xml | 56 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/addons/website/views/snippets.xml b/addons/website/views/snippets.xml index d10eee50f1d..67f21ac5401 100644 --- a/addons/website/views/snippets.xml +++ b/addons/website/views/snippets.xml @@ -109,7 +109,7 @@

- +
@@ -126,7 +126,7 @@
- +

A Section Subtitle

@@ -243,7 +243,7 @@

A Punchy Headline

- +

@@ -277,7 +277,7 @@

And a good subtitle

- +

Streamline Recruitments

Post job offers and keep track of each application @@ -290,7 +290,7 @@

- +

Enterprise Social Network

Break down information silos. Share knowledge and best @@ -302,7 +302,7 @@

- +

Leaves Management

Keep track of the vacation days accrued by each @@ -382,19 +382,19 @@

More than 500 successful projects

- - - + + +
- - - + + +
- - - + + +
@@ -415,28 +415,28 @@

More than 500 successful projects

- +
- +
- +
- +
- +
- +
- +
- +
@@ -650,19 +650,19 @@
- +
- +
- +
- +
- +
From 1e9df02682d84a4d9e012c18c4abdcf083b92a08 Mon Sep 17 00:00:00 2001 From: ddm Date: Fri, 8 Nov 2013 15:38:48 +0100 Subject: [PATCH 02/30] [FIX] tour has been fixed bzr revid: ddm@openerp.com-20131108143848-eg0xulyeggjs4tts --- .../website/static/src/js/website.snippets.js | 21 ++++++++++--------- .../static/src/js/website.tour.basic.js | 11 +++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/addons/website/static/src/js/website.snippets.js b/addons/website/static/src/js/website.snippets.js index 6a9c4039e97..8032d688a82 100644 --- a/addons/website/static/src/js/website.snippets.js +++ b/addons/website/static/src/js/website.snippets.js @@ -22,8 +22,9 @@ window.snippets = this.snippets = new website.snippet.BuildingBlock(this); this.snippets.appendTo(this.$el); - this.rte.on('rte:ready', this, function () { + this.on('rte:ready', this, function () { self.snippets.$button.removeClass("hidden"); + self.trigger('rte:snippets_ready'); }); return this._super.apply(this, arguments); @@ -52,7 +53,7 @@ }); /* ----- SNIPPET SELECTOR ---- */ - + website.snippet = {}; var observer = new website.Observer(function (mutations) { if (!_(mutations).find(function (m) { @@ -504,7 +505,7 @@ console.debug( "A good node must have a [data-oe-model] attribute or must have at least one parent with [data-oe-model] attribute."); console.debug( "Wrong node(s): ", selector); } - + function is_visible($el){ return $el.css('display') != 'none' && $el.css('opacity') != '0' @@ -519,7 +520,7 @@ var parents = $(this).parents().filter(function(){ return !is_visible($(this)); }); return parents.length === 0; }); - + $targets.each(function () { var $target = $(this); if (!$target.data('overlay')) { @@ -558,13 +559,13 @@ start: function () { }, /* onFocusEdit - * if they are an editor for this data-snippet-id + * if they are an editor for this data-snippet-id * Called before onFocus of snippet editor */ onFocusEdit : function () {}, /* onBlurEdit - * if they are an editor for this data-snippet-id + * if they are an editor for this data-snippet-id * Called after onBlur of snippet editor */ onBlurEdit : function () {}, @@ -665,7 +666,7 @@ }); $("body").addClass('move-important'); - + self._drag_and_drop_after_insert_dropzone(); self._drag_and_drop_active_drop_zone($('.oe_drop_zone')); }, @@ -855,7 +856,7 @@ if (!resize_values.s) $box.find(".oe_handle.s").remove(); if (!resize_values.e) $box.find(".oe_handle.e").remove(); if (!resize_values.w) $box.find(".oe_handle.w").remove(); - + this.$overlay.append($box.find(".oe_handles").html()); this.$overlay.find(".oe_handle").on('mousedown', function (event){ @@ -1111,7 +1112,7 @@ var index = $active.index(); this.$target.find('.carousel-control, .carousel-indicators').removeClass("hidden"); this.$indicators.append('
  • '); - + var $clone = this.$el.find(".item.active").clone(); var bg = this.$editor.find('ul[name="carousel-background"] li:not([data-value="'+ $active.css("background-image").replace(/.*:\/\/[^\/]+|\)$/g, '') +'"]):first').data("value"); $clone.css("background-image", "url('"+ bg +"')"); @@ -1216,7 +1217,7 @@ var $li = $ul.find("li"); var $parallax = this.$target.find('.parallax'); var speed = $parallax.data('stellar-background-ratio') || 0.5 ; - + $ul.find('[data-value="' + speed + '"]').addClass('active'); $li.on('click', function (event) { $li.removeClass("active"); diff --git a/addons/website/static/src/js/website.tour.basic.js b/addons/website/static/src/js/website.tour.basic.js index 876d2a7b5b9..649317b8cfc 100644 --- a/addons/website/static/src/js/website.tour.basic.js +++ b/addons/website/static/src/js/website.tour.basic.js @@ -24,10 +24,14 @@ stepId: 'edit-page', element: 'button[data-action=edit]', placement: 'bottom', - reflex: true, title: "Edit this page", content: "Every page of your website can be modified through the Edit button.", template: render('website.tour_popover'), + onShow: function () { + editor.on('rte:snippets_ready', editor, function() { + self.movetoStep('add-block'); + }); + }, }, { stepId: 'add-block', @@ -37,11 +41,6 @@ content: "To add content in a page, you can insert building blocks.", template: render('website.tour_popover'), onShow: function () { - function refreshAddBlockStep () { - self.tour.showStep(self.indexOfStep('add-block')); - editor.off('rte:ready', editor, refreshAddBlockStep); - } - editor.on('rte:ready', editor, refreshAddBlockStep); $('button[data-action=snippet]').click(function () { self.movetoStep('drag-banner'); }); From 01a414fb7cebedb67e0ce203af67ba7eca455697 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 8 Nov 2013 14:26:15 +0100 Subject: [PATCH 03/30] [ADD] initial route introspection + fix pair of routes/controllers * most controllers turn out to be complete cork and thus can't be reversed * fixup a pair of simple controllers TODO: * fixup more controllers * how can labels/page names be produced? * grouping/categories of links? At a high level, workings are pretty simple: * iterate on all rules (every url pattern produces a werkzeug rule) * check if the url can make sense as a link: GET, http, no auth or public auth, coming from the CMS (no web client links) and all converters can generate values for themselves (e.g. a url with an `int` converter can't be generated as there is no finite set of integers, let alone one small enough to make sense to show to users) * check if the controller function bound to the URL can use the URLs we can generate (no **kwargs as that means arbitrary get|post parameter, no query param without a default value (a query param is a parameter which does not come from a URL/rule converter)) * use rule converter(s) to generate a matrix of values, and build urls from these bzr revid: xmo@openerp.com-20131108132615-2n7t1vj8hz9v9eis --- addons/website/controllers/main.py | 2 +- addons/website/models/website.py | 101 ++++++++++++++++-- .../controllers/main.py | 6 +- 3 files changed, 94 insertions(+), 15 deletions(-) diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index d9384e2a6ca..f5a72790153 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -281,7 +281,7 @@ class Website(openerp.addons.web.controllers.main.Home): return request.make_response(body, headers=[('Content-Type', 'text/plain')]) @website.route('/sitemap', type='http', auth='public', multilang=True) - def sitemap(self, **kwargs): + def sitemap(self): return request.website.render('website.sitemap', {'pages': request.website.list_pages()}) @website.route('/sitemap.xml', type='http', auth="public") diff --git a/addons/website/models/website.py b/addons/website/models/website.py index d0328e2182b..e257e3b1844 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -1,29 +1,34 @@ # -*- coding: utf-8 -*- import fnmatch import functools +import inspect import logging import math -import simplejson +import itertools import traceback import urllib import urlparse +import simplejson import werkzeug import werkzeug.exceptions import werkzeug.wrappers import openerp from openerp.exceptions import AccessError, AccessDenied -from openerp.osv import osv, fields +from openerp.osv import orm, osv, fields from openerp.tools.safe_eval import safe_eval + from openerp.addons.web import http from openerp.addons.web.http import request + logger = logging.getLogger(__name__) def route(routes, *route_args, **route_kwargs): def decorator(f): new_routes = routes if isinstance(routes, list) else [routes] + f.cms = True f.multilang = route_kwargs.get('multilang', False) if f.multilang: route_kwargs.pop('multilang') @@ -257,6 +262,64 @@ class website(osv.osv): ] } + + def rule_is_enumerable(self, rule): + """ Checks that it is possible to generate sensible GET queries for + a given rule (if the endpoint matches its own requirements) + + :type rule: werkzeug.routing.Rule + :rtype: bool + """ + endpoint = rule.endpoint + methods = rule.methods or ['GET'] + + return ( + 'GET' in methods + and endpoint.exposed == 'http' + and endpoint.auth in ('none', 'public') + and getattr(endpoint, 'cms', False) + # ensure all converters on the rule are able to generate values for + # themselves + and all(hasattr(converter, 'generate') + for converter in rule._converters.itervalues()) + ) and self.endpoint_is_enumerable(rule) + + def endpoint_is_enumerable(self, rule): + """ Verifies that it's possible to generate a valid url for the rule's + endpoint + + :type rule: werkzeug.routing.Rule + :rtype: bool + """ + + # apparently the decorator package makes getargspec work correctly + # on functions it decorates. That's not the case for + # @functools.wraps, so hack around to get the original function + # (and hope a single decorator was applied or we're hosed) + # FIXME: this is going to blow up if we want/need to use multiple @route (with various configurations) on a method + undecorated_func = rule.endpoint.func_closure[0].cell_contents + + # If this is ever ported to py3, use signatures, it doesn't suck as much + spec = inspect.getargspec(undecorated_func) + + # if *args or **kwargs, just bail the fuck out, only dragons can + # live there + if spec.varargs or spec.keywords: + return False + + # remove all arguments with a default value from the list + defaults_count = len(spec.defaults or []) # spec.defaults can be None + # a[:-0] ~ a[:0] ~ [] -> replace defaults_count == 0 by None to get + # a[:None] ~ a + args = spec.args[:(-defaults_count or None)] + + # params with defaults were removed, leftover allowed are: + # * self (technically should be first-parameter-of-instance-method but whatever) + # * any parameter mapping to a converter + return all( + (arg == 'self' or arg in rule._converters) + for arg in args) + def list_pages(self, cr, uid, ids, context=None): """ Available pages in the website/CMS. This is mostly used for links generation and can be overridden by modules setting up new HTML @@ -269,16 +332,32 @@ class website(osv.osv): of the same. :rtype: list({name: str, url: str}) """ - View = self.pool['ir.ui.view'] - views = View.search_read(cr, uid, [['page', '=', True]], - fields=['name'], order='name', context=context) - xids = View.get_external_id(cr, uid, [view['id'] for view in views], context=context) - return [ - {'name': view['name'], 'url': '/page/' + xids[view['id']]} - for view in views - if xids[view['id']] - ] + router = request.httprequest.app.get_db_router(request.db) + + for rule in router.iter_rules(): + endpoint = rule.endpoint + if not self.rule_is_enumerable(rule): + continue + + generated = map(dict, itertools.product(*( + itertools.izip(itertools.repeat(name), converter.generate()) + for name, converter in rule._converters.iteritems() + ))) + + for values in generated: + name = endpoint.__name__ + record = next((item for item in values.values() if isinstance(item, orm.browse_record)), + None) + if record: + #name = record.display_name + [(_, record_name)] = record.name_get() + name = u"%s: %s" % (name, record_name) + yield { + 'name': name, + # rule.build returns (domain_part, rel_url) + 'url': rule.build(values, append_unknown=False)[1] + } def kanban(self, cr, uid, ids, model, domain, column, template, step=None, scope=None, orderby=None, context=None): step = step and int(step) or 10 diff --git a/addons/website_hr_recruitment/controllers/main.py b/addons/website_hr_recruitment/controllers/main.py index beca795e7e7..83836040c74 100644 --- a/addons/website_hr_recruitment/controllers/main.py +++ b/addons/website_hr_recruitment/controllers/main.py @@ -11,7 +11,7 @@ import base64 class website_hr_recruitment(http.Controller): @website.route(['/jobs', '/jobs/page//', '/department//', '/department//page//'], type='http', auth="public", multilang=True) - def jobs(self, id=0, page=1, **post): + def jobs(self, id=0, page=1): id = id and int(id) or 0 hr_job_obj = request.registry['hr.job'] hr_department_obj = request.registry['hr.department'] @@ -51,7 +51,7 @@ class website_hr_recruitment(http.Controller): return request.website.render("website_hr_recruitment.index", values) @website.route(['/job/detail/'], type='http', auth="public", multilang=True) - def detail(self, job=None, **kwargs): + def detail(self, job): values = { 'job': job, 'vals_date': job.write_date.split(' ')[0], @@ -77,7 +77,7 @@ class website_hr_recruitment(http.Controller): return request.website.render("website_hr_recruitment.thankyou", values) @website.route(['/apply/'], type='http', auth="public", multilang=True) - def applyjobpost(self, job=None, **kwargs): + def applyjobpost(self, job): return request.website.render("website_hr_recruitment.applyjobpost", { 'job': job }) @website.route('/job/publish', type='json', auth="admin", multilang=True) From 3abd06ffe06c34151dfefc457630f636906f203b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 8 Nov 2013 15:21:49 +0100 Subject: [PATCH 04/30] [FIX] blog controller to suck less and be more compatible with routes introspection Routes introspection fixes: * convert to * remove **kw, specify explicit enable_editor parameter Suckless: * remove useless `/blog/tag/` route * add pagination support in tags * add pagination support when no category or tag (`/blog/`) * remove handling of impossible case of category *and* tag * make exclusive cases more exclusive, avoid repeatedly checking the same condition over and over bzr revid: xmo@openerp.com-20131108142149-v2z2m6kwgf97o7b0 --- addons/website_blog/controllers/main.py | 81 ++++++++++--------------- 1 file changed, 32 insertions(+), 49 deletions(-) diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py index 989565941dd..599e71cafcf 100644 --- a/addons/website_blog/controllers/main.py +++ b/addons/website_blog/controllers/main.py @@ -35,24 +35,23 @@ class WebsiteBlog(http.Controller): @website.route([ '/blog/', - '/blog//', - '/blog//page//', - '/blog/cat//', - '/blog/cat//page//', - '/blog/tag/', - '/blog/tag//', + '/blog/page//', + '/blog//', + '/blog//page//', + '/blog/cat//', + '/blog/cat//page//', + '/blog/tag//', + '/blog/tag//page//', ], type='http', auth="public", multilang=True) - def blog(self, category_id=None, blog_post_id=None, tag_id=None, page=1, **post): + def blog(self, category=None, blog_post=None, tag=None, page=1, enable_editor=None): """ Prepare all values to display the blog. - :param integer category_id: id of the category currently browsed. - :param integer tag_id: id of the tag that is currently used to filter - blog posts - :param integer blog_post_id: ID of the blog post currently browsed. If not - set, the user is browsing the category and - a post pager is calculated. If set the user - is reading the blog post and a comments pager - is calculated. + :param category: category currently browsed. + :param tag: tag that is currently used to filter blog posts + :param blog_post: blog post currently browsed. If not set, the user is + browsing the category and a post pager is calculated. + If set the user is reading the blog post and a + comments pager is calculated. :param integer page: current page of the pager. Can be the category or post pager. :param dict post: kwargs, may contain @@ -73,44 +72,40 @@ class WebsiteBlog(http.Controller): """ cr, uid, context = request.cr, request.uid, request.context blog_post_obj = request.registry['blog.post'] - tag_obj = request.registry['blog.tag'] category_obj = request.registry['blog.category'] - tag = None - category = None - blog_post = None blog_posts = None - pager = None nav = {} category_ids = category_obj.search(cr, uid, [], context=context) categories = category_obj.browse(cr, uid, category_ids, context=context) - if tag_id: - tag = tag_obj.browse(cr, uid, tag_id, context=context) - if category_id: - category = category_obj.browse(cr, uid, category_id, context=context) - elif blog_post_id: - blog_post = blog_post_obj.browse(cr, uid, blog_post_id, context=context) - blog_message_ids = blog_post.website_message_ids + if blog_post: category = blog_post.category_id - category_id = category.id - - if not blog_post_id: - if category and tag: - blog_posts = [cat_post for cat_post in category.blog_post_ids - if tag_id in [post_tag.id for post_tag in cat_post.tag_ids]] - elif category: + pager = request.website.pager( + url="/blog/%s/" % blog_post.id, + total=len(blog_post.website_message_ids), + page=page, + step=self._post_comment_per_page, + scope=7 + ) + pager_begin = (page - 1) * self._post_comment_per_page + pager_end = page * self._post_comment_per_page + blog_post.website_message_ids = blog_post.website_message_ids[pager_begin:pager_end] + else: + if category: + pager_url = "/blog/cat/%s/" % category.id blog_posts = category.blog_post_ids elif tag: + pager_url = '/blog/tag/%s/' % tag.id blog_posts = tag.blog_post_ids else: + pager_url = '/blog/' blog_post_ids = blog_post_obj.search(cr, uid, [], context=context) blog_posts = blog_post_obj.browse(cr, uid, blog_post_ids, context=context) - if blog_posts: pager = request.website.pager( - url="/blog/cat/%s/" % category_id, + url=pager_url, total=len(blog_posts), page=page, step=self._category_post_per_page, @@ -120,18 +115,6 @@ class WebsiteBlog(http.Controller): pager_end = page * self._category_post_per_page blog_posts = blog_posts[pager_begin:pager_end] - if blog_post: - pager = request.website.pager( - url="/blog/%s/" % blog_post_id, - total=len(blog_message_ids), - page=page, - step=self._post_comment_per_page, - scope=7 - ) - pager_begin = (page - 1) * self._post_comment_per_page - pager_end = page * self._post_comment_per_page - blog_post.website_message_ids = blog_post.website_message_ids[pager_begin:pager_end] - for group in blog_post_obj.read_group(cr, uid, [], ['name', 'create_date'], groupby="create_date", orderby="create_date asc", context=context): year = group['create_date'].split(" ")[1] if not year in nav: @@ -147,7 +130,7 @@ class WebsiteBlog(http.Controller): 'blog_posts': blog_posts, 'pager': pager, 'nav_list': nav, - 'enable_editor': post.get('enable_editor') + 'enable_editor': enable_editor, } if blog_post: From ff7316b89ba327b4866c37f20878c6a25243fa0e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 8 Nov 2013 15:51:42 +0100 Subject: [PATCH 05/30] [ADD] small comment bzr revid: xmo@openerp.com-20131108145142-px3947qa1apy8gwd --- addons/website_blog/controllers/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py index 599e71cafcf..d15c78eabb1 100644 --- a/addons/website_blog/controllers/main.py +++ b/addons/website_blog/controllers/main.py @@ -75,7 +75,6 @@ class WebsiteBlog(http.Controller): category_obj = request.registry['blog.category'] blog_posts = None - nav = {} category_ids = category_obj.search(cr, uid, [], context=context) categories = category_obj.browse(cr, uid, category_ids, context=context) @@ -115,7 +114,9 @@ class WebsiteBlog(http.Controller): pager_end = page * self._category_post_per_page blog_posts = blog_posts[pager_begin:pager_end] + nav = {} for group in blog_post_obj.read_group(cr, uid, [], ['name', 'create_date'], groupby="create_date", orderby="create_date asc", context=context): + # FIXME: vietnamese month names contain spaces. Set sail for fail. year = group['create_date'].split(" ")[1] if not year in nav: nav[year] = {'name': year, 'create_date_count': 0, 'months': []} From ecce1f0f4df6c1ec5b42197268d4615304431310 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 8 Nov 2013 16:00:25 +0100 Subject: [PATCH 06/30] [FIX] website snippets parallax: remove lib and add custom code to fix editor and reduce code bzr revid: chm@openerp.com-20131108150025-xlqoygvkz7122gru --- addons/website/static/lib/stellar/LICENSE-MIT | 20 - addons/website/static/lib/stellar/README.md | 308 -------- .../website/static/lib/stellar/component.json | 8 - addons/website/static/lib/stellar/grunt.js | 71 -- .../static/lib/stellar/jquery.stellar.js | 660 ------------------ .../static/lib/stellar/jquery.stellar.min.js | 2 - .../website/static/lib/stellar/package.json | 46 -- .../static/lib/stellar/stellar.jquery.json | 29 - addons/website/static/src/css/website.css | 3 +- addons/website/static/src/css/website.sass | 3 +- .../website/static/src/js/website.snippets.js | 85 ++- addons/website/views/snippets.xml | 8 +- addons/website/views/website_templates.xml | 1 - 13 files changed, 63 insertions(+), 1181 deletions(-) delete mode 100644 addons/website/static/lib/stellar/LICENSE-MIT delete mode 100644 addons/website/static/lib/stellar/README.md delete mode 100644 addons/website/static/lib/stellar/component.json delete mode 100644 addons/website/static/lib/stellar/grunt.js delete mode 100644 addons/website/static/lib/stellar/jquery.stellar.js delete mode 100644 addons/website/static/lib/stellar/jquery.stellar.min.js delete mode 100644 addons/website/static/lib/stellar/package.json delete mode 100644 addons/website/static/lib/stellar/stellar.jquery.json diff --git a/addons/website/static/lib/stellar/LICENSE-MIT b/addons/website/static/lib/stellar/LICENSE-MIT deleted file mode 100644 index b590574757d..00000000000 --- a/addons/website/static/lib/stellar/LICENSE-MIT +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2013 Mark Dalgleish - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/addons/website/static/lib/stellar/README.md b/addons/website/static/lib/stellar/README.md deleted file mode 100644 index e87107d87b2..00000000000 --- a/addons/website/static/lib/stellar/README.md +++ /dev/null @@ -1,308 +0,0 @@ -[![Build Status](https://secure.travis-ci.org/markdalgleish/stellar.js.png)](http://travis-ci.org/markdalgleish/stellar.js) - -# Stellar.js - -### Parallax scrolling made easy - -Full guide and demonstrations available at the [official Stellar.js project page](http://markdalgleish.com/projects/stellar.js/). - -## Download - -Get the [development](https://raw.github.com/markdalgleish/stellar.js/master/jquery.stellar.js) or [production](https://raw.github.com/markdalgleish/stellar.js/master/jquery.stellar.min.js) version, or use a [package manager](https://github.com/markdalgleish/stellar.js#package-managers). - -## Getting Started - -Stellar.js is a jQuery plugin that provides parallax scrolling effects to any scrolling element. The first step is to run `.stellar()` against the element: - -``` js -// For example: -$(window).stellar(); -// or: -$('#main').stellar(); -``` - -If you're running Stellar.js on 'window', you can use the shorthand: - -``` js -$.stellar(); -``` - -This will look for any parallax backgrounds or elements within the specified element and reposition them when the element scrolls. - -## Mobile Support - -Support in Mobile WebKit browsers requires a touch scrolling library, and a slightly tweaked configuration. For a full walkthrough on how to implement this correctly, read my blog post ["Mobile Parallax with Stellar.js"](http://markdalgleish.com/2012/10/mobile-parallax-with-stellar-js). - -Please note that parallax backgrounds are not recommended in Mobile WebKit due to performance constraints. Instead, use parallax elements with static backgrounds. - -## Parallax Elements - -If you want elements to scroll at a different speed, add the following attribute to any element with a CSS position of absolute, relative or fixed: - -``` html -
    -``` - -The ratio is relative to the natural scroll speed, so a ratio of 0.5 would cause the element to scroll at half-speed, a ratio of 1 would have no effect, and a ratio of 2 would cause the element to scroll at twice the speed. If a ratio lower than 1 is causing the element to appear jittery, try setting its CSS position to fixed. - -In order for Stellar.js to perform its calculations correctly, all parallax elements must have their dimensions specified in pixels for the axis/axes being used for parallax effects. For example, all parallax elements for a vertical site must have a pixel height specified. If your design prohibits the use of pixels, try using the ['responsive' option](#configuring-everything). - -## Parallax Backgrounds - -If you want an element's background image to reposition on scroll, simply add the following attribute: - -``` html -
    -``` - -As with parallax elements, the ratio is relative to the natural scroll speed. For ratios lower than 1, to avoid jittery scroll performance, set the element's CSS 'background-attachment' to fixed. - -## Configuring Offsets - -Stellar.js' most powerful feature is the way it aligns elements. - -All elements will return to their original positioning when their offset parent meets the edge of the screen—plus or minus your own optional offset. This allows you to create intricate parallax patterns very easily. - -Confused? [See how offsets are used on the Stellar.js home page.](http://markdalgleish.com/projects/stellar.js/#show-offsets) - -To modify the offsets for all elements at once, pass in the options: - -``` js -$.stellar({ - horizontalOffset: 40, - verticalOffset: 150 -}); -``` - -You can also modify the offsets on a per-element basis using the following data attributes: - -``` html -
    -``` - -## Configuring Offset Parents - -By default, offsets are relative to the element's offset parent. This mirrors the way an absolutely positioned element behaves when nested inside an element with a relative position. - -As with regular CSS, the closest parent element with a position of relative or absolute is the offset parent. - -To override this and force the offset parent to be another element higher up the DOM, use the following data attribute: - -``` html -
    -``` - -The offset parent can also have its own offsets: - -``` html -
    -``` - -Similar to CSS, the rules take precedence from element, to offset parent, to JavaScript options. - -Confused? [See how offset parents are used on the Stellar.js home page.](http://markdalgleish.com/projects/stellar.js/#show-offset-parents) - -Still confused? [See what it looks like with its default offset parents.](http://markdalgleish.com/projects/stellar.js/#show-offset-parents-default) Notice how the alignment happens on a per-letter basis? That's because each letter's containing div is its default offset parent. - -By specifying the h2 element as the offset parent, we can ensure that the alignment of all the stars in a heading is based on the h2 and not the div further down the DOM tree. - -## Configuring Scroll Positioning - -You can define what it means for an element to 'scroll'. Whether it's the element's scroll position that's changing, its margins or its CSS3 'transform' position, you can define it using the 'scrollProperty' option: - -``` js -$('#gallery').stellar({ - scrollProperty: 'transform' -}); -``` - -This option is what allows you to run [Stellar.js on iOS](http://markdalgleish.com/projects/stellar.js/demos/ios.html). - -You can even define how the elements are repositioned, whether it's through standard top and left properties or using CSS3 transforms: - -``` js -$('#gallery').stellar({ - positionProperty: 'transform' -}); -``` - -Don't have the level of control you need? Write a plugin! - -Otherwise, you're ready to get started! - -## Configuring Everything - -Below you will find a complete list of options and matching default values: - -``` js -$.stellar({ - // Set scrolling to be in either one or both directions - horizontalScrolling: true, - verticalScrolling: true, - - // Set the global alignment offsets - horizontalOffset: 0, - verticalOffset: 0, - - // Refreshes parallax content on window load and resize - responsive: false, - - // Select which property is used to calculate scroll. - // Choose 'scroll', 'position', 'margin' or 'transform', - // or write your own 'scrollProperty' plugin. - scrollProperty: 'scroll', - - // Select which property is used to position elements. - // Choose between 'position' or 'transform', - // or write your own 'positionProperty' plugin. - positionProperty: 'position', - - // Enable or disable the two types of parallax - parallaxBackgrounds: true, - parallaxElements: true, - - // Hide parallax elements that move outside the viewport - hideDistantElements: true, - - // Customise how elements are shown and hidden - hideElement: function($elem) { $elem.hide(); }, - showElement: function($elem) { $elem.show(); } -}); -``` - -## Writing a Scroll Property Plugin - -Out of the box, Stellar.js supports the following scroll properties: -'scroll', 'position', 'margin' and 'transform'. - -If your method for creating a scrolling interface isn't covered by one of these, you can write your own. For example, if 'margin' didn't exist yet you could write it like so: - -``` js -$.stellar.scrollProperty.margin = { - getLeft: function($element) { - return parseInt($element.css('margin-left'), 10) * -1; - }, - getTop: function($element) { - return parseInt($element.css('margin-top'), 10) * -1; - } -} -``` - -Now, you can specify this scroll property in Stellar.js' configuration. - -``` js -$.stellar({ - scrollProperty: 'margin' -}); -``` - -## Writing a Position Property Plugin - -Stellar.js has two methods for positioning elements built in: 'position' for modifying its top and left properties, and 'transform' for using CSS3 transforms. - -If you need more control over how elements are positioned, you can write your own setter functions. For example, if 'position' didn't exist yet, it could be written as a plugin like this: - -``` js -$.stellar.positionProperty.position = { - setTop: function($element, newTop, originalTop) { - $element.css('top', newTop); - }, - setLeft: function($element, newLeft, originalLeft) { - $element.css('left', newLeft); - } -} -``` - -Now, you can specify this position property in Stellar.js' configuration. - -``` js -$.stellar({ - positionProperty: 'position' -}); -``` - -If, for technical reasons, you need to set both properties at once, you can define a single 'setPosition' function: - -``` js -$.stellar.positionProperty.foobar = { - setPosition: function($element, newLeft, originalLeft, newTop, originalTop) { - $element.css('transform', 'translate3d(' + - (newLeft - originalLeft) + 'px, ' + - (newTop - originalTop) + 'px, ' + - '0)'); - } -} - -$.stellar({ - positionProperty: 'foobar' -}); -``` - -## Package Managers - -Stellar.js can be installed with [Bower](http://twitter.github.com/bower/): - -``` bash -$ bower install jquery.stellar -``` - -## Sites Using Stellar.js - -* [National Geographic - Alien Deep Interactive](http://channel.nationalgeographic.com/channel/alien-deep/interactives/alien-deep-interactive) -* [François Hollande](http://www.parti-socialiste.fr/latimelineduchangement) -* [Brabus Private Aviation](http://www.brabus-aviation.com/) -* [Mary and Frankie's Wedding](http://www.maryandfrankiewedding.com/) -* [IT Support London](http://www.itsupportlondon.com) -* [Ashford University](http://bright.ashford.edu) -* [Clif Adventures](http://www.clifbar.com/adventures) -* [Mindster](http://www.mindster.org) -* [WS Interactive](http://www.ws-interactive.fr/methode) -* [Moire Mag - Untitled](http://www.moiremag.net/untitled) -* [Carnival of Courage](http://www.carnivalofcourage.com.au) -* [Ian Poulter](http://www.ianpoulter.com) -* [360 Strategy Group](http://360strategygroup.com) -* [Code, Love and Boards](http://codeloveandboards.com/) - -I'm sure there are heaps more. [Let me know if you'd like me to feature your site here.](http://twitter.com/markdalgleish) - -## How to Build - -Stellar.js uses [Node.js](nodejs.org), [Grunt](http://gruntjs.com) and [PhantomJS](http://phantomjs.org/). - -Once you've got Node and PhantomJS set up, install the dependencies: - -`$ npm install` - -To lint, test and minify the project, simply run the following command: - -`$ grunt` - -Each of the build steps are also available individually. - -`$ grunt test` to test the code using QUnit and PhantomJS: - -`$ grunt lint` to validate the code using JSHint. - -`$ grunt watch` to continuously lint and test the code while developing. - -## Contributing to Stellar.js - -Ensure that you successfully test and build the project with `$ grunt` before committing. - -Make sure that all plugin changes are made in `src/jquery.stellar.js` (`/jquery.stellar.js` and `/jquery.stellar.min.js` are generated by Grunt). - -If you want to contribute in a way that changes the API, please file an issue before submitting a pull request so we can discuss how to appropriately integrate your ideas. - -## Questions? - -Contact me on GitHub or Twitter: [@markdalgleish](http://twitter.com/markdalgleish) - -## License - -Copyright 2013, Mark Dalgleish -This content is released under the MIT license -http://markdalgleish.mit-license.org diff --git a/addons/website/static/lib/stellar/component.json b/addons/website/static/lib/stellar/component.json deleted file mode 100644 index f4b651386b7..00000000000 --- a/addons/website/static/lib/stellar/component.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "jquery.stellar", - "version": "0.6.2", - "main": ["./jquery.stellar.js"], - "dependencies": { - "jquery": ">=1.4.3" - } -} \ No newline at end of file diff --git a/addons/website/static/lib/stellar/grunt.js b/addons/website/static/lib/stellar/grunt.js deleted file mode 100644 index 114348d92ac..00000000000 --- a/addons/website/static/lib/stellar/grunt.js +++ /dev/null @@ -1,71 +0,0 @@ -/*global module:false*/ -module.exports = function(grunt) { - - // Project configuration. - grunt.initConfig({ - pkg: '', - meta: { - banner: '/*!\n' + - ' * <%= pkg.title || pkg.name %> v<%= pkg.version %>\n' + - ' * <%= pkg.homepage %>\n' + - ' * \n' + - ' * Copyright <%= grunt.template.today("yyyy") %>, <%= pkg.author.name %>\n' + - ' * This content is released under the <%= _.pluck(pkg.licenses, "type").join(", ") %> license<%= pkg.licenses.length === 1 ? "" : "s" %>\n' + - ' * <%= _.pluck(pkg.licenses, "url").join(", ") %>\n' + - ' */', - microbanner: '/*! <%= pkg.title || pkg.name %> v<%= pkg.version %> | Copyright <%= grunt.template.today("yyyy") %>, <%= pkg.author.name %> | <%= pkg.homepage %> | <%= _.pluck(pkg.licenses, "url").join(", ") %> */' - }, - lint: { - files: ['grunt.js', 'test/**/*.js', 'src/**/*.js'] - }, - server: { - port: 8573 - }, - qunit: { - urls: ['1.4.3', '1.10.1', '2.0.2'].map(function(version) { - return 'http://localhost:<%= server.port %>/test/jquery.stellar.html?jquery=' + version; - }) - }, - concat: { - dist: { - src: ['', '.js>'], - dest: '<%= pkg.name %>.js' - } - }, - min: { - dist: { - src: ['', ''], - dest: '<%= pkg.name %>.min.js' - } - }, - watch: { - files: '', - tasks: 'server lint qunit' - }, - jshint: { - options: { - evil: true, - curly: false, - eqeqeq: true, - immed: true, - latedef: true, - newcap: true, - noarg: true, - sub: true, - undef: true, - boss: true, - browser: true - }, - globals: { - jQuery: true - } - }, - uglify: {} - }); - - // Default task. - grunt.registerTask('default', 'server lint qunit concat min'); - - grunt.registerTask('test', 'server lint qunit'); - -}; diff --git a/addons/website/static/lib/stellar/jquery.stellar.js b/addons/website/static/lib/stellar/jquery.stellar.js deleted file mode 100644 index a64c8153000..00000000000 --- a/addons/website/static/lib/stellar/jquery.stellar.js +++ /dev/null @@ -1,660 +0,0 @@ -/*! - * Stellar.js v0.6.2 - * http://markdalgleish.com/projects/stellar.js - * - * Copyright 2013, Mark Dalgleish - * This content is released under the MIT license - * http://markdalgleish.mit-license.org - */ - -;(function($, window, document, undefined) { - - var pluginName = 'stellar', - defaults = { - scrollProperty: 'scroll', - positionProperty: 'position', - horizontalScrolling: true, - verticalScrolling: true, - horizontalOffset: 0, - verticalOffset: 0, - responsive: false, - parallaxBackgrounds: true, - parallaxElements: true, - hideDistantElements: true, - hideElement: function($elem) { $elem.hide(); }, - showElement: function($elem) { $elem.show(); } - }, - - scrollProperty = { - scroll: { - getLeft: function($elem) { return $elem.scrollLeft(); }, - setLeft: function($elem, val) { $elem.scrollLeft(val); }, - - getTop: function($elem) { return $elem.scrollTop(); }, - setTop: function($elem, val) { $elem.scrollTop(val); } - }, - position: { - getLeft: function($elem) { return parseInt($elem.css('left'), 10) * -1; }, - getTop: function($elem) { return parseInt($elem.css('top'), 10) * -1; } - }, - margin: { - getLeft: function($elem) { return parseInt($elem.css('margin-left'), 10) * -1; }, - getTop: function($elem) { return parseInt($elem.css('margin-top'), 10) * -1; } - }, - transform: { - getLeft: function($elem) { - var computedTransform = getComputedStyle($elem[0])[prefixedTransform]; - return (computedTransform !== 'none' ? parseInt(computedTransform.match(/(-?[0-9]+)/g)[4], 10) * -1 : 0); - }, - getTop: function($elem) { - var computedTransform = getComputedStyle($elem[0])[prefixedTransform]; - return (computedTransform !== 'none' ? parseInt(computedTransform.match(/(-?[0-9]+)/g)[5], 10) * -1 : 0); - } - } - }, - - positionProperty = { - position: { - setLeft: function($elem, left) { $elem.css('left', left); }, - setTop: function($elem, top) { $elem.css('top', top); } - }, - transform: { - setPosition: function($elem, left, startingLeft, top, startingTop) { - $elem[0].style[prefixedTransform] = 'translate3d(' + (left - startingLeft) + 'px, ' + (top - startingTop) + 'px, 0)'; - } - } - }, - - // Returns a function which adds a vendor prefix to any CSS property name - vendorPrefix = (function() { - var prefixes = /^(Moz|Webkit|Khtml|O|ms|Icab)(?=[A-Z])/, - style = $('script')[0].style, - prefix = '', - prop; - - for (prop in style) { - if (prefixes.test(prop)) { - prefix = prop.match(prefixes)[0]; - break; - } - } - - if ('WebkitOpacity' in style) { prefix = 'Webkit'; } - if ('KhtmlOpacity' in style) { prefix = 'Khtml'; } - - return function(property) { - return prefix + (prefix.length > 0 ? property.charAt(0).toUpperCase() + property.slice(1) : property); - }; - }()), - - prefixedTransform = vendorPrefix('transform'), - - supportsBackgroundPositionXY = $('
    ', { style: 'background:#fff' }).css('background-position-x') !== undefined, - - setBackgroundPosition = (supportsBackgroundPositionXY ? - function($elem, x, y) { - $elem.css({ - 'background-position-x': x, - 'background-position-y': y - }); - } : - function($elem, x, y) { - $elem.css('background-position', x + ' ' + y); - } - ), - - getBackgroundPosition = (supportsBackgroundPositionXY ? - function($elem) { - return [ - $elem.css('background-position-x'), - $elem.css('background-position-y') - ]; - } : - function($elem) { - return $elem.css('background-position').split(' '); - } - ), - - requestAnimFrame = ( - window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame || - function(callback) { - setTimeout(callback, 1000 / 60); - } - ); - - function Plugin(element, options) { - this.element = element; - this.options = $.extend({}, defaults, options); - - this._defaults = defaults; - this._name = pluginName; - - this.init(); - } - - Plugin.prototype = { - init: function() { - this.options.name = pluginName + '_' + Math.floor(Math.random() * 1e9); - - this._defineElements(); - this._defineGetters(); - this._defineSetters(); - this._handleWindowLoadAndResize(); - this._detectViewport(); - - this.refresh({ firstLoad: true }); - - if (this.options.scrollProperty === 'scroll') { - this._handleScrollEvent(); - } else { - this._startAnimationLoop(); - } - }, - _defineElements: function() { - if (this.element === document.body) this.element = window; - this.$scrollElement = $(this.element); - this.$element = (this.element === window ? $('body') : this.$scrollElement); - this.$viewportElement = (this.options.viewportElement !== undefined ? $(this.options.viewportElement) : (this.$scrollElement[0] === window || this.options.scrollProperty === 'scroll' ? this.$scrollElement : this.$scrollElement.parent()) ); - }, - _defineGetters: function() { - var self = this, - scrollPropertyAdapter = scrollProperty[self.options.scrollProperty]; - - this._getScrollLeft = function() { - return scrollPropertyAdapter.getLeft(self.$scrollElement); - }; - - this._getScrollTop = function() { - return scrollPropertyAdapter.getTop(self.$scrollElement); - }; - }, - _defineSetters: function() { - var self = this, - scrollPropertyAdapter = scrollProperty[self.options.scrollProperty], - positionPropertyAdapter = positionProperty[self.options.positionProperty], - setScrollLeft = scrollPropertyAdapter.setLeft, - setScrollTop = scrollPropertyAdapter.setTop; - - this._setScrollLeft = (typeof setScrollLeft === 'function' ? function(val) { - setScrollLeft(self.$scrollElement, val); - } : $.noop); - - this._setScrollTop = (typeof setScrollTop === 'function' ? function(val) { - setScrollTop(self.$scrollElement, val); - } : $.noop); - - this._setPosition = positionPropertyAdapter.setPosition || - function($elem, left, startingLeft, top, startingTop) { - if (self.options.horizontalScrolling) { - positionPropertyAdapter.setLeft($elem, left, startingLeft); - } - - if (self.options.verticalScrolling) { - positionPropertyAdapter.setTop($elem, top, startingTop); - } - }; - }, - _handleWindowLoadAndResize: function() { - var self = this, - $window = $(window); - - if (self.options.responsive) { - $window.bind('load.' + this.name, function() { - self.refresh(); - }); - } - - $window.bind('resize.' + this.name, function() { - self._detectViewport(); - - if (self.options.responsive) { - self.refresh(); - } - }); - }, - refresh: function(options) { - var self = this, - oldLeft = self._getScrollLeft(), - oldTop = self._getScrollTop(); - - if (!options || !options.firstLoad) { - this._reset(); - } - - this._setScrollLeft(0); - this._setScrollTop(0); - - this._setOffsets(); - this._findParticles(); - this._findBackgrounds(); - - // Fix for WebKit background rendering bug - if (options && options.firstLoad && /WebKit/.test(navigator.userAgent)) { - $(window).load(function() { - var oldLeft = self._getScrollLeft(), - oldTop = self._getScrollTop(); - - self._setScrollLeft(oldLeft + 1); - self._setScrollTop(oldTop + 1); - - self._setScrollLeft(oldLeft); - self._setScrollTop(oldTop); - }); - } - - this._setScrollLeft(oldLeft); - this._setScrollTop(oldTop); - }, - _detectViewport: function() { - var viewportOffsets = this.$viewportElement.offset(), - hasOffsets = viewportOffsets !== null && viewportOffsets !== undefined; - - this.viewportWidth = this.$viewportElement.width(); - this.viewportHeight = this.$viewportElement.height(); - - this.viewportOffsetTop = (hasOffsets ? viewportOffsets.top : 0); - this.viewportOffsetLeft = (hasOffsets ? viewportOffsets.left : 0); - }, - _findParticles: function() { - var self = this, - scrollLeft = this._getScrollLeft(), - scrollTop = this._getScrollTop(); - - if (this.particles !== undefined) { - for (var i = this.particles.length - 1; i >= 0; i--) { - this.particles[i].$element.data('stellar-elementIsActive', undefined); - } - } - - this.particles = []; - - if (!this.options.parallaxElements) return; - - this.$element.find('[data-stellar-ratio]').each(function(i) { - var $this = $(this), - horizontalOffset, - verticalOffset, - positionLeft, - positionTop, - marginLeft, - marginTop, - $offsetParent, - offsetLeft, - offsetTop, - parentOffsetLeft = 0, - parentOffsetTop = 0, - tempParentOffsetLeft = 0, - tempParentOffsetTop = 0; - - // Ensure this element isn't already part of another scrolling element - if (!$this.data('stellar-elementIsActive')) { - $this.data('stellar-elementIsActive', this); - } else if ($this.data('stellar-elementIsActive') !== this) { - return; - } - - self.options.showElement($this); - - // Save/restore the original top and left CSS values in case we refresh the particles or destroy the instance - if (!$this.data('stellar-startingLeft')) { - $this.data('stellar-startingLeft', $this.css('left')); - $this.data('stellar-startingTop', $this.css('top')); - } else { - $this.css('left', $this.data('stellar-startingLeft')); - $this.css('top', $this.data('stellar-startingTop')); - } - - positionLeft = $this.position().left; - positionTop = $this.position().top; - - // Catch-all for margin top/left properties (these evaluate to 'auto' in IE7 and IE8) - marginLeft = ($this.css('margin-left') === 'auto') ? 0 : parseInt($this.css('margin-left'), 10); - marginTop = ($this.css('margin-top') === 'auto') ? 0 : parseInt($this.css('margin-top'), 10); - - offsetLeft = $this.offset().left - marginLeft; - offsetTop = $this.offset().top - marginTop; - - // Calculate the offset parent - $this.parents().each(function() { - var $this = $(this); - - if ($this.data('stellar-offset-parent') === true) { - parentOffsetLeft = tempParentOffsetLeft; - parentOffsetTop = tempParentOffsetTop; - $offsetParent = $this; - - return false; - } else { - tempParentOffsetLeft += $this.position().left; - tempParentOffsetTop += $this.position().top; - } - }); - - // Detect the offsets - horizontalOffset = ($this.data('stellar-horizontal-offset') !== undefined ? $this.data('stellar-horizontal-offset') : ($offsetParent !== undefined && $offsetParent.data('stellar-horizontal-offset') !== undefined ? $offsetParent.data('stellar-horizontal-offset') : self.horizontalOffset)); - verticalOffset = ($this.data('stellar-vertical-offset') !== undefined ? $this.data('stellar-vertical-offset') : ($offsetParent !== undefined && $offsetParent.data('stellar-vertical-offset') !== undefined ? $offsetParent.data('stellar-vertical-offset') : self.verticalOffset)); - - // Add our object to the particles collection - self.particles.push({ - $element: $this, - $offsetParent: $offsetParent, - isFixed: $this.css('position') === 'fixed', - horizontalOffset: horizontalOffset, - verticalOffset: verticalOffset, - startingPositionLeft: positionLeft, - startingPositionTop: positionTop, - startingOffsetLeft: offsetLeft, - startingOffsetTop: offsetTop, - parentOffsetLeft: parentOffsetLeft, - parentOffsetTop: parentOffsetTop, - stellarRatio: ($this.data('stellar-ratio') !== undefined ? $this.data('stellar-ratio') : 1), - width: $this.outerWidth(true), - height: $this.outerHeight(true), - isHidden: false - }); - }); - }, - _findBackgrounds: function() { - var self = this, - scrollLeft = this._getScrollLeft(), - scrollTop = this._getScrollTop(), - $backgroundElements; - - this.backgrounds = []; - - if (!this.options.parallaxBackgrounds) return; - - $backgroundElements = this.$element.find('[data-stellar-background-ratio]'); - - if (this.$element.data('stellar-background-ratio')) { - $backgroundElements = $backgroundElements.add(this.$element); - } - - $backgroundElements.each(function() { - var $this = $(this), - backgroundPosition = getBackgroundPosition($this), - horizontalOffset, - verticalOffset, - positionLeft, - positionTop, - marginLeft, - marginTop, - offsetLeft, - offsetTop, - $offsetParent, - parentOffsetLeft = 0, - parentOffsetTop = 0, - tempParentOffsetLeft = 0, - tempParentOffsetTop = 0; - - // Ensure this element isn't already part of another scrolling element - if (!$this.data('stellar-backgroundIsActive')) { - $this.data('stellar-backgroundIsActive', this); - } else if ($this.data('stellar-backgroundIsActive') !== this) { - return; - } - - // Save/restore the original top and left CSS values in case we destroy the instance - if (!$this.data('stellar-backgroundStartingLeft')) { - $this.data('stellar-backgroundStartingLeft', backgroundPosition[0]); - $this.data('stellar-backgroundStartingTop', backgroundPosition[1]); - } else { - setBackgroundPosition($this, $this.data('stellar-backgroundStartingLeft'), $this.data('stellar-backgroundStartingTop')); - } - - // Catch-all for margin top/left properties (these evaluate to 'auto' in IE7 and IE8) - marginLeft = ($this.css('margin-left') === 'auto') ? 0 : parseInt($this.css('margin-left'), 10); - marginTop = ($this.css('margin-top') === 'auto') ? 0 : parseInt($this.css('margin-top'), 10); - - offsetLeft = $this.offset().left - marginLeft - scrollLeft; - offsetTop = $this.offset().top - marginTop - scrollTop; - - // Calculate the offset parent - $this.parents().each(function() { - var $this = $(this); - - if ($this.data('stellar-offset-parent') === true) { - parentOffsetLeft = tempParentOffsetLeft; - parentOffsetTop = tempParentOffsetTop; - $offsetParent = $this; - - return false; - } else { - tempParentOffsetLeft += $this.position().left; - tempParentOffsetTop += $this.position().top; - } - }); - - // Detect the offsets - horizontalOffset = ($this.data('stellar-horizontal-offset') !== undefined ? $this.data('stellar-horizontal-offset') : ($offsetParent !== undefined && $offsetParent.data('stellar-horizontal-offset') !== undefined ? $offsetParent.data('stellar-horizontal-offset') : self.horizontalOffset)); - verticalOffset = ($this.data('stellar-vertical-offset') !== undefined ? $this.data('stellar-vertical-offset') : ($offsetParent !== undefined && $offsetParent.data('stellar-vertical-offset') !== undefined ? $offsetParent.data('stellar-vertical-offset') : self.verticalOffset)); - - self.backgrounds.push({ - $element: $this, - $offsetParent: $offsetParent, - isFixed: $this.css('background-attachment') === 'fixed', - horizontalOffset: horizontalOffset, - verticalOffset: verticalOffset, - startingValueLeft: backgroundPosition[0], - startingValueTop: backgroundPosition[1], - startingBackgroundPositionLeft: (isNaN(parseInt(backgroundPosition[0], 10)) ? 0 : parseInt(backgroundPosition[0], 10)), - startingBackgroundPositionTop: (isNaN(parseInt(backgroundPosition[1], 10)) ? 0 : parseInt(backgroundPosition[1], 10)), - startingPositionLeft: $this.position().left, - startingPositionTop: $this.position().top, - startingOffsetLeft: offsetLeft, - startingOffsetTop: offsetTop, - parentOffsetLeft: parentOffsetLeft, - parentOffsetTop: parentOffsetTop, - stellarRatio: ($this.data('stellar-background-ratio') === undefined ? 1 : $this.data('stellar-background-ratio')) - }); - }); - }, - _reset: function() { - var particle, - startingPositionLeft, - startingPositionTop, - background, - i; - - for (i = this.particles.length - 1; i >= 0; i--) { - particle = this.particles[i]; - startingPositionLeft = particle.$element.data('stellar-startingLeft'); - startingPositionTop = particle.$element.data('stellar-startingTop'); - - this._setPosition(particle.$element, startingPositionLeft, startingPositionLeft, startingPositionTop, startingPositionTop); - - this.options.showElement(particle.$element); - - particle.$element.data('stellar-startingLeft', null).data('stellar-elementIsActive', null).data('stellar-backgroundIsActive', null); - } - - for (i = this.backgrounds.length - 1; i >= 0; i--) { - background = this.backgrounds[i]; - - background.$element.data('stellar-backgroundStartingLeft', null).data('stellar-backgroundStartingTop', null); - - setBackgroundPosition(background.$element, background.startingValueLeft, background.startingValueTop); - } - }, - destroy: function() { - this._reset(); - - this.$scrollElement.unbind('resize.' + this.name).unbind('scroll.' + this.name); - this._animationLoop = $.noop; - - $(window).unbind('load.' + this.name).unbind('resize.' + this.name); - }, - _setOffsets: function() { - var self = this, - $window = $(window); - - $window.unbind('resize.horizontal-' + this.name).unbind('resize.vertical-' + this.name); - - if (typeof this.options.horizontalOffset === 'function') { - this.horizontalOffset = this.options.horizontalOffset(); - $window.bind('resize.horizontal-' + this.name, function() { - self.horizontalOffset = self.options.horizontalOffset(); - }); - } else { - this.horizontalOffset = this.options.horizontalOffset; - } - - if (typeof this.options.verticalOffset === 'function') { - this.verticalOffset = this.options.verticalOffset(); - $window.bind('resize.vertical-' + this.name, function() { - self.verticalOffset = self.options.verticalOffset(); - }); - } else { - this.verticalOffset = this.options.verticalOffset; - } - }, - _repositionElements: function() { - var scrollLeft = this._getScrollLeft(), - scrollTop = this._getScrollTop(), - horizontalOffset, - verticalOffset, - particle, - fixedRatioOffset, - background, - bgLeft, - bgTop, - isVisibleVertical = true, - isVisibleHorizontal = true, - newPositionLeft, - newPositionTop, - newOffsetLeft, - newOffsetTop, - i; - - // First check that the scroll position or container size has changed - if (this.currentScrollLeft === scrollLeft && this.currentScrollTop === scrollTop && this.currentWidth === this.viewportWidth && this.currentHeight === this.viewportHeight) { - return; - } else { - this.currentScrollLeft = scrollLeft; - this.currentScrollTop = scrollTop; - this.currentWidth = this.viewportWidth; - this.currentHeight = this.viewportHeight; - } - - // Reposition elements - for (i = this.particles.length - 1; i >= 0; i--) { - particle = this.particles[i]; - - fixedRatioOffset = (particle.isFixed ? 1 : 0); - - // Calculate position, then calculate what the particle's new offset will be (for visibility check) - if (this.options.horizontalScrolling) { - newPositionLeft = (scrollLeft + particle.horizontalOffset + this.viewportOffsetLeft + particle.startingPositionLeft - particle.startingOffsetLeft + particle.parentOffsetLeft) * -(particle.stellarRatio + fixedRatioOffset - 1) + particle.startingPositionLeft; - newOffsetLeft = newPositionLeft - particle.startingPositionLeft + particle.startingOffsetLeft; - } else { - newPositionLeft = particle.startingPositionLeft; - newOffsetLeft = particle.startingOffsetLeft; - } - - if (this.options.verticalScrolling) { - newPositionTop = (scrollTop + particle.verticalOffset + this.viewportOffsetTop + particle.startingPositionTop - particle.startingOffsetTop + particle.parentOffsetTop) * -(particle.stellarRatio + fixedRatioOffset - 1) + particle.startingPositionTop; - newOffsetTop = newPositionTop - particle.startingPositionTop + particle.startingOffsetTop; - } else { - newPositionTop = particle.startingPositionTop; - newOffsetTop = particle.startingOffsetTop; - } - - // Check visibility - if (this.options.hideDistantElements) { - isVisibleHorizontal = !this.options.horizontalScrolling || newOffsetLeft + particle.width > (particle.isFixed ? 0 : scrollLeft) && newOffsetLeft < (particle.isFixed ? 0 : scrollLeft) + this.viewportWidth + this.viewportOffsetLeft; - isVisibleVertical = !this.options.verticalScrolling || newOffsetTop + particle.height > (particle.isFixed ? 0 : scrollTop) && newOffsetTop < (particle.isFixed ? 0 : scrollTop) + this.viewportHeight + this.viewportOffsetTop; - } - - if (isVisibleHorizontal && isVisibleVertical) { - if (particle.isHidden) { - this.options.showElement(particle.$element); - particle.isHidden = false; - } - - this._setPosition(particle.$element, newPositionLeft, particle.startingPositionLeft, newPositionTop, particle.startingPositionTop); - } else { - if (!particle.isHidden) { - this.options.hideElement(particle.$element); - particle.isHidden = true; - } - } - } - - // Reposition backgrounds - for (i = this.backgrounds.length - 1; i >= 0; i--) { - background = this.backgrounds[i]; - - fixedRatioOffset = (background.isFixed ? 0 : 1); - bgLeft = (this.options.horizontalScrolling ? (scrollLeft + background.horizontalOffset - this.viewportOffsetLeft - background.startingOffsetLeft + background.parentOffsetLeft - background.startingBackgroundPositionLeft) * (fixedRatioOffset - background.stellarRatio) + 'px' : background.startingValueLeft); - bgTop = (this.options.verticalScrolling ? (scrollTop + background.verticalOffset - this.viewportOffsetTop - background.startingOffsetTop + background.parentOffsetTop - background.startingBackgroundPositionTop) * (fixedRatioOffset - background.stellarRatio) + 'px' : background.startingValueTop); - - setBackgroundPosition(background.$element, bgLeft, bgTop); - } - }, - _handleScrollEvent: function() { - var self = this, - ticking = false; - - var update = function() { - self._repositionElements(); - ticking = false; - }; - - var requestTick = function() { - if (!ticking) { - requestAnimFrame(update); - ticking = true; - } - }; - - this.$scrollElement.bind('scroll.' + this.name, requestTick); - requestTick(); - }, - _startAnimationLoop: function() { - var self = this; - - this._animationLoop = function() { - requestAnimFrame(self._animationLoop); - self._repositionElements(); - }; - this._animationLoop(); - } - }; - - $.fn[pluginName] = function (options) { - var args = arguments; - if (options === undefined || typeof options === 'object') { - return this.each(function () { - if (!$.data(this, 'plugin_' + pluginName)) { - $.data(this, 'plugin_' + pluginName, new Plugin(this, options)); - } - }); - } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') { - return this.each(function () { - var instance = $.data(this, 'plugin_' + pluginName); - if (instance instanceof Plugin && typeof instance[options] === 'function') { - instance[options].apply(instance, Array.prototype.slice.call(args, 1)); - } - if (options === 'destroy') { - $.data(this, 'plugin_' + pluginName, null); - } - }); - } - }; - - $[pluginName] = function(options) { - var $window = $(window); - return $window.stellar.apply($window, Array.prototype.slice.call(arguments, 0)); - }; - - // Expose the scroll and position property function hashes so they can be extended - $[pluginName].scrollProperty = scrollProperty; - $[pluginName].positionProperty = positionProperty; - - // Expose the plugin class so it can be modified - window.Stellar = Plugin; -}(jQuery, this, document)); \ No newline at end of file diff --git a/addons/website/static/lib/stellar/jquery.stellar.min.js b/addons/website/static/lib/stellar/jquery.stellar.min.js deleted file mode 100644 index dd7827adce4..00000000000 --- a/addons/website/static/lib/stellar/jquery.stellar.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/*! Stellar.js v0.6.2 | Copyright 2013, Mark Dalgleish | http://markdalgleish.com/projects/stellar.js | http://markdalgleish.mit-license.org */ -(function(e,t,n,r){function d(t,n){this.element=t,this.options=e.extend({},s,n),this._defaults=s,this._name=i,this.init()}var i="stellar",s={scrollProperty:"scroll",positionProperty:"position",horizontalScrolling:!0,verticalScrolling:!0,horizontalOffset:0,verticalOffset:0,responsive:!1,parallaxBackgrounds:!0,parallaxElements:!0,hideDistantElements:!0,hideElement:function(e){e.hide()},showElement:function(e){e.show()}},o={scroll:{getLeft:function(e){return e.scrollLeft()},setLeft:function(e,t){e.scrollLeft(t)},getTop:function(e){return e.scrollTop()},setTop:function(e,t){e.scrollTop(t)}},position:{getLeft:function(e){return parseInt(e.css("left"),10)*-1},getTop:function(e){return parseInt(e.css("top"),10)*-1}},margin:{getLeft:function(e){return parseInt(e.css("margin-left"),10)*-1},getTop:function(e){return parseInt(e.css("margin-top"),10)*-1}},transform:{getLeft:function(e){var t=getComputedStyle(e[0])[f];return t!=="none"?parseInt(t.match(/(-?[0-9]+)/g)[4],10)*-1:0},getTop:function(e){var t=getComputedStyle(e[0])[f];return t!=="none"?parseInt(t.match(/(-?[0-9]+)/g)[5],10)*-1:0}}},u={position:{setLeft:function(e,t){e.css("left",t)},setTop:function(e,t){e.css("top",t)}},transform:{setPosition:function(e,t,n,r,i){e[0].style[f]="translate3d("+(t-n)+"px, "+(r-i)+"px, 0)"}}},a=function(){var t=/^(Moz|Webkit|Khtml|O|ms|Icab)(?=[A-Z])/,n=e("script")[0].style,r="",i;for(i in n)if(t.test(i)){r=i.match(t)[0];break}return"WebkitOpacity"in n&&(r="Webkit"),"KhtmlOpacity"in n&&(r="Khtml"),function(e){return r+(r.length>0?e.charAt(0).toUpperCase()+e.slice(1):e)}}(),f=a("transform"),l=e("
    ",{style:"background:#fff"}).css("background-position-x")!==r,c=l?function(e,t,n){e.css({"background-position-x":t,"background-position-y":n})}:function(e,t,n){e.css("background-position",t+" "+n)},h=l?function(e){return[e.css("background-position-x"),e.css("background-position-y")]}:function(e){return e.css("background-position").split(" ")},p=t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)};d.prototype={init:function(){this.options.name=i+"_"+Math.floor(Math.random()*1e9),this._defineElements(),this._defineGetters(),this._defineSetters(),this._handleWindowLoadAndResize(),this._detectViewport(),this.refresh({firstLoad:!0}),this.options.scrollProperty==="scroll"?this._handleScrollEvent():this._startAnimationLoop()},_defineElements:function(){this.element===n.body&&(this.element=t),this.$scrollElement=e(this.element),this.$element=this.element===t?e("body"):this.$scrollElement,this.$viewportElement=this.options.viewportElement!==r?e(this.options.viewportElement):this.$scrollElement[0]===t||this.options.scrollProperty==="scroll"?this.$scrollElement:this.$scrollElement.parent()},_defineGetters:function(){var e=this,t=o[e.options.scrollProperty];this._getScrollLeft=function(){return t.getLeft(e.$scrollElement)},this._getScrollTop=function(){return t.getTop(e.$scrollElement)}},_defineSetters:function(){var t=this,n=o[t.options.scrollProperty],r=u[t.options.positionProperty],i=n.setLeft,s=n.setTop;this._setScrollLeft=typeof i=="function"?function(e){i(t.$scrollElement,e)}:e.noop,this._setScrollTop=typeof s=="function"?function(e){s(t.$scrollElement,e)}:e.noop,this._setPosition=r.setPosition||function(e,n,i,s,o){t.options.horizontalScrolling&&r.setLeft(e,n,i),t.options.verticalScrolling&&r.setTop(e,s,o)}},_handleWindowLoadAndResize:function(){var n=this,r=e(t);n.options.responsive&&r.bind("load."+this.name,function(){n.refresh()}),r.bind("resize."+this.name,function(){n._detectViewport(),n.options.responsive&&n.refresh()})},refresh:function(n){var r=this,i=r._getScrollLeft(),s=r._getScrollTop();(!n||!n.firstLoad)&&this._reset(),this._setScrollLeft(0),this._setScrollTop(0),this._setOffsets(),this._findParticles(),this._findBackgrounds(),n&&n.firstLoad&&/WebKit/.test(navigator.userAgent)&&e(t).load(function(){var e=r._getScrollLeft(),t=r._getScrollTop();r._setScrollLeft(e+1),r._setScrollTop(t+1),r._setScrollLeft(e),r._setScrollTop(t)}),this._setScrollLeft(i),this._setScrollTop(s)},_detectViewport:function(){var e=this.$viewportElement.offset(),t=e!==null&&e!==r;this.viewportWidth=this.$viewportElement.width(),this.viewportHeight=this.$viewportElement.height(),this.viewportOffsetTop=t?e.top:0,this.viewportOffsetLeft=t?e.left:0},_findParticles:function(){var t=this,n=this._getScrollLeft(),i=this._getScrollTop();if(this.particles!==r)for(var s=this.particles.length-1;s>=0;s--)this.particles[s].$element.data("stellar-elementIsActive",r);this.particles=[];if(!this.options.parallaxElements)return;this.$element.find("[data-stellar-ratio]").each(function(n){var i=e(this),s,o,u,a,f,l,c,h,p,d=0,v=0,m=0,g=0;if(!i.data("stellar-elementIsActive"))i.data("stellar-elementIsActive",this);else if(i.data("stellar-elementIsActive")!==this)return;t.options.showElement(i),i.data("stellar-startingLeft")?(i.css("left",i.data("stellar-startingLeft")),i.css("top",i.data("stellar-startingTop"))):(i.data("stellar-startingLeft",i.css("left")),i.data("stellar-startingTop",i.css("top"))),u=i.position().left,a=i.position().top,f=i.css("margin-left")==="auto"?0:parseInt(i.css("margin-left"),10),l=i.css("margin-top")==="auto"?0:parseInt(i.css("margin-top"),10),h=i.offset().left-f,p=i.offset().top-l,i.parents().each(function(){var t=e(this);if(t.data("stellar-offset-parent")===!0)return d=m,v=g,c=t,!1;m+=t.position().left,g+=t.position().top}),s=i.data("stellar-horizontal-offset")!==r?i.data("stellar-horizontal-offset"):c!==r&&c.data("stellar-horizontal-offset")!==r?c.data("stellar-horizontal-offset"):t.horizontalOffset,o=i.data("stellar-vertical-offset")!==r?i.data("stellar-vertical-offset"):c!==r&&c.data("stellar-vertical-offset")!==r?c.data("stellar-vertical-offset"):t.verticalOffset,t.particles.push({$element:i,$offsetParent:c,isFixed:i.css("position")==="fixed",horizontalOffset:s,verticalOffset:o,startingPositionLeft:u,startingPositionTop:a,startingOffsetLeft:h,startingOffsetTop:p,parentOffsetLeft:d,parentOffsetTop:v,stellarRatio:i.data("stellar-ratio")!==r?i.data("stellar-ratio"):1,width:i.outerWidth(!0),height:i.outerHeight(!0),isHidden:!1})})},_findBackgrounds:function(){var t=this,n=this._getScrollLeft(),i=this._getScrollTop(),s;this.backgrounds=[];if(!this.options.parallaxBackgrounds)return;s=this.$element.find("[data-stellar-background-ratio]"),this.$element.data("stellar-background-ratio")&&(s=s.add(this.$element)),s.each(function(){var s=e(this),o=h(s),u,a,f,l,p,d,v,m,g,y=0,b=0,w=0,E=0;if(!s.data("stellar-backgroundIsActive"))s.data("stellar-backgroundIsActive",this);else if(s.data("stellar-backgroundIsActive")!==this)return;s.data("stellar-backgroundStartingLeft")?c(s,s.data("stellar-backgroundStartingLeft"),s.data("stellar-backgroundStartingTop")):(s.data("stellar-backgroundStartingLeft",o[0]),s.data("stellar-backgroundStartingTop",o[1])),p=s.css("margin-left")==="auto"?0:parseInt(s.css("margin-left"),10),d=s.css("margin-top")==="auto"?0:parseInt(s.css("margin-top"),10),v=s.offset().left-p-n,m=s.offset().top-d-i,s.parents().each(function(){var t=e(this);if(t.data("stellar-offset-parent")===!0)return y=w,b=E,g=t,!1;w+=t.position().left,E+=t.position().top}),u=s.data("stellar-horizontal-offset")!==r?s.data("stellar-horizontal-offset"):g!==r&&g.data("stellar-horizontal-offset")!==r?g.data("stellar-horizontal-offset"):t.horizontalOffset,a=s.data("stellar-vertical-offset")!==r?s.data("stellar-vertical-offset"):g!==r&&g.data("stellar-vertical-offset")!==r?g.data("stellar-vertical-offset"):t.verticalOffset,t.backgrounds.push({$element:s,$offsetParent:g,isFixed:s.css("background-attachment")==="fixed",horizontalOffset:u,verticalOffset:a,startingValueLeft:o[0],startingValueTop:o[1],startingBackgroundPositionLeft:isNaN(parseInt(o[0],10))?0:parseInt(o[0],10),startingBackgroundPositionTop:isNaN(parseInt(o[1],10))?0:parseInt(o[1],10),startingPositionLeft:s.position().left,startingPositionTop:s.position().top,startingOffsetLeft:v,startingOffsetTop:m,parentOffsetLeft:y,parentOffsetTop:b,stellarRatio:s.data("stellar-background-ratio")===r?1:s.data("stellar-background-ratio")})})},_reset:function(){var e,t,n,r,i;for(i=this.particles.length-1;i>=0;i--)e=this.particles[i],t=e.$element.data("stellar-startingLeft"),n=e.$element.data("stellar-startingTop"),this._setPosition(e.$element,t,t,n,n),this.options.showElement(e.$element),e.$element.data("stellar-startingLeft",null).data("stellar-elementIsActive",null).data("stellar-backgroundIsActive",null);for(i=this.backgrounds.length-1;i>=0;i--)r=this.backgrounds[i],r.$element.data("stellar-backgroundStartingLeft",null).data("stellar-backgroundStartingTop",null),c(r.$element,r.startingValueLeft,r.startingValueTop)},destroy:function(){this._reset(),this.$scrollElement.unbind("resize."+this.name).unbind("scroll."+this.name),this._animationLoop=e.noop,e(t).unbind("load."+this.name).unbind("resize."+this.name)},_setOffsets:function(){var n=this,r=e(t);r.unbind("resize.horizontal-"+this.name).unbind("resize.vertical-"+this.name),typeof this.options.horizontalOffset=="function"?(this.horizontalOffset=this.options.horizontalOffset(),r.bind("resize.horizontal-"+this.name,function(){n.horizontalOffset=n.options.horizontalOffset()})):this.horizontalOffset=this.options.horizontalOffset,typeof this.options.verticalOffset=="function"?(this.verticalOffset=this.options.verticalOffset(),r.bind("resize.vertical-"+this.name,function(){n.verticalOffset=n.options.verticalOffset()})):this.verticalOffset=this.options.verticalOffset},_repositionElements:function(){var e=this._getScrollLeft(),t=this._getScrollTop(),n,r,i,s,o,u,a,f=!0,l=!0,h,p,d,v,m;if(this.currentScrollLeft===e&&this.currentScrollTop===t&&this.currentWidth===this.viewportWidth&&this.currentHeight===this.viewportHeight)return;this.currentScrollLeft=e,this.currentScrollTop=t,this.currentWidth=this.viewportWidth,this.currentHeight=this.viewportHeight;for(m=this.particles.length-1;m>=0;m--)i=this.particles[m],s=i.isFixed?1:0,this.options.horizontalScrolling?(h=(e+i.horizontalOffset+this.viewportOffsetLeft+i.startingPositionLeft-i.startingOffsetLeft+i.parentOffsetLeft)*-(i.stellarRatio+s-1)+i.startingPositionLeft,d=h-i.startingPositionLeft+i.startingOffsetLeft):(h=i.startingPositionLeft,d=i.startingOffsetLeft),this.options.verticalScrolling?(p=(t+i.verticalOffset+this.viewportOffsetTop+i.startingPositionTop-i.startingOffsetTop+i.parentOffsetTop)*-(i.stellarRatio+s-1)+i.startingPositionTop,v=p-i.startingPositionTop+i.startingOffsetTop):(p=i.startingPositionTop,v=i.startingOffsetTop),this.options.hideDistantElements&&(l=!this.options.horizontalScrolling||d+i.width>(i.isFixed?0:e)&&d<(i.isFixed?0:e)+this.viewportWidth+this.viewportOffsetLeft,f=!this.options.verticalScrolling||v+i.height>(i.isFixed?0:t)&&v<(i.isFixed?0:t)+this.viewportHeight+this.viewportOffsetTop),l&&f?(i.isHidden&&(this.options.showElement(i.$element),i.isHidden=!1),this._setPosition(i.$element,h,i.startingPositionLeft,p,i.startingPositionTop)):i.isHidden||(this.options.hideElement(i.$element),i.isHidden=!0);for(m=this.backgrounds.length-1;m>=0;m--)o=this.backgrounds[m],s=o.isFixed?0:1,u=this.options.horizontalScrolling?(e+o.horizontalOffset-this.viewportOffsetLeft-o.startingOffsetLeft+o.parentOffsetLeft-o.startingBackgroundPositionLeft)*(s-o.stellarRatio)+"px":o.startingValueLeft,a=this.options.verticalScrolling?(t+o.verticalOffset-this.viewportOffsetTop-o.startingOffsetTop+o.parentOffsetTop-o.startingBackgroundPositionTop)*(s-o.stellarRatio)+"px":o.startingValueTop,c(o.$element,u,a)},_handleScrollEvent:function(){var e=this,t=!1,n=function(){e._repositionElements(),t=!1},r=function(){t||(p(n),t=!0)};this.$scrollElement.bind("scroll."+this.name,r),r()},_startAnimationLoop:function(){var e=this;this._animationLoop=function(){p(e._animationLoop),e._repositionElements()},this._animationLoop()}},e.fn[i]=function(t){var n=arguments;if(t===r||typeof t=="object")return this.each(function(){e.data(this,"plugin_"+i)||e.data(this,"plugin_"+i,new d(this,t))});if(typeof t=="string"&&t[0]!=="_"&&t!=="init")return this.each(function(){var r=e.data(this,"plugin_"+i);r instanceof d&&typeof r[t]=="function"&&r[t].apply(r,Array.prototype.slice.call(n,1)),t==="destroy"&&e.data(this,"plugin_"+i,null)})},e[i]=function(n){var r=e(t);return r.stellar.apply(r,Array.prototype.slice.call(arguments,0))},e[i].scrollProperty=o,e[i].positionProperty=u,t.Stellar=d})(jQuery,this,document); \ No newline at end of file diff --git a/addons/website/static/lib/stellar/package.json b/addons/website/static/lib/stellar/package.json deleted file mode 100644 index 1df062d9935..00000000000 --- a/addons/website/static/lib/stellar/package.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "jquery.stellar", - "title": "Stellar.js", - "version": "0.6.2", - "description": "Parallax scrolling made easy.", - "homepage": "http://markdalgleish.com/projects/stellar.js", - "author": { - "name": "Mark Dalgleish", - "url": "http://markdalgleish.com" - }, - "keywords": [ - "parallax", - "scroll", - "effect", - "animation" - ], - "licenses": [ - { - "type": "MIT", - "url": "http://markdalgleish.mit-license.org" - } - ], - "dependencies": { - "jquery": ">=1.4.3" - }, - "bugs": "https://github.com/markdalgleish/stellar.js/issues", - "repository": { - "type": "git", - "url": "git://github.com/markdalgleish/stellar.js.git" - }, - "maintainers": [ - { - "name": "Mark Dalgleish", - "url": "http://markdalgleish.com" - } - ], - "files": [ - "jquery.stellar.js" - ], - "scripts": { - "test": "grunt test" - }, - "devDependencies": { - "grunt": "~0.3.17" - } -} diff --git a/addons/website/static/lib/stellar/stellar.jquery.json b/addons/website/static/lib/stellar/stellar.jquery.json deleted file mode 100644 index 1eeffdffc1b..00000000000 --- a/addons/website/static/lib/stellar/stellar.jquery.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "stellar", - "title": "Stellar.js", - "version": "0.6.2", - "description": "Parallax scrolling made easy.", - "homepage": "http://markdalgleish.com/projects/stellar.js", - "author": { - "name": "Mark Dalgleish", - "url": "http://markdalgleish.com" - }, - "keywords": [ - "parallax", - "scroll", - "effect", - "animation" - ], - "licenses": [ - { - "type": "MIT", - "url": "http://markdalgleish.mit-license.org" - } - ], - "dependencies": { - "jquery": ">=1.4.3" - }, - "bugs": "https://github.com/markdalgleish/stellar.js/issues", - "docs": "http://markdalgleish.com/projects/stellar.js/docs", - "download": "https://github.com/markdalgleish/stellar.js#download" -} \ No newline at end of file diff --git a/addons/website/static/src/css/website.css b/addons/website/static/src/css/website.css index a14e9e8a3f8..d93d789d0b4 100644 --- a/addons/website/static/src/css/website.css +++ b/addons/website/static/src/css/website.css @@ -361,8 +361,7 @@ footer { } .parallax { - background-attachment: fixed; - background-size: 100%; + position: relative; } .parallax.oe_small { height: 200px; diff --git a/addons/website/static/src/css/website.sass b/addons/website/static/src/css/website.sass index f34cb9d5b67..b5b2476dd17 100644 --- a/addons/website/static/src/css/website.sass +++ b/addons/website/static/src/css/website.sass @@ -276,8 +276,7 @@ footer background-color: grey .parallax - background-attachment: fixed - background-size: 100% + position: relative &.oe_small height: 200px &.oe_medium diff --git a/addons/website/static/src/js/website.snippets.js b/addons/website/static/src/js/website.snippets.js index 8032d688a82..da99b76f279 100644 --- a/addons/website/static/src/js/website.snippets.js +++ b/addons/website/static/src/js/website.snippets.js @@ -1,6 +1,21 @@ (function () { 'use strict'; + + var start_snippet_animation = function () { + hack_to_add_snippet_id(); + $("[data-snippet-id]").each(function() { + var $snipped_id = $(this); + if ( !$snipped_id.parents("#oe_snippets").length && + typeof $snipped_id.data("snippet-view") === 'undefined' && + website.snippet.animationRegistry[$snipped_id.data("snippet-id")]) { + var snippet = new website.snippet.animationRegistry[$snipped_id.data("snippet-id")]($snipped_id); + $snipped_id.data("snippet-view", snippet); + } + }); + }; + $(document).ready(start_snippet_animation); + var website = openerp.website; website.add_template_file('/website/static/src/xml/website.snippets.xml'); @@ -24,6 +39,7 @@ this.on('rte:ready', this, function () { self.snippets.$button.removeClass("hidden"); + start_snippet_animation(); self.trigger('rte:snippets_ready'); }); @@ -40,18 +56,6 @@ }, }); - - $(document).ready(function () { - hack_to_add_snippet_id(); - $("[data-snippet-id]").each(function() { - var $snipped_id = $(this); - if (typeof $snipped_id.data("snippet-view") === 'undefined' && - website.snippet.animationRegistry[$snipped_id.data("snippet-id")]) { - $snipped_id.data("snippet-view", new website.snippet.animationRegistry[$snipped_id.data("snippet-id")]($snipped_id)); - } - }); - }); - /* ----- SNIPPET SELECTOR ---- */ website.snippet = {}; @@ -1208,24 +1212,23 @@ website.snippet.editorRegistry.parallax = website.snippet.editorRegistry.resize.extend({ start : function () { this._super(); - this.change_background($('.parallax', this.$target), 'ul[name="parallax-background"]'); + this.change_background(this.$target, 'ul[name="parallax-background"]'); this.scroll(); this.change_size(); }, - scroll: function(){ + scroll: function () { + var self = this; var $ul = this.$editor.find('ul[name="parallax-scroll"]'); var $li = $ul.find("li"); - var $parallax = this.$target.find('.parallax'); - var speed = $parallax.data('stellar-background-ratio') || 0.5 ; - + var speed = this.$target.data('scroll-background-ratio') || 0.6 ; $ul.find('[data-value="' + speed + '"]').addClass('active'); $li.on('click', function (event) { $li.removeClass("active"); $(this).addClass("active"); var speed = $(this).data('value'); - $parallax.attr('data-stellar-background-ratio', speed); + self.$target.attr('data-scroll-background-ratio', speed); + self.$target.data("snippet-view").set_values(); }); - }, clean_for_save: function () { this._super(); @@ -1233,12 +1236,11 @@ }, change_size: function () { var self = this; - var $el = $('.oe_big,.oe_medium,.oe_small', this.$target); var size = 'oe_big'; - if ($el.hasClass('oe_small')) + if (this.$target.hasClass('oe_small')) size = 'oe_small'; - else if ($el.hasClass('oe_medium')) + else if (this.$target.hasClass('oe_medium')) size = 'oe_medium'; var $ul = this.$editor.find('ul[name="parallax-size"]'); var $li = $ul.find("li"); @@ -1248,21 +1250,50 @@ $li.on('click', function (event) { $li.removeClass("active"); $(this).addClass("active"); + self.$target.data("snippet-view").set_values(); }) .on('mouseover', function (event) { - $el.removeClass('oe_big oe_small oe_medium'); - $el.addClass($(event.currentTarget).data("value")); + self.$target.removeClass('oe_big oe_small oe_medium'); + self.$target.addClass($(event.currentTarget).data("value")); }) .on('mouseout', function (event) { - $el.removeClass('oe_big oe_small oe_medium'); - $el.addClass($ul.find('li.active').data("value")); + self.$target.removeClass('oe_big oe_small oe_medium'); + self.$target.addClass($ul.find('li.active').data("value")); }); } }); website.snippet.animationRegistry.parallax = website.snippet.Animation.extend({ start: function () { - $.stellar({ horizontalScrolling: false, verticalOffset: 0 }); + var self = this; + this.set_values(); + var on_scroll = function () { + var speed = parseFloat(self.$target.attr("data-scroll-background-ratio") || 0); + if (speed == 1) return; + var offset = parseFloat(self.$target.attr("data-scroll-background-offset") || 0); + var top = offset + window.scrollY * speed; + self.$target.css("background-position", "0px " + top + "px"); + }; + $(window).off("scroll").on("scroll", on_scroll); }, + set_values: function () { + var self = this; + var speed = parseFloat(self.$target.attr("data-scroll-background-ratio") || 0); + + if (speed == 1) { + this.$target.css("background-attachment", "fixed").css("background-position", "0px 0px"); + return; + } else { + this.$target.css("background-attachment", "scroll"); + } + + this.$target.attr("data-scroll-background-offset", 0); + var img = new Image(); + img.onload = function () { + self.$target.attr("data-scroll-background-offset", self.$target.outerHeight() - this.height); + $(window).scroll(); + }; + img.src = this.$target.css("background-image").replace(/url\(['"]*|['"]*\)/g, ""); + } }); /* diff --git a/addons/website/views/snippets.xml b/addons/website/views/snippets.xml index 67f21ac5401..868c9cdfe43 100644 --- a/addons/website/views/snippets.xml +++ b/addons/website/views/snippets.xml @@ -691,7 +691,6 @@ -
    -
    - -
    +
    diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml index c0af595c0d2..d0ce607b064 100644 --- a/addons/website/views/website_templates.xml +++ b/addons/website/views/website_templates.xml @@ -76,7 +76,6 @@ - From 870559b5cc7fd73bb5b0af8afa6dc2f48321f6b0 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 8 Nov 2013 16:24:45 +0100 Subject: [PATCH 07/30] [FIX] webiste snippet: mega super fix bzr revid: chm@openerp.com-20131108152445-9n4oixwxwp150u9k --- addons/website/views/snippets.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/website/views/snippets.xml b/addons/website/views/snippets.xml index 868c9cdfe43..1f800e090e2 100644 --- a/addons/website/views/snippets.xml +++ b/addons/website/views/snippets.xml @@ -693,7 +693,7 @@
  • Landscape
  • Mountains
  • Office
  • -
  • Chose your picture
  • +
  • Choose your picture