Skip to content

Commit

Permalink
avoiding XHR request of the Store.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonvictor committed Aug 18, 2013
1 parent eb5ef9f commit c64b4b4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 44 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Notes:

First, import the rv fontsize js file:
``` html
<script type="text/javascript" src="js/store.min.js"></script><!-- store plugin required if "store : true"! -->
<script type="text/javascript" src="js/rv-jquery-fontsize-2.0.min.js"></script>
```

Expand All @@ -26,7 +27,7 @@ After that, call $.rvFontsize() with the desired options:
// plugin call used in live demo page
$.rvFontsize({
targetSection: '#content .post',
store: true,
store: true, // store.min.js required!
controllers: {
appendTo: '#rvfs-controllers',
showResetButton: true
Expand Down Expand Up @@ -73,14 +74,9 @@ Feel free to adapt it to fit your project needs.
<td align="left" valign="top">store</td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">If set as <code>true</code> the browser localStorage will be used to store font size settings. Thus, even if the user refreshs the page the font size will keep the same.<br><br>
When this feature is enabled it uses <a href="https://github.com/marcuswestin/store.js">store.js</a> plugin. So, don't forget to add <strong>store.min.js</strong> file inside your <strong>/js</strong> folder.
When this feature is enabled it uses <a href="https://github.com/marcuswestin/store.js">store.js</a> plugin. So, don't forget to load the <strong>store.min.js</strong> script right before the <strong>rv-jquery-fontsize.js</strong>.
</td>
</tr>
<tr>
<td align="left" valign="top">storeJsSrc</td>
<td align="left" valign="top">'js/store.min.js'</td>
<td align="left" valign="top">Change the default source of "store.min.js" file, if it's needed.</td>
</tr>
<tr>
<td align="left" valign="top">variations</td>
<td align="left" valign="top">7</td>
Expand Down
10 changes: 6 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<title>RV Font Size Plugin 2.0</title>
<title>RV Font Size Plugin 2.0.3</title>

<!-- meta -->
<meta name="description" content="RV Font Size Plugin : an easy and flexible jquery plugin to give font size accessibility control.">
Expand Down Expand Up @@ -45,7 +45,7 @@
<div id="all">
<header id="header">
<div class="vcard">
<h1 class="fn">RV Fonte Size Plugin 2.0 (beta)
<h1 class="fn">RV Fonte Size Plugin 2.0.3
<a href="https://github.com/ramonvictor/rv-jquery-fontsize">[download]</a>
</h1>
</div><!-- vcard -->
Expand Down Expand Up @@ -76,14 +76,16 @@ <h1 class="fn">RV Fonte Size Plugin 2.0 (beta)
</div><!-- main-content -->
</div><!-- all -->
<a href="https://github.com/ramonvictor/rv-jquery-fontsize"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_left_darkblue_121621.png" alt="Fork me on GitHub"></a>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.9.1.min.js"><\/script>')</script>
<script type="text/javascript" src="js/rv-jquery-fontsize-2.0.min.js"></script>
<script type="text/javascript" src="js/store.min.js"></script>
<script type="text/javascript" src="js/rv-jquery-fontsize-2.0.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.rvFontsize({
targetSection: '#content .post',
store: true,
store: true, // store.min.js required!
controllers: {
appendTo: '#rvfs-controllers',
showResetButton: true
Expand Down
38 changes: 16 additions & 22 deletions js/rv-jquery-fontsize-2.0.js → js/rv-jquery-fontsize-2.0.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
defaults = {
targetSection: 'body',
store: false,
storeJsSrc: 'js/store.min.js',
storeIsDefined: !(typeof store === "undefined"),
variations: 7,
controllers: {
append: true,
Expand All @@ -40,33 +40,21 @@
Plugin.prototype = {

init: function() {

var _self = this,
fn = function(){
_self.defineElements();
_self.getDefaultFontSize();
};

if( _self.options.store === true ){
var jsPath = _self.options.storeJsSrc;
_self.cachedScript( jsPath ).done(function(){
fn();
});
} else {
fn();
}
fn();

if( _self.options.store === true && !(_self.options.storeIsDefined) ) {
_self.dependencyWarning();
}
},

cachedScript : function(url, options) {

options = $.extend(options || {}, {
dataType: "script",
cache: true,
url: url
});

return $.ajax(options);
dependencyWarning : function(){
console.warn('When you difine "store: true", store script is required (https://github.com/ramonvictor/rv-jquery-fontsize/blob/master/js/store.min.js)');
},

bindControlerHandlers: function(){
Expand Down Expand Up @@ -182,8 +170,9 @@
setDefaultFontSize: function(){
var _self = this;

if( _self.options.store === true && store.get('rvfs') ){
_self.$target.attr("data-rvfs", store.get('rvfs') );
if( _self.options.store === true && _self.options.storeIsDefined ){
var currentFs = store.get('rvfs') || _self.defaultFontsize;
_self.$target.attr("data-rvfs", currentFs );
} else {
_self.$target.attr("data-rvfs", _self.defaultFontsize );
}
Expand All @@ -192,7 +181,12 @@
},

storeCurrentSize : function() {
store.set('rvfs', this.$target.attr("data-rvfs"));
var _self = this;
if( _self.options.storeIsDefined ) {
store.set('rvfs', _self.$target.attr("data-rvfs"));
} else {
_self.dependencyWarning();
}
},

getCurrentVariation : function(){
Expand Down
10 changes: 10 additions & 0 deletions js/rv-jquery-fontsize-2.0.3.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions js/rv-jquery-fontsize-2.0.min.js

This file was deleted.

2 changes: 1 addition & 1 deletion rvfontsize.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"jquery",
"typography"
],
"version": "0.2.2",
"version": "0.2.3",
"author": {
"name": "Ramon Victor",
"url": "https://github.com/ramonvictor"
Expand Down

0 comments on commit c64b4b4

Please sign in to comment.