diff --git a/PrefModel.js b/PrefModel.js new file mode 100644 index 0000000..cb02a92 --- /dev/null +++ b/PrefModel.js @@ -0,0 +1,87 @@ +var INTSCHEME_A = "A";// constant +var INTSCHEME_B = "B";// constant + +var PrefModel = { + + // intScheme : INTSCHEME_A + // , + // rrq_LoFret : 0 + // , + // rrq_HiFret : 0 + // , + // rrq_Notegroups : [] + // , + notegroups: [] + , + aPrefs : + { + intScheme : INTSCHEME_A, + rrq_LoFret: 0, + rrq_HiFret: 19, + rrq_LoStr: 1, + rrq_HiStr: 6, + rrq_Notegroups : [], + }, + init : function(aNotegroups, maxFret, maxString){ + this.aPrefs.rrq_HiFret = maxFret; + this.aPrefs.rrq_HiStr = maxString; + for(ng in aNotegroups){ + // Note: only pushing scales not arps or anything else + this.aPrefs.rrq_Notegroups.push([dictScales[ng].ngtype+'_'+dictScales[ng].varname, true]); + } + } + , + usingUserPrefs:false + , + writePrefCookie : function(){ + // put form values in mPref.aPrefs and save to cookie, or local storage if chrome + + // random root + mPref.aPrefs.rrq_LoFret = $('#spRR_LoFret').spinner().spinner( "value" ); + mPref.aPrefs.rrq_HiFret = $('#spRR_HiFret').spinner().spinner( "value" ); + mPref.aPrefs.rrq_LoStr = $('#spRR_LoStr').spinner().spinner( "value" ); + mPref.aPrefs.rrq_HiStr = $('#spRR_HiStr').spinner().spinner( "value" ); + // go through Notegroup inputs in the preferences popup and align with aPrefs.rrq_Notegroups + // 0 is name and 1 is true or false (checked or unchecked) + for (var ng in mPref.aPrefs.rrq_Notegroups){ + if($('#prefRRQ_'+mPref.aPrefs.rrq_Notegroups[ng][0]).is(':checked')){ + mPref.aPrefs.rrq_Notegroups[ng][1] = true; + } else{ + mPref.aPrefs.rrq_Notegroups[ng][1] = false; + } + } + + + // local chrome will not save cookies + var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; + //set cookies + if(is_chrome)$.localStorage('fs_userPrefs', this.aPrefs); + else $.cookies.set('fs_userPrefs', this.aPrefs); + } + , + retrieveUserPrefs : function(){ + var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; + + //get cookies + var fs_userPrefs=(is_chrome)?$.localStorage('fs_userPrefs'):$.cookies.get('fs_userPrefs'); + if(fs_userPrefs!=null){ + this.aPrefs = fs_userPrefs; + this.usingUserPrefs = true; + } + //alert( fs_userPrefs +' '+fs_userPrefs.rrq_LoFret+' '+fs_userPrefs.rrq_HiFret); + + } + , + notegroupInPrefs : function(ngKey){ + var rBool = false; + var nGrps = this.aPrefs.rrq_Notegroups + for(ng in nGrps){ + if(ngKey == nGrps[0][0].varname){ + rBool = true; + } + } + return rBool; + } + + +} \ No newline at end of file diff --git a/ScaleDictionary.js b/ScaleDictionary.js index d38d92e..a2226db 100644 --- a/ScaleDictionary.js +++ b/ScaleDictionary.js @@ -193,7 +193,7 @@ var INTCLR_AEOLIAN = ["i_root", "white","black","i_third","white","black","white var INTCLR_PHRYGIAN = ["i_root","black","white","i_third","white","black","white","i_fifth","black","white","i_seventh","white"]; var INTCLR_LOCRIAN = ["i_root","black","white","i_third","white","black","i_fifth","white","black","white","i_seventh","white"]; var INTCLR_AEOLIAN = ["i_root", "white","black","i_third","white","black","white","i_fifth","black","white","i_seventh","white"]; -var INTCLR_SYMDIM = ["i_root", "black","white","i_third","black","white","black","i_fifth","white","black","i_seventh","white"]; +var INTCLR_SYMDIM = ["i_root", "black","white","i_third","black","white","i_fifth","black","white","i_seventh","black","white"]; var INTCLR_MINHARM = ["i_root", "white","black","i_third","white","black","white","i_fifth","black","white","white","i_seventh"]; var INTCLR_MINMEL = ["i_root", "white","black","i_third","white","black","white","i_fifth","white","black","white","i_seventh"]; var INTCLR_ALTERED = ["i_root", "black","white","i_third","black","white","i_fifth","white","black","white","i_seventh","white"]; diff --git a/boxfrets.js b/boxfrets.js index b48561f..ac3b2cf 100644 --- a/boxfrets.js +++ b/boxfrets.js @@ -52,7 +52,8 @@ // var CHECKANSWER = 'Check Answer!'; - +var GTR_FRETS = 19; +var GTR_STRINGS = 6; var GUITAR_STRINGS; // will be array of strings var INTERVAL_COLORS = [ "i_root", @@ -667,17 +668,53 @@ var ctl_newIntQuiz = function(){ var ctl_newRandRoot = function(){ clear_fretboard(); - //INTERVALMODE = false; - //get random scale - // get randonm note on FB - var note = get_random_stringFret(); // 0 = string, 1 = fret - td_paint('#'+'nc_'+note[0]+'_'+note[1], "red"); - var sKey = getKeyObjFromNoteName($('#'+'nc_'+note[0]+'_'+note[1]).attr('notename')).safename; - var ng = get_random_scale_notegroup_key() // gets random dictionary key from scaleDict - arrNg = ng.split('_'); + // random string, fret according to mPrefs + var lowFret = mPref.aPrefs.rrq_LoFret; + var highFret = mPref.aPrefs.rrq_HiFret; + var lowString = mPref.aPrefs.rrq_LoStr -1; + var highString = mPref.aPrefs.rrq_HiStr -1; + var stringFret= [-1, -1];// random string/fret + while(!(stringFret[0] >= lowString && stringFret[0] <= highString)){ + stringFret[0] = Math.floor((Math.random() * GUITAR_STRINGS.length) );// string + } + while (!(stringFret[1] >= lowFret && stringFret[1] <= highFret)){ + stringFret[1] = Math.floor(Math.random() * highFret ); + } + td_paint('#'+'nc_'+stringFret[0]+'_'+stringFret[1], "red"); + var sKey = getKeyObjFromNoteName($('#'+'nc_'+stringFret[0]+'_'+stringFret[1]).attr('notename')).safename; + + // get random dictionary notegroup key that is in user preferences + checkedNG =[];// notegroups checked in preferences + for(ng in mPref.aPrefs.rrq_Notegroups){ + if(mPref.aPrefs.rrq_Notegroups[ng][1]){ + checkedNG.push(mPref.aPrefs.rrq_Notegroups[ng][0]); + } + } + var arrNg = checkedNG[Math.floor((Math.random() * checkedNG.length))].split('_'); set_notes_per_notegroup(sKey, arrNg[0] , arrNg[1]) } + // check boxes according to Pref model +var ctl_updateRRQprefView = function(){ + for (var ng in mPref.aPrefs.rrq_Notegroups){ + //0: scale name, 1: t/f checked in prefs + if(mPref.aPrefs.rrq_Notegroups[ng][1]){ + // control eg 'prefRRQ_SC_DORIAN' + $('#prefRRQ_'+mPref.aPrefs.rrq_Notegroups[ng][0]).prop('checked', true); + }else{ + $('#prefRRQ_'+mPref.aPrefs.rrq_Notegroups[ng][0]).prop('checked', false); + } + } +}; + + //when dialog is closed, update the Pref model with data in popup form controls +var ctl_updatePrefs = function(){ + //RandomRootQuiz + mPref.rrq_LoFret = $("#spRR_LoFret").spinner( "value" ); + mPref.rrq_HiFret = $("#spRR_HiFret").spinner( "value" ); + mPref.writePrefCookie(); + +}; // more utilities // @@ -924,6 +961,25 @@ var populateNotegroupsUnabridged = function(){ }; +var populateNotegroupsRandRootTab = function(){ + var itemsPerCol =7; + var colItem=0; + html=""; + html+=''; + for (var ng in mPref.aPrefs.rrq_Notegroups){ + colItem = colItem+1; + if(colItem > itemsPerCol){ + html+=''; + colItem = 1; + } + ng = dictScales[mPref.aPrefs.rrq_Notegroups[ng][0]]; // 0 is name, 1 is t/f for checked box + html += ' '+ng.name+'
'; + } + html+=''; + $("#RR_scaleOptionsDiv").append(html); +}; + + // Unabridged divs are the notegroup div objects in the left hand div under the fretboard // with all the tabs for each key. These are all the scales and arpeggios, unabridged. // These become draggable over to the right hand div under the fretboard which is governed by @@ -1001,8 +1057,10 @@ jQuery(document).ready(function() { $( ".cNoteGroup" ).draggable({ addClasses: false }); + // make fretboard - $(gen_fret_boxes(19, 6)).insertAfter($('#mainfretboard')); + + $(gen_fret_boxes(GTR_FRETS, GTR_STRINGS)).insertAfter($('#mainfretboard')); GUITAR_STRINGS = getFretcloneStrings(); set_notes(); @@ -1020,6 +1078,51 @@ jQuery(document).ready(function() { } $('#fretclone > tbody:last').append(newRow); + + // instantiate prefsModel -- for user preferences to govern and be saved as cookie or storage + mPref = PrefModel; + mPref.init(dictScales, GUITAR_STRINGS[0].length, GUITAR_STRINGS.length); // notegroups array, maxFrets, maxStrings + + + // make tabs in popup + $("#prefTabs").tabs(); + + // set up RandomRoot quiz prefs + var spRR_LoFret = $( "#spRR_LoFret" ).spinner({ + min: mPref.aPrefs.rrq_LoFret, + max: mPref.aPrefs.rrq_HiFret, + value: mPref.aPrefs.rrq_LoFret + }); + var spRR_HiFret = $("#spRR_HiFret").spinner({ + min: mPref.aPrefs.rrq_LoFret, + max: mPref.aPrefs.rrq_HiFret, + value: mPref.aPrefs.rrq_HiFret + }); + var spRR_LoStr = $("#spRR_LoStr").spinner({ + min: mPref.aPrefs.rrq_LoStr, + max: mPref.aPrefs.rrq_HiStr, + value: mPref.aPrefs.rrq_LoStr + }); + var spRR_HiStr = $("#spRR_HiStr").spinner({ + min: mPref.aPrefs.rrq_LoStr, + max: mPref.aPrefs.rrq_HiStr, + value: mPref.aPrefs.rrq_HiStr, + }); + +// set up prefs per user cookie or default + mPref.retrieveUserPrefs(); + + spRR_LoFret.spinner("value",mPref.aPrefs.rrq_LoFret); + spRR_HiFret.spinner("value",mPref.aPrefs.rrq_HiFret); + spRR_LoStr.spinner("value",mPref.aPrefs.rrq_LoStr); + spRR_HiStr.spinner("value",mPref.aPrefs.rrq_HiStr); + + // dynamically insert notegroup checkboxes + populateNotegroupsRandRootTab(); + // check boxes according to Pref model + ctl_updateRRQprefView(); + + // get any url parameters and adjust model(s) appropriately var url_params = get_url_parameters(); var loadFromUrl = function(){ @@ -1135,12 +1238,56 @@ jQuery(document).ready(function() { // bind help button to show help dialog - $('#btnHelp').click(function(){ + $('#btnHelp').button({ + text: false, + icons: + { + primary: "ui-icon-help" + } + }).click(function(){ $( "#helpText" ).html(HELP_TEXT); $( "#helpText" ).dialog( "open" ); }); +// preferences dialog + $(function() { + $( "#prefWin" ).dialog({ + autoOpen: false, + modal: true, + //closeOnEscape: false, + //open: function(event, ui) { $(".ui-dialog-titlebar-close", $(this).parent()).hide(); }, + buttons:{ + 'Save and Close':function(){ + //save prefs PrefModel and then write cookie + ctl_updatePrefs(); + + $(this).dialog('close'); + } + } + },{ + width: 640, + height: 472 + + },{ + dialogClass:".helpInstructions", + }); + }); + +// bind pref button to show preferences dialog + $('#btnPref').button({ + text: false, + icons: + { + primary: "ui-icon-gear" + } + }).click(function(){ + $( "#prefWin" ).dialog( "open" ); + }); + // $('#prefWin').bind('dialogclose', function(event) { + // //when dialog is closed, update the Pref model with data in popup form controls + // ctl_updatePrefs(); + // }); // set up eraser brush and clear buttons: diff --git a/fretboard.css b/fretboard.css index ff5bd06..091acd0 100644 --- a/fretboard.css +++ b/fretboard.css @@ -71,8 +71,8 @@ div#fretboard_container width:1289px; } #message {float:right; display: inline; padding-top: 6px;} -#btnHelp {float:right; padding:3px; width: 24px; height: 24px; font-weight:bold; border-radius: 5px; margin-left: 24px; background-color: white; border: #b5b5b5 solid 1px; } - +#btnHelp {float:right; width: 16px; height:16px; padding:0; margin-left: 4px; } +#btnPref {float:right; width: 16px; height:16px; padding:0; margin-left: 4px; } #diagram_title { font-size:25px; font-weight:bold; margin:0 0 0 15px; display:block; padding:4px; border:0; width:auto; float:left; } div.h_ctrl_cnt{ padding:10px; margin:0px 10px 0px 10px; } @@ -125,6 +125,24 @@ input.color_button { width:40px; border-radius: 5px; margin-left: 8px; } .tabs-nohdr .ui-tabs-anchor{ font-weight:normal; } + +.prefTabs{ + font-size: 11px; +} + +.prefTabs .pref_hSpan{ + margin: 0 16px 0 0; +} + +.prefTabs h3 { + margin-bottom: 6px; +} + +.prefTabs .RR_scaleOptionsCol{ + display:block; + float: left; + margin-right: 12px; +} /* must be under tabs-nohdr */ div#notegroupsUnabridged { font-size:12px; diff --git a/fretboard.html b/fretboard.html index 4d1cf97..40bbe37 100644 --- a/fretboard.html +++ b/fretboard.html @@ -7,6 +7,8 @@ + + @@ -14,6 +16,7 @@ + + + jquery.ga.js | Google analytics implementation for jQuery. + + + +

jQuery Storage

+ +
+

localStorage

+
+
+ $.localStorage('', ' '); + +
+ +
+ $.localStorage(''); + +
+ +
+ $.localStorage('', null); + +
+
+ +
+

sessionStorage

+
+
+
+ + + + + + + + + +
+ +
+ + - No documentation yet - + + + +
+ + + + + + \ No newline at end of file diff --git a/jquery.storage.js-master/jquery.storage.js b/jquery.storage.js-master/jquery.storage.js new file mode 100644 index 0000000..4894610 --- /dev/null +++ b/jquery.storage.js-master/jquery.storage.js @@ -0,0 +1,82 @@ +/*! + * jquery.storage.js 0.0.3 - https://github.com/yckart/jquery.storage.js + * The client-side storage for every browser, on any device. + * + * Copyright (c) 2012 Yannick Albert (http://yckart.com) + * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php). + * 2013/02/10 + **/ +;(function($, window, document) { + 'use strict'; + + $.map(['localStorage', 'sessionStorage'], function( method ) { + var defaults = { + cookiePrefix : 'fallback:' + method + ':', + cookieOptions : { + path : '/', + domain : document.domain, + expires : ('localStorage' === method) ? { expires: 365 } : undefined + } + }; + + try { + $.support[method] = method in window && window[method] !== null; + } catch (e) { + $.support[method] = false; + } + + $[method] = function(key, value) { + var options = $.extend({}, defaults, $[method].options); + + this.getItem = function( key ) { + var returns = function(key){ + return JSON.parse($.support[method] ? window[method].getItem(key) : $.cookie(options.cookiePrefix + key)); + }; + if(typeof key === 'string') return returns(key); + + var arr = [], + i = key.length; + while(i--) arr[i] = returns(key[i]); + return arr; + }; + + this.setItem = function( key, value ) { + value = JSON.stringify(value); + return $.support[method] ? window[method].setItem(key, value) : $.cookie(options.cookiePrefix + key, value, options.cookieOptions); + }; + + this.removeItem = function( key ) { + return $.support[method] ? window[method].removeItem(key) : $.cookie(options.cookiePrefix + key, null, $.extend(options.cookieOptions, { + expires: -1 + })); + }; + + this.clear = function() { + if($.support[method]) { + return window[method].clear(); + } else { + var reg = new RegExp('^' + options.cookiePrefix, ''), + opts = $.extend(options.cookieOptions, { + expires: -1 + }); + + if(document.cookie && document.cookie !== ''){ + $.map(document.cookie.split(';'), function( cookie ){ + if(reg.test(cookie = $.trim(cookie))) { + $.cookie( cookie.substr(0,cookie.indexOf('=')), null, opts); + } + }); + } + } + }; + + if (typeof key !== "undefined") { + return typeof value !== "undefined" ? ( value === null ? this.removeItem(key) : this.setItem(key, value) ) : this.getItem(key); + } + + return this; + }; + + $[method].options = defaults; + }); +}(jQuery, window, document)); \ No newline at end of file diff --git a/jquery.storage.js-master/localstorage.jquery.json b/jquery.storage.js-master/localstorage.jquery.json new file mode 100644 index 0000000..9eb4402 --- /dev/null +++ b/jquery.storage.js-master/localstorage.jquery.json @@ -0,0 +1,31 @@ +{ + "name": "localstorage", + "title": "jQuery Localstorage", + "description": "The client-side storage for every browser, on any device.", + "keywords": [ + "cookie", + "storage", + "localstorage", + "save", + "yckart", + "yannick", + "albert" + ], + "version": "0.0.3", + "author": { + "name": "Yannick Albert", + "email": "mail@yckart.com", + "url": "https://github.com/yckart" + }, + "licenses": [{ + "type": "MIT", + "url": "http://yckart.com/mit/" + }], + "homepage": "http://yckart.github.com/jquery.storage.js", + "demo": "http://yckart.github.com/jquery.storage.js", + "docs": "https://github.com/yckart/jquery.storage.js", + "bugs": "https://github.com/yckart/jquery.storage.js/issues", + "dependencies": { + "jquery": ">=1.6.4" + } +} \ No newline at end of file diff --git a/jquery.storage.js-master/sessionstorage.jquery.json b/jquery.storage.js-master/sessionstorage.jquery.json new file mode 100644 index 0000000..5817b37 --- /dev/null +++ b/jquery.storage.js-master/sessionstorage.jquery.json @@ -0,0 +1,31 @@ +{ + "name": "sessionstorage", + "title": "jQuery Sessionstorage", + "description": "The client-side storage for every browser, on any device.", + "keywords": [ + "cookie", + "storage", + "localstorage", + "save", + "yckart", + "yannick", + "albert" + ], + "version": "0.0.3", + "author": { + "name": "Yannick Albert", + "email": "mail@yckart.com", + "url": "https://github.com/yckart" + }, + "licenses": [{ + "type": "MIT", + "url": "http://yckart.com/mit/" + }], + "homepage": "http://yckart.github.com/jquery.storage.js", + "demo": "http://yckart.github.com/jquery.storage.js", + "docs": "https://github.com/yckart/jquery.storage.js", + "bugs": "https://github.com/yckart/jquery.storage.js/issues", + "dependencies": { + "jquery": ">=1.6.4" + } +} \ No newline at end of file diff --git a/jquery.storage.js-master/storage.jquery.json b/jquery.storage.js-master/storage.jquery.json new file mode 100644 index 0000000..296742c --- /dev/null +++ b/jquery.storage.js-master/storage.jquery.json @@ -0,0 +1,31 @@ +{ + "name": "storage", + "title": "jQuery Storage", + "description": "The client-side storage for every browser, on any device.", + "keywords": [ + "cookie", + "storage", + "localstorage", + "save", + "yckart", + "yannick", + "albert" + ], + "version": "0.0.3", + "author": { + "name": "Yannick Albert", + "email": "mail@yckart.com", + "url": "https://github.com/yckart" + }, + "licenses": [{ + "type": "MIT", + "url": "http://yckart.com/mit/" + }], + "homepage": "http://yckart.github.com/jquery.storage.js", + "demo": "http://yckart.github.com/jquery.storage.js", + "docs": "https://github.com/yckart/jquery.storage.js", + "bugs": "https://github.com/yckart/jquery.storage.js/issues", + "dependencies": { + "jquery": ">=1.6.4" + } +} \ No newline at end of file diff --git a/storage.js-master/.DS_Store b/storage.js-master/.DS_Store new file mode 100644 index 0000000..f1466f0 Binary files /dev/null and b/storage.js-master/.DS_Store differ diff --git a/storage.js-master/LICENSE.txt b/storage.js-master/LICENSE.txt new file mode 100644 index 0000000..f5fedcf --- /dev/null +++ b/storage.js-master/LICENSE.txt @@ -0,0 +1,25 @@ +STORAGE.JS IS DOUBLE LICENSED UNDER THE MIT LICENSE AND GPL LICENSE + +MIT LICENSE + +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. + +GPL LICENSE + +A jquery plugin for simple page editing that uses HTML5 content editable and HTML5 localStorage + Copyright (C) 2011 Ethan Kramer + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . diff --git a/storage.js-master/README.md b/storage.js-master/README.md new file mode 100644 index 0000000..02ad031 --- /dev/null +++ b/storage.js-master/README.md @@ -0,0 +1,101 @@ +Storage.js v2.0 +========= + +If you've created a site (or sites) or know of a site (or sites) using Storage.js, add its URL the official ["Sites using Storage.js wiki"](https://github.com/ekdevdes/storage.js/wiki/Sites-using-Storage.js). + +Please note that the coffescript file will be updated from now on but will remain for reference. + +Usage +----- +[Need an example of using Storage.js to save the new text of the element to your Database? Look no further.](http://ethankr.com/projects/storagejs/ajax-example/) + +First include the latest version of jQuery + +``` html + +``` + +Next, include Storage.js and Cookies.js (a dependency of Storage.js used for IE Support) in your project + +Please Note: You can find the unminified version at: http://cdn.jsdelivr.net/storagejs/2.0/storage.js + +``` html + + +``` + +Last but not least, call Storage.js on whatever elements you wish to editable. + +``` javascript +$('#theElement').storage({storageKey:'storageKey'}); +``` + ++ $('#element') is the element you want the HTML5 contentEditable attribute to placed on ++ The 'storageKey' is what will the element's key will be in localStorage ++ For a complete list of options you can pass please refer to the [API & Options Section of the Website](http://ek.alphaschildren.org/projects/storagejs/#api-options) + +__That's it! Have Fun!__ + +TODO +---- + ++ Add `data-*` attribute support + + +Bug Reporter & Feature Requests +------------ + +Please report any bugs here on Github. + +[http://github.com/ekdevdes/storage.js/issues](http://github.com/ekdevdes/storage.js/issues) + +Thank you. + +Contributing +------------ + +If you would like to contribute to Storage.js please do the following: + ++ Fork this repo ++ Make your changes ++ Update example/index.html (the docs) with your change ++ Minify the javascript ++ Send me a pull request + +Thank you :) + +Credits +------- + +Anyone that uses this plugin, I would much appreciate it if you emailed me (at ethankr@comcast.net) the URL of the site you are going to use Storage.js on and (optionally) a logo for your site that I may showcase your website on Storage.js's website :). + +Thank you. + +License +------- + +STORAGE.JS IS DOUBLE LICENSED UNDER THE MIT LICENSE AND GPL LICENSE + +MIT LICENSE + +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. + +GPL LICENSE + +A jquery plugin for simple page editing that uses HTML5 content editable and HTML5 localStorage + Copyright (C) 2011 Ethan Kramer + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . diff --git a/storage.js-master/cookies.js b/storage.js-master/cookies.js new file mode 100644 index 0000000..2f837f2 --- /dev/null +++ b/storage.js-master/cookies.js @@ -0,0 +1,2 @@ +// Copyright (c) 2012 Florian H., https://github.com/js-coder https://github.com/js-coder/cookie.js +!function(h,j){function c(){return c.get.apply(c,arguments)}var g={isArray:Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},d:function(a){return a===Object(a)},e:function(a){return Array.prototype.slice.call(a)},c:Object.keys||function(a){var e=[],b="";for(b in a)a.hasOwnProperty(b)&&e.push(b);return e},a:function(a,e){return a===j?e:a}};c.set=function(a,e,b){if(g.d(a))for(var d in a)a.hasOwnProperty(d)&&this.set(d,a[d]);else{b=b||{};d=b.b||"";var f=typeof d,c=b.path?";path="+b.path:"",i=b.domain?";domain="+b.domain:"",b=b.g?";secure":"";"string"===f&&""!==d?d=";expires="+d:"number"==f?(f=new Date,f.setTime(f.getTime()+86400*d),d=";expires="+f.toGMTString()):d.hasOwnProperty("toGMTString")&&(d=";expires="+d.toGMTString());h.cookie=escape(a)+"="+escape(e)+d+c+i+b}return this};c.remove=function(a){for(var a=g.isArray(a)?a:g.e(arguments),e=0,b=a.length;e + + + + Storage.js, Simple HTML5 Page Edits + + + + + + + +
+
+

Storage.js

+

Simple HTML5 page edits. Storage.js uses the new HTML5 contenteditable attribute and localStorage to bring you HTML5 awesomeness.

+
+
+

I am an example, click me!

+

So am I, click me too! Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctu.

+

I'm another example. Go ahead, click me to change my text, click somewhere random on the page then refresh the browser. My text will still say what you just changed it too a few seconds ago!

Now try this...

Go ahead, click me to change my text again then click somewhere random on the page. After that, quit your browser, that's right quit it! Next, come back to this page ... notice how my text is still what you just changed it too!

+

I'm an example of the onStart event. Click me to change my text!

+

I'm an example of the onExit event. Click me to change my text, then click somewhere random on the page to see me in action.

+

I'm an example of the the onStart & onExit events. Click me to change my text, then click somewhere random on the page to see me in action.

+

I'm an example of the revert option. Click me to change my text then click somewhere random on the page.
I am unique because my text isn't persistent across browser refreshes. You can still edit my text though, and it will remain what you just changed it too, but only until the next time you refresh your browser.

+

+

I'm an example of the beforeSave event. Click me to change my text, then click somewhere random on the page and watch what happens.

+

+

I'm an example of the afterSave event. Click me to change my text, then click somewhere random on the page and watch what happens.

+

+

I'm an example of both the beforeSave & afterSave events. Click me to change my text, then click somewhere random on the page and watch what happens.

+

+

I am an example of the store option. Im similar to the revert option except my text doesn't get saved to localStorage. Useful if you have a huge table of data you want to 'Storagify' but don't want to bloat localStorage with a key for each table cell. The onStart and onExit events still work and my text is still editable, in fact...click me to change my text, then click somewhere random on the page. After someone edits me, you could do an AJAX request with my new value in the onExit event (optionally passing through the elem and text paramters described below)

+
+
+

API & Options

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OptionTypeDefaultDescription
storageKeyString'storageKey'This will be the elements key in localStorage
onStart +
+
+
    +
  • elem
  • +
  • text
  • +
+
Function +
+
+
    +
  • Parameter
  • +
  • Parameter
  • +
+
Nothing +
+
+
    +
  • Nothing
  • +
  • Nothing
  • +
+
This event is triggered when the the element has focus + +
+
+
    +
  • An optional parameter of the onStart function that returns the current element as a 'jQuerified' Object
  • +
  • An optional parameter of the onStart function that returns the current text of the element.
  • +
+
onExit +
+
+
    +
  • elem
  • +
  • text
  • +
+
Function +
+
+
    +
  • Parameter
  • +
  • Parameter
  • +
+
Nothing +
+
+
    +
  • Nothing
  • +
  • Nothing
  • +
+
This event is triggered when the element has lost focus, when the user has clicked away from the element. Useful for doing AJAX request with the new value of the element. +
+
+
    +
  • An optional parameter of the onExit function that returns the current element as a 'jQuerified' Object
  • +
  • An optional parameter of the onExit function that returns the current text of the element [As it may may have changed]
  • +
+
revertBooleanfalseWhen true, reverts the element's text back to what it was before Storage.js got a hold of it
beforeSave +
+
+
    +
  • elem
  • +
  • text
  • +
+
Function +
+
+
    +
  • Parameter
  • +
  • Parameter
  • +
+
Nothing +
+
+
    +
  • Nothing
  • +
  • Nothing
  • +
+
This event is triggered just before the elements text is saved to localStorage +
+
+
    +
  • An optional parameter of the onExit function that returns the current element as a 'jQuerified' Object
  • +
  • An optional parameter of the onExit function that returns the current text of the element [As it may may have changed]
  • +
+
afterSave +
+
+
    +
  • elem
  • +
  • text
  • +
+
Function +
+
+
    +
  • Parameter
  • +
  • Parameter
  • +
+
Nothing +
+
+
    +
  • Nothing
  • +
  • Nothing
  • +
+
This event is triggered just after the elements text has been succesfully saved to localStorage +
+
+
    +
  • An optional parameter of the onExit function that returns the current element as a 'jQuerified' Object
  • +
  • An optional parameter of the onExit function that returns the current text of the element [As it may may have changed]
  • +
+
storeBooleantrueWhen false, the elements text will not be saved to localStorage
+
+
+

Usage

+

First include the latest version of jQuery

+ <script src="http://code.jquery.com/jquery.min.js"></script> +

Next, download and include Storage.js

+ <script src="/path/to/storage.min.js"></script> +

Last but not least, call Storage.js on whatever elements you wish to editable.

+ $('#theElement').storage({storageKey:'storageKey'}); +
    +
  • $('#element') is the element you want the HTML5 contentEditable attribute to placed on
  • +
  • The 'storageKey' is what will the element's key will be in localStorage
  • +
  • For a complete list of options you can pass please refer to the API & Options section
  • +
+

That's it! Have Fun!

+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/storage.js-master/images/.DS_Store b/storage.js-master/images/.DS_Store new file mode 100644 index 0000000..8771e1a Binary files /dev/null and b/storage.js-master/images/.DS_Store differ diff --git a/storage.js-master/images/quilt.png b/storage.js-master/images/quilt.png new file mode 100644 index 0000000..832c5a2 Binary files /dev/null and b/storage.js-master/images/quilt.png differ diff --git a/storage.js-master/index.html b/storage.js-master/index.html new file mode 100644 index 0000000..2af63c1 --- /dev/null +++ b/storage.js-master/index.html @@ -0,0 +1,395 @@ + + + + + Storage.js, Simple HTML5 Page Edits + + + + + + + +
+
+

Storage.js

+

Simple HTML5 page edits. Storage.js uses the new HTML5 contenteditable attribute and localStorage to bring you HTML5 awesomeness.

+
+
+

I am an example, click me!

+

So am I, click me too! Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctu.

+

I'm another example. Go ahead, click me to change my text, click somewhere random on the page then refresh the browser. My text will still say what you just changed it too a few seconds ago!

Now try this...

Go ahead, click me to change my text again then click somewhere random on the page. After that, quit your browser, that's right quit it! Next, come back to this page ... notice how my text is still what you just changed it too!

+

I'm an example of the onStart event. Click me to change my text!

+

I'm an example of the onExit event. Click me to change my text, then click somewhere random on the page to see me in action.

+

I'm an example of the the onStart & onExit events. Click me to change my text, then click somewhere random on the page to see me in action.

+

I'm an example of the revert option. Click me to change my text then click somewhere random on the page.
I am unique because my text isn't persistent across browser refreshes. You can still edit my text though, and it will remain what you just changed it too, but only until the next time you refresh your browser.

+

+

I'm an example of the beforeSave event. Click me to change my text, then click somewhere random on the page and watch what happens.

+

+

I'm an example of the afterSave event. Click me to change my text, then click somewhere random on the page and watch what happens.

+

+

I'm an example of both the beforeSave & afterSave events. Click me to change my text, then click somewhere random on the page and watch what happens.

+

+

I am an example of the store option. Im similar to the revert option except my text doesn't get saved to localStorage. Useful if you have a huge table of data you want to 'Storagify' but don't want to bloat localStorage with a key for each table cell. The onStart and onExit events still work and my text is still editable, in fact...click me to change my text, then click somewhere random on the page. After someone edits me, you could do an AJAX request with my new value in the onExit event (optionally passing through the elem and text paramters described below)

+
+
+

API & Options

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OptionTypeDefaultDescription
storageKeyString'storageKey'This will be the elements key in localStorage
onStart +
+
+
    +
  • elem
  • +
  • text
  • +
+
Function +
+
+
    +
  • Parameter
  • +
  • Parameter
  • +
+
Nothing +
+
+
    +
  • Nothing
  • +
  • Nothing
  • +
+
This event is triggered when the the element has focus + +
+
+
    +
  • An optional parameter of the onStart function that returns the current element as a 'jQuerified' Object
  • +
  • An optional parameter of the onStart function that returns the current text of the element.
  • +
+
onExit +
+
+
    +
  • elem
  • +
  • text
  • +
+
Function +
+
+
    +
  • Parameter
  • +
  • Parameter
  • +
+
Nothing +
+
+
    +
  • Nothing
  • +
  • Nothing
  • +
+
This event is triggered when the element has lost focus, when the user has clicked away from the element. Useful for doing AJAX request with the new value of the element. +
+
+
    +
  • An optional parameter of the onExit function that returns the current element as a 'jQuerified' Object
  • +
  • An optional parameter of the onExit function that returns the current text of the element [As it may may have changed]
  • +
+
revertBooleanfalseWhen true, reverts the element's text back to what it was before Storage.js got a hold of it
beforeSave +
+
+
    +
  • elem
  • +
  • text
  • +
+
Function +
+
+
    +
  • Parameter
  • +
  • Parameter
  • +
+
Nothing +
+
+
    +
  • Nothing
  • +
  • Nothing
  • +
+
This event is triggered just before the elements text is saved to localStorage +
+
+
    +
  • An optional parameter of the onExit function that returns the current element as a 'jQuerified' Object
  • +
  • An optional parameter of the onExit function that returns the current text of the element [As it may may have changed]
  • +
+
afterSave +
+
+
    +
  • elem
  • +
  • text
  • +
+
Function +
+
+
    +
  • Parameter
  • +
  • Parameter
  • +
+
Nothing +
+
+
    +
  • Nothing
  • +
  • Nothing
  • +
+
This event is triggered just after the elements text has been succesfully saved to localStorage +
+
+
    +
  • An optional parameter of the onExit function that returns the current element as a 'jQuerified' Object
  • +
  • An optional parameter of the onExit function that returns the current text of the element [As it may may have changed]
  • +
+
storeBooleantrueWhen false, the elements text will not be saved to localStorage
+
+
+

Usage

+

First include the latest version of jQuery

+ <script src="http://code.jquery.com/jquery.min.js"></script> +

Next, download and include Storage.js

+ <script src="/path/to/storage.min.js"></script> +

Last but not least, call Storage.js on whatever elements you wish to editable.

+ $('#theElement').storage({storageKey:'storageKey'}); +
    +
  • $('#element') is the element you want the HTML5 contentEditable attribute to placed on
  • +
  • The 'storageKey' is what will the element's key will be in localStorage
  • +
  • For a complete list of options you can pass please refer to the API & Options section
  • +
+

That's it! Have Fun!

+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/storage.js-master/storage.jquery.json b/storage.js-master/storage.jquery.json new file mode 100644 index 0000000..e661491 --- /dev/null +++ b/storage.js-master/storage.jquery.json @@ -0,0 +1,38 @@ +{ + "name":"storage", + "version":"2.0.0", + "title":"Storage.js", + "author":{ + "name" : "Ethan Kramer", + "url" : "http://ek.alphaschildren.org" + }, + "licenses" : [ + { + "type" : "MIT", + "url" : "https://github.com/ekdevdes/storage.js/2.0.0/LICENSE.txt" + } + ], + "dependencies" : { + "jquery" : ">=1.5" + }, + "keywords" :[ + "html5", + "local", + "page", + "edit", + "inline", + "storage", + "editing", + "jquery", + "javascript" + ], + "bugs": "https://github.com/ekdevdes/storage.js/issues", + "homepage": "https://github.com/ekdevdes/storage-js", + "docs": "https://ethankr.com/projects/storagejs", + "maintainers" : [ + { + "name" : "Ethan Kramer", + "url" : "http://ethankr.com" + } + ] +} \ No newline at end of file diff --git a/storage.js-master/storage.js b/storage.js-master/storage.js new file mode 100644 index 0000000..53f8241 --- /dev/null +++ b/storage.js-master/storage.js @@ -0,0 +1,162 @@ +/* + Storage.js v1.6.2 + + Storage.js jQuery Plugin (C) 2011 Ethan Kramer + + STORAGE.JS IS DOUBLE LICENSED UNDER THE MIT LICENSE AND GPL LICENSE + + MIT LICENSE + + 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. + + GPL LICENSE + + A jquery plugin for simple page editing that uses HTML5 content editable and HTML5 localStorage + Copyright (C) 2011 Ethan Kramer + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + + +(function ($){ + + $.fn.storage = function(options){ + + var defaults = { + onStart:function(){}, + onExit:function(){}, + beforeSave:function(){}, + afterSave:function(){}, + storageKey:'storageKey', + revert:false, + store:true + }, + settings = $.extend({},defaults,options); + + var objects = $(this), + keys = []; + + if (settings.store) { + + + for (var i=0; i < objects.length; i++) { + + key = settings.storageKey + '-' + i; + $(objects[i]).attr('data-orig-text',$(objects[i]).text()); + + if (settings.revert) { + + // set localstorage and cookies.js to the current value of the element + + localStorage.setItem(key,$(objects[i]).data('orig-text')); + cookie.set(key,$(objects[i]).data('orig-text')); + $(objects[i]).text($(objects[i]).data('orig-text')); + + if ($(objects[i]).text() == "" || $(objects[i]).text() == "null") { + $(objects[i]).text($(objects[i]).data('orig-text')); + } + + //and cookies.js + + }else{ + + + $(objects[i]).text(localStorage.getItem(key)); + $(objects[i]).text(cookie.get(key)); + + if ($(objects[i]).text() == "" || $(objects[i]).text() == "null") { + $(objects[i]).text($(objects[i]).data('orig-text')); + } + + // and cookies.js + } + + keys.push(key); + $(objects[i]).attr('data-key',key); + + + } + } + + + return this.each(function(){ + + var $this = $(this), + sKey = $this.data('key'); + + $this.attr('contenteditable',''); + + + // when the user has clicked on the element + $this.focus(function(){ + + var focusText = $(this).text(); + + // add a class of sf-focus to the element + $this.addClass("sf-focus"); + + // call the function the user passed in + settings.onStart.apply(this,[$(this),focusText]); + + }); + + // after the user has clicked away from the element + $this.blur(function(){ + + var blurText = $(this).text(); + + // remove the sf-focus class + $this.removeClass("sf-focus"); + + // add an sf-blur class + $this.addClass("sf-blur"); + + // then call the onExit function + + settings.onExit.apply(this,[$(this),blurText]); + + // save new text to localStorage + + if (settings.store) { + + // call the before save function + settings.beforeSave.apply(this,[$(this),blurText]); + + // save new text of element to localstorage + localStorage.setItem(sKey,blurText); + + // save it to cookies.js + cookie.set(sKey,blurText); + + // call the afterSave function + settings.afterSave.apply(this,[$(this),blurText]); + + + + } + + // remove the class sf-blur + + $this.removeClass("sf-blur"); + + }); + + + }); + }; + +})(jQuery); \ No newline at end of file diff --git a/storage.js-master/storage.min.js b/storage.js-master/storage.min.js new file mode 100644 index 0000000..2591099 --- /dev/null +++ b/storage.js-master/storage.min.js @@ -0,0 +1 @@ +(function(a){a.fn.storage=function(b){var g={onStart:function(){},onExit:function(){},beforeSave:function(){},afterSave:function(){},storageKey:"storageKey",revert:false,store:true},d=a.extend({},g,b);var f=a(this),e=[];if(d.store){for(var c=0;c