Permalink
Browse files

+ making Picky JS code customizable

  • Loading branch information...
1 parent 274fc46 commit 12a18b332a402109fc4f8a7760cf5a890d84f348 @floere committed Feb 3, 2012

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
@@ -220,7 +220,7 @@ function AllocationRenderer(allocationChosenCallback, config) {
return self;
};
- //
+ // TODO Extract.
//
var listItem = function(text, count) {
return $('<li><div class="text">' + text + '</div><div class="count">' + count + '</div></li>');
@@ -1,9 +1,9 @@
var PickyAllocationsCloud = function(view, config) {
- var allocations = $(config['allocationsSelector'] || '#picky .allocations');
- var shownAllocations = allocations.find('.shown');
- var showMoreAllocations = allocations.find('.more');
- var hiddenAllocations = allocations.find('.hidden');
+ var allocations = config['allocations'];
+ var shownAllocations = config['shownAllocations'];
+ var showMoreAllocations = config['showMoreAllocations'];
+ var hiddenAllocations = config['hiddenAllocations'];
// Show the cloud.
//
@@ -48,7 +48,7 @@ var PickyAllocationsCloud = function(view, config) {
var renderList = function(list) {
if (list.length == 0) {
- return $('#search .allocations').hide();
+ return allocations.hide();
}
var maxSuggestions = 3;
clearAllocationCloud();
@@ -67,7 +67,7 @@ var PickyAllocationsCloud = function(view, config) {
shownAllocations.append(item);
});
}
- return $('#search .allocations').show();
+ return allocations.show();
};
// Render the allocation list.
@@ -1,12 +1,38 @@
var Localization = {};
+var PickyI18n = { };
+
+// Set the correct locale for all js code.
+//
+$(function() {
+ PickyI18n.locale = $('html').attr('lang').split('-')[0] || 'en';
+});
// The client handles parameters and
// offers an insert method.
//
var PickyClient = function(config) {
- // Params handling.
+ // The following part handles all of the parameters.
+ // jQuery selectors are executed.
+ //
+
+ // View config.
//
+ config['input'] = $(config['inputSelector'] || '#picky input.query');
+ config['reset'] = $(config['resetSelector'] || '#picky div.reset');
+ config['button'] = $(config['buttonSelector'] || '#picky input.search_button');
+ config['counter'] = $(config['counterSelector'] || '#picky div.status');
+ config['dashboard'] = $(config['dashboardSelector'] || '#picky .dashboard');
+ config['results'] = $(config['resultsSelector'] || '#picky div.results');
+ config['noResults'] = $(config['noResultsSelector'] || '#picky .no_results');
+
+ // Allocations cloud.
+ //
+ config['allocations'] = $(config['allocationsSelector'] || '#picky .allocations');
+ config['shownAllocations'] = config['allocations'].find('.shown');
+ config['showMoreAllocations'] = config['allocations'].find('.more');
+ config['hiddenAllocations'] = config['allocations'].find('.hidden');
+
// This is used to generate the correct query strings, localized.
//
@@ -1,12 +1,5 @@
// Translations
//
-var PickyI18n = { };
-
-// Set the correct locale for all js code.
-//
-$(function() {
- PickyI18n.locale = $('html').attr('lang').split('-')[0] || 'en';
-});
var dictionary = {
common:{
@@ -5,17 +5,18 @@ var PickyView = function(picky_controller, config) {
var showResultsLimit = config.showResultsLimit || 10;
- var searchField = $(config['inputSelector'] || '#picky input.query');
- var clearButton = $(config['resetSelector'] || '#picky div.reset');
- var searchButton = $(config['buttonSelector'] || '#picky input.search_button');
- var resultCounter = $(config['counterSelector'] || '#picky div.status');
- var dashboard = $(config['dashboardSelector'] || '#picky .dashboard');
+ var searchField = config['input'];
+ var clearButton = config['reset'];
+ var searchButton = config['button'];
+ var resultCounter = config['counter'];
+ var dashboard = config['dashboard'];
// Push into results.
- var results = $(config['resultsSelector'] || '#picky div.results');
- var noResults = $(config['noResultsSelector'] || '#picky .no_results');
+ //
+ var results = config['results'];
+ var noResults = config['noResults'];
- var addination = new PickyAddination(this, results); // Push into results.
+ var addination = new PickyAddination(this, results); // Push into results.
var allocationsCloud = new PickyAllocationsCloud(this, config);
var resultsRenderer = new PickyResultsRenderer(addination, config);
@@ -220,7 +220,7 @@ function AllocationRenderer(allocationChosenCallback, config) {
return self;
};
- //
+ // TODO Extract.
//
var listItem = function(text, count) {
return $('<li><div class="text">' + text + '</div><div class="count">' + count + '</div></li>');
@@ -1,9 +1,9 @@
var PickyAllocationsCloud = function(view, config) {
- var allocations = $(config['allocationsSelector'] || '#picky .allocations');
- var shownAllocations = allocations.find('.shown');
- var showMoreAllocations = allocations.find('.more');
- var hiddenAllocations = allocations.find('.hidden');
+ var allocations = config['allocations'];
+ var shownAllocations = config['shownAllocations'];
+ var showMoreAllocations = config['showMoreAllocations'];
+ var hiddenAllocations = config['hiddenAllocations'];
// Show the cloud.
//
@@ -48,7 +48,7 @@ var PickyAllocationsCloud = function(view, config) {
var renderList = function(list) {
if (list.length == 0) {
- return $('#search .allocations').hide();
+ return allocations.hide();
}
var maxSuggestions = 3;
clearAllocationCloud();
@@ -67,7 +67,7 @@ var PickyAllocationsCloud = function(view, config) {
shownAllocations.append(item);
});
}
- return $('#search .allocations').show();
+ return allocations.show();
};
// Render the allocation list.
@@ -1,12 +1,41 @@
var Localization = {};
+var PickyI18n = { };
+
+// Set the correct locale for all Picky js code using
+// the "lang" attribute on the "html" html element.
+//
+// Note: Default is 'en'.
+//
+$(function() {
+ PickyI18n.locale = $('html').attr('lang').split('-')[0] || 'en';
+});
// The client handles parameters and
// offers an insert method.
//
var PickyClient = function(config) {
- // Params handling.
+ // The following part handles all of the parameters.
+ // jQuery selectors are executed.
+ //
+
+ // View config.
+ //
+ config['input'] = $(config['inputSelector'] || '#picky input.query');
+ config['reset'] = $(config['resetSelector'] || '#picky div.reset');
+ config['button'] = $(config['buttonSelector'] || '#picky input.search_button');
+ config['counter'] = $(config['counterSelector'] || '#picky div.status');
+ config['dashboard'] = $(config['dashboardSelector'] || '#picky .dashboard');
+ config['results'] = $(config['resultsSelector'] || '#picky div.results');
+ config['noResults'] = $(config['noResultsSelector'] || '#picky .no_results');
+
+ // Allocations cloud.
//
+ config['allocations'] = $(config['allocationsSelector'] || '#picky .allocations');
+ config['shownAllocations'] = config['allocations'].find('.shown');
+ config['showMoreAllocations'] = config['allocations'].find('.more');
+ config['hiddenAllocations'] = config['allocations'].find('.hidden');
+
// This is used to generate the correct query strings, localized.
//
@@ -1,12 +1,5 @@
// Translations
//
-var PickyI18n = { };
-
-// Set the correct locale for all js code.
-//
-$(function() {
- PickyI18n.locale = $('html').attr('lang').split('-')[0] || 'en';
-});
var dictionary = {
common:{
@@ -5,17 +5,18 @@ var PickyView = function(picky_controller, config) {
var showResultsLimit = config.showResultsLimit || 10;
- var searchField = $(config['inputSelector'] || '#picky input.query');
- var clearButton = $(config['resetSelector'] || '#picky div.reset');
- var searchButton = $(config['buttonSelector'] || '#picky input.search_button');
- var resultCounter = $(config['counterSelector'] || '#picky div.status');
- var dashboard = $(config['dashboardSelector'] || '#picky .dashboard');
+ var searchField = config['input'];
+ var clearButton = config['reset'];
+ var searchButton = config['button'];
+ var resultCounter = config['counter'];
+ var dashboard = config['dashboard'];
// Push into results.
- var results = $(config['resultsSelector'] || '#picky div.results');
- var noResults = $(config['noResultsSelector'] || '#picky .no_results');
+ //
+ var results = config['results'];
+ var noResults = config['noResults'];
- var addination = new PickyAddination(this, results); // Push into results.
+ var addination = new PickyAddination(this, results); // Push into results.
var allocationsCloud = new PickyAllocationsCloud(this, config);
var resultsRenderer = new PickyResultsRenderer(addination, config);
Oops, something went wrong.

0 comments on commit 12a18b3

Please sign in to comment.