Triggers classes on html elements based on the scroll position. It makes use of requestAnimationFrame so it doesn't jack the users scroll, that way the user / browser keeps their original scroll behaviour.
by via jQuery-Plugins.net RSS Feed
"Mr Branding" is a blog based on RSS for everything related to website branding and website design, it collects its posts from many sites in order to facilitate the updating to the latest technology.
To suggest any source, please contact me: Taha.baba@consultant.com
Triggers classes on html elements based on the scroll position. It makes use of requestAnimationFrame so it doesn't jack the users scroll, that way the user / browser keeps their original scroll behaviour.
|
In the first and second parts of this three-part tutorial series, we saw how to lay out the template structure in a Flask-based application using Jinja2 in a modular manner and how to create custom context processors, filters and macros in Jinja2.
In this part, we will cover how to implement advanced date and time formatting at template level in Jinja2 using moment.js.
Date and time formatting is a painful thing to handle in web applications. Handling them at the level of Python, using the datetime library, increases the overhead and is pretty complex when it comes to handling time zones correctly. We should standardize the timestamps to UTC when stored in the database, but then the timestamps need to be processed every time they need to be presented to the users worldwide.
It is a smart thing to defer this processing to the client side, that is, the browser. The browser always knows the current time zone of the user and will be able to do the date and time manipulation correctly. Also, this takes off the necessary overhead from our application servers.
Just like any JS library, Moment.js can be included in our app in the following manner. We will just have to place the JS file, moment.min.js
, in the static/js
folder. This can then be used in our HTML file by adding the following statement along with other JS libraries:
<script src="/static/js/moment.min.js"></script>
The basic usage of Moment.js is shown in the following code. This can be done in the browser console for JavaScript:
>>> moment().calendar(); "Today at 9:37 PM" >>> moment().endOf('day').fromNow(); "in 2 hours" >>> moment().format('LLLL'); "Wednesday, January 27, 2016 9:38 PM"
To use Moment.js in our application, the best way will be to write a wrapper in Python and use it via jinja2
environment variables. Refer to this runnable for more background. Add a file named momentjs.py
at the same level as my_app.py
.
from jinja2 import Markup class momentjs(object): def __init__(self, timestamp): self.timestamp = timestamp # Wrapper to call moment.js method def render(self, format): return Markup("<script>\ndocument.write(moment(\"%s\").%s);\n</script>" % (self.timestamp.strftime("%Y-%m-%dT%H:%M:%S"), format)) # Format time def format(self, fmt): return self.render("format(\"%s\")" % fmt) def calendar(self): return self.render("calendar()") def fromNow(self): return self.render("fromNow()")
Add the following line in flask_app/my_app.py
after app
initialisation. This will add the momentjs
class to jinja
environment variables.
# Set jinja template global app.jinja_env.globals['momentjs'] = momentjs
Now moment.js can be used to format date and time in templates as follows:
<p>Current time: </p> <br/> <p>Time: </p> <br/> <p>From now: </p>
In this tutorial series, we covered the basics of Jinja2 templating from the perspective of Flask. We started with very basics of Jinja2 and learnt the best practices on how to lay out the template structure and leverage inheritance patterns.
Then we created some custom context processors, filters and macros which come very handy in advanced templating. The final tutorial covered how moment.js can be utilised along with Jinja2 to create highly flexible and powerful datetime formatting.
Do you want to add video to your social media marketing? Looking for ways to increase video views and engagement? In this article, you’ll discover 26 ways to use video to improve your social media marketing. #1: Experiment With Video Lengths When it comes to the ideal video duration, a lot depends on the type [...]
This post 26 Ways to Use Video for Your Social Media Marketing first appeared on .
- Your Guide to the Social Media Jungle
This weeks RSS and site sponsor is the awesome One Page Checkout extension for WooCommerce.
For those new to WooCommerce, it is a free WordPress plugin built by WooThemes. This extremely popular plugin gives anyone the ability to sell anything online within their WordPress installation.
How popular you ask? 30% of ALL online stores are powered by WooCommerce!
We don’t feature a lot of these WooCommerces powered stores as they aren’t Single Page websites. This is all going to change with the introduction of the One Page Checkout extension.
Think of an extension as an “add on” to an already very functional product. The reason it’s not bundled into the main product is because it is not for everyone. So it is offered as an optional extension keeping the main code less bloated. Smart.
This One Page Checkout extension keeps the whole commerce checkout process within the same page ie. the same One Page website if your store is on your home page.
This means when a user clicks an “Add To Cart” button, the items are added to the shopping cart without the page reloading. The user can continue to checkout and pay right there without any further waiting for pages to load or further distractions.
1 in 10 people who abandon their cart do so because the checkout process is too long. Reduce cart abandonment by offering the entire purchase process on a single page, with WooCommerce One Page Checkout.
Their promo video explains it quite well and includes a quick demo on implementation:
One Page Checkout displays product selection and checkout forms on a single page. Customers can add products to an order (or remove them) and complete payment without leaving the page:
You choose the products to display on each checkout page. Create a page for just the one featured product, a few related products for a promotion, or your store’s entire catalog:
You can also create multiple unique landing pages for special events, promotions or select customers. Add the shortcode to any page (or post) and add your content above the shortcode to display unique sales copy before the purchase process:
One Page Checkout includes several built-in templates, including a simple pricing table and list of products. Choose the template most suited to your page or if the built-in templates don’t fit your needs, create a custom template:
Probably best you see how extensive the documentation is. I’ve given it a spin myself and it’s super easy to implement. Basically all that is involved is dropping a simple shortcode anywhere in your One Pager that requires the commerce section:
WooCommerce is totally free but this One Page Checkout premium extension is $79 and well worth the money. Your purchasing includes one year of quality email support and plugin updates.
I’d love to see what you’re building with this extension so please email or tweet me your links. We might put together a roundup of sites to showcase more on the product:)
An extended checkbox plugin for Bootstrap built using JQuery, which allows three checkbox states and includes additional styles. The plugin uses Bootstrap markup and CSS 3 styling by default, but it can be overridden with any other CSS markup. It also helps you to fallback to a native checkbox OR display native checkboxes with tristate capability.
The post Checkbox X : jQuery extended Checkbox Plugin for Bootstrap appeared first on jQuery Rain.