solidus_api_v2 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +38 -0
- data/Gemfile +13 -0
- data/LICENSE +26 -0
- data/README.md +98 -0
- data/Rakefile +37 -0
- data/app/controllers/concerns/spree/api/v2/renderable.rb +51 -0
- data/app/controllers/spree/api/v2/base_controller.rb +31 -0
- data/app/controllers/spree/api/v2/children_controller.rb +29 -0
- data/app/controllers/spree/api/v2/countries_controller.rb +21 -0
- data/app/controllers/spree/api/v2/images_controller.rb +29 -0
- data/app/controllers/spree/api/v2/line_items_controller.rb +36 -0
- data/app/controllers/spree/api/v2/option_types_controller.rb +31 -0
- data/app/controllers/spree/api/v2/option_values_controller.rb +29 -0
- data/app/controllers/spree/api/v2/orders_controller.rb +11 -0
- data/app/controllers/spree/api/v2/prices_controller.rb +27 -0
- data/app/controllers/spree/api/v2/products_controller.rb +37 -0
- data/app/controllers/spree/api/v2/states_controller.rb +29 -0
- data/app/controllers/spree/api/v2/taxonomies_controller.rb +21 -0
- data/app/controllers/spree/api/v2/taxons_controller.rb +40 -0
- data/app/controllers/spree/api/v2/variants_controller.rb +35 -0
- data/app/models/spree/base_decorator.rb +5 -0
- data/app/models/spree/image_decorator.rb +3 -0
- data/app/models/spree/price_decorator.rb +3 -0
- data/app/models/spree/state_decorator.rb +3 -0
- data/app/serializers/spree/address_serializer.rb +9 -0
- data/app/serializers/spree/base_serializer.rb +13 -0
- data/app/serializers/spree/country_serializer.rb +7 -0
- data/app/serializers/spree/error_serializer.rb +52 -0
- data/app/serializers/spree/image_serializer.rb +13 -0
- data/app/serializers/spree/line_item_serializer.rb +13 -0
- data/app/serializers/spree/option_type_serializer.rb +8 -0
- data/app/serializers/spree/option_value_serializer.rb +8 -0
- data/app/serializers/spree/order_serializer.rb +21 -0
- data/app/serializers/spree/price_serializer.rb +7 -0
- data/app/serializers/spree/product_serializer.rb +12 -0
- data/app/serializers/spree/role_serializer.rb +5 -0
- data/app/serializers/spree/state_serializer.rb +7 -0
- data/app/serializers/spree/store_serializer.rb +6 -0
- data/app/serializers/spree/taxon_serializer.rb +16 -0
- data/app/serializers/spree/taxonomy_serializer.rb +7 -0
- data/app/serializers/spree/user_serializer.rb +5 -0
- data/app/serializers/spree/variant_serializer.rb +12 -0
- data/bin/rails +7 -0
- data/circle.yml +13 -0
- data/config/locales/en.yml +25 -0
- data/config/routes.rb +53 -0
- data/docs/.nojekyll +0 -0
- data/docs/Dockerfile +12 -0
- data/docs/Gemfile +13 -0
- data/docs/README.md +12 -0
- data/docs/Rakefile +9 -0
- data/docs/config.rb +39 -0
- data/docs/font-selection.json +148 -0
- data/docs/source/fonts/slate.eot +0 -0
- data/docs/source/fonts/slate.svg +14 -0
- data/docs/source/fonts/slate.ttf +0 -0
- data/docs/source/fonts/slate.woff +0 -0
- data/docs/source/fonts/slate.woff2 +0 -0
- data/docs/source/images/logo.png +0 -0
- data/docs/source/images/navbar.png +0 -0
- data/docs/source/includes/_authentication.md +61 -0
- data/docs/source/includes/_countries.md +133 -0
- data/docs/source/includes/_errors.md +17 -0
- data/docs/source/includes/_filtering.md +11 -0
- data/docs/source/includes/_images.md +201 -0
- data/docs/source/includes/_line_items.md +137 -0
- data/docs/source/includes/_option_types.md +267 -0
- data/docs/source/includes/_option_values.md +227 -0
- data/docs/source/includes/_orders.md +75 -0
- data/docs/source/includes/_pagination.md +10 -0
- data/docs/source/includes/_prices.md +188 -0
- data/docs/source/includes/_products.md +403 -0
- data/docs/source/includes/_states.md +96 -0
- data/docs/source/includes/_taxonomies.md +325 -0
- data/docs/source/includes/_taxons.md +414 -0
- data/docs/source/includes/_variants.md +430 -0
- data/docs/source/index.md +53 -0
- data/docs/source/javascripts/all.js +4 -0
- data/docs/source/javascripts/all_nosearch.js +3 -0
- data/docs/source/javascripts/app/_lang.js +162 -0
- data/docs/source/javascripts/app/_search.js +74 -0
- data/docs/source/javascripts/app/_toc.js +55 -0
- data/docs/source/javascripts/lib/_energize.js +169 -0
- data/docs/source/javascripts/lib/_imagesloaded.min.js +7 -0
- data/docs/source/javascripts/lib/_jquery.highlight.js +108 -0
- data/docs/source/javascripts/lib/_jquery.tocify.js +1042 -0
- data/docs/source/javascripts/lib/_jquery_ui.js +566 -0
- data/docs/source/javascripts/lib/_lunr.js +1910 -0
- data/docs/source/layouts/layout.erb +102 -0
- data/docs/source/stylesheets/_icon-font.scss +38 -0
- data/docs/source/stylesheets/_normalize.css +427 -0
- data/docs/source/stylesheets/_syntax.scss.erb +27 -0
- data/docs/source/stylesheets/_variables.scss +109 -0
- data/docs/source/stylesheets/print.css.scss +142 -0
- data/docs/source/stylesheets/screen.css.scss +622 -0
- data/lib/solidus_api_v2.rb +5 -0
- data/lib/spree_api_v2/engine.rb +21 -0
- data/lib/spree_api_v2.rb +4 -0
- data/solidus_api_v2.gemspec +36 -0
- data/spec/controllers/spree/api/v2/children_controller_spec.rb +28 -0
- data/spec/controllers/spree/api/v2/countries_controller_spec.rb +25 -0
- data/spec/controllers/spree/api/v2/images_controller_spec.rb +93 -0
- data/spec/controllers/spree/api/v2/line_items_controller_spec.rb +86 -0
- data/spec/controllers/spree/api/v2/option_types_controller_spec.rb +73 -0
- data/spec/controllers/spree/api/v2/option_values_controller_spec.rb +88 -0
- data/spec/controllers/spree/api/v2/orders_controller_spec.rb +15 -0
- data/spec/controllers/spree/api/v2/prices_controller_spec.rb +55 -0
- data/spec/controllers/spree/api/v2/products_controller_spec.rb +95 -0
- data/spec/controllers/spree/api/v2/states_controller_spec.rb +42 -0
- data/spec/controllers/spree/api/v2/taxonomies_controller_spec.rb +31 -0
- data/spec/controllers/spree/api/v2/taxons_controller_spec.rb +54 -0
- data/spec/controllers/spree/api/v2/variants_controller_spec.rb +108 -0
- data/spec/models/spree/base_decorator_spec.rb +9 -0
- data/spec/models/spree/price_decorator_spec.rb +3 -0
- data/spec/serializers/spree/address_serializer_spec.rb +35 -0
- data/spec/serializers/spree/country_serializer_spec.rb +27 -0
- data/spec/serializers/spree/error_serializer_spec.rb +116 -0
- data/spec/serializers/spree/image_serializer_spec.rb +30 -0
- data/spec/serializers/spree/line_item_serializer_spec.rb +40 -0
- data/spec/serializers/spree/option_type_serializer_spec.rb +27 -0
- data/spec/serializers/spree/option_value_serializer_spec.rb +29 -0
- data/spec/serializers/spree/order_serializer_spec.rb +69 -0
- data/spec/serializers/spree/price_serializer_spec.rb +28 -0
- data/spec/serializers/spree/product_serializer_spec.rb +47 -0
- data/spec/serializers/spree/role_serializer_spec.rb +17 -0
- data/spec/serializers/spree/state_serializer_spec.rb +25 -0
- data/spec/serializers/spree/store_serializer_spec.rb +25 -0
- data/spec/serializers/spree/taxon_serializer_spec.rb +44 -0
- data/spec/serializers/spree/taxonomy_serializer_spec.rb +27 -0
- data/spec/serializers/spree/user_serializer_spec.rb +17 -0
- data/spec/serializers/spree/variant_serializer_spec.rb +55 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/shoulda_matchers.rb +6 -0
- data/spree_api_v2.gemspec +36 -0
- metadata +437 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//= require ../lib/_lunr
|
|
2
|
+
//= require ../lib/_jquery.highlight
|
|
3
|
+
(function () {
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
var content, searchResults;
|
|
7
|
+
var highlightOpts = { element: 'span', className: 'search-highlight' };
|
|
8
|
+
|
|
9
|
+
var index = new lunr.Index();
|
|
10
|
+
|
|
11
|
+
index.ref('id');
|
|
12
|
+
index.field('title', { boost: 10 });
|
|
13
|
+
index.field('body');
|
|
14
|
+
index.pipeline.add(lunr.trimmer, lunr.stopWordFilter);
|
|
15
|
+
|
|
16
|
+
$(populate);
|
|
17
|
+
$(bind);
|
|
18
|
+
|
|
19
|
+
function populate() {
|
|
20
|
+
$('h1, h2').each(function() {
|
|
21
|
+
var title = $(this);
|
|
22
|
+
var body = title.nextUntil('h1, h2');
|
|
23
|
+
index.add({
|
|
24
|
+
id: title.prop('id'),
|
|
25
|
+
title: title.text(),
|
|
26
|
+
body: body.text()
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function bind() {
|
|
32
|
+
content = $('.content');
|
|
33
|
+
searchResults = $('.search-results');
|
|
34
|
+
|
|
35
|
+
$('#input-search').on('keyup', search);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function search(event) {
|
|
39
|
+
unhighlight();
|
|
40
|
+
searchResults.addClass('visible');
|
|
41
|
+
|
|
42
|
+
// ESC clears the field
|
|
43
|
+
if (event.keyCode === 27) this.value = '';
|
|
44
|
+
|
|
45
|
+
if (this.value) {
|
|
46
|
+
var results = index.search(this.value).filter(function(r) {
|
|
47
|
+
return r.score > 0.0001;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (results.length) {
|
|
51
|
+
searchResults.empty();
|
|
52
|
+
$.each(results, function (index, result) {
|
|
53
|
+
var elem = document.getElementById(result.ref);
|
|
54
|
+
searchResults.append("<li><a href='#" + result.ref + "'>" + $(elem).text() + "</a></li>");
|
|
55
|
+
});
|
|
56
|
+
highlight.call(this);
|
|
57
|
+
} else {
|
|
58
|
+
searchResults.html('<li></li>');
|
|
59
|
+
$('.search-results li').text('No Results Found for "' + this.value + '"');
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
unhighlight();
|
|
63
|
+
searchResults.removeClass('visible');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function highlight() {
|
|
68
|
+
if (this.value) content.highlight(this.value, highlightOpts);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function unhighlight() {
|
|
72
|
+
content.unhighlight(highlightOpts);
|
|
73
|
+
}
|
|
74
|
+
})();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//= require ../lib/_jquery_ui
|
|
2
|
+
//= require ../lib/_jquery.tocify
|
|
3
|
+
//= require ../lib/_imagesloaded.min
|
|
4
|
+
(function (global) {
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
var closeToc = function() {
|
|
8
|
+
$(".tocify-wrapper").removeClass('open');
|
|
9
|
+
$("#nav-button").removeClass('open');
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
var makeToc = function() {
|
|
13
|
+
global.toc = $("#toc").tocify({
|
|
14
|
+
selectors: 'h1, h2',
|
|
15
|
+
extendPage: false,
|
|
16
|
+
theme: 'none',
|
|
17
|
+
smoothScroll: false,
|
|
18
|
+
showEffectSpeed: 0,
|
|
19
|
+
hideEffectSpeed: 180,
|
|
20
|
+
ignoreSelector: '.toc-ignore',
|
|
21
|
+
highlightOffset: 60,
|
|
22
|
+
scrollTo: -1,
|
|
23
|
+
scrollHistory: true,
|
|
24
|
+
hashGenerator: function (text, element) {
|
|
25
|
+
return element.prop('id');
|
|
26
|
+
}
|
|
27
|
+
}).data('toc-tocify');
|
|
28
|
+
|
|
29
|
+
$("#nav-button").click(function() {
|
|
30
|
+
$(".tocify-wrapper").toggleClass('open');
|
|
31
|
+
$("#nav-button").toggleClass('open');
|
|
32
|
+
return false;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
$(".page-wrapper").click(closeToc);
|
|
36
|
+
$(".tocify-item").click(closeToc);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Hack to make already open sections to start opened,
|
|
40
|
+
// instead of displaying an ugly animation
|
|
41
|
+
function animate() {
|
|
42
|
+
setTimeout(function() {
|
|
43
|
+
toc.setOption('showEffectSpeed', 180);
|
|
44
|
+
}, 50);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
$(function() {
|
|
48
|
+
makeToc();
|
|
49
|
+
animate();
|
|
50
|
+
$('.content').imagesLoaded( function() {
|
|
51
|
+
global.toc.calculateHeights();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
})(window);
|
|
55
|
+
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* energize.js v0.1.0
|
|
3
|
+
*
|
|
4
|
+
* Speeds up click events on mobile devices.
|
|
5
|
+
* https://github.com/davidcalhoun/energize.js
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
(function() { // Sandbox
|
|
9
|
+
/**
|
|
10
|
+
* Don't add to non-touch devices, which don't need to be sped up
|
|
11
|
+
*/
|
|
12
|
+
if(!('ontouchstart' in window)) return;
|
|
13
|
+
|
|
14
|
+
var lastClick = {},
|
|
15
|
+
isThresholdReached, touchstart, touchmove, touchend,
|
|
16
|
+
click, closest;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* isThresholdReached
|
|
20
|
+
*
|
|
21
|
+
* Compare touchstart with touchend xy coordinates,
|
|
22
|
+
* and only fire simulated click event if the coordinates
|
|
23
|
+
* are nearby. (don't want clicking to be confused with a swipe)
|
|
24
|
+
*/
|
|
25
|
+
isThresholdReached = function(startXY, xy) {
|
|
26
|
+
return Math.abs(startXY[0] - xy[0]) > 5 || Math.abs(startXY[1] - xy[1]) > 5;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* touchstart
|
|
31
|
+
*
|
|
32
|
+
* Save xy coordinates when the user starts touching the screen
|
|
33
|
+
*/
|
|
34
|
+
touchstart = function(e) {
|
|
35
|
+
this.startXY = [e.touches[0].clientX, e.touches[0].clientY];
|
|
36
|
+
this.threshold = false;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* touchmove
|
|
41
|
+
*
|
|
42
|
+
* Check if the user is scrolling past the threshold.
|
|
43
|
+
* Have to check here because touchend will not always fire
|
|
44
|
+
* on some tested devices (Kindle Fire?)
|
|
45
|
+
*/
|
|
46
|
+
touchmove = function(e) {
|
|
47
|
+
// NOOP if the threshold has already been reached
|
|
48
|
+
if(this.threshold) return false;
|
|
49
|
+
|
|
50
|
+
this.threshold = isThresholdReached(this.startXY, [e.touches[0].clientX, e.touches[0].clientY]);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* touchend
|
|
55
|
+
*
|
|
56
|
+
* If the user didn't scroll past the threshold between
|
|
57
|
+
* touchstart and touchend, fire a simulated click.
|
|
58
|
+
*
|
|
59
|
+
* (This will fire before a native click)
|
|
60
|
+
*/
|
|
61
|
+
touchend = function(e) {
|
|
62
|
+
// Don't fire a click if the user scrolled past the threshold
|
|
63
|
+
if(this.threshold || isThresholdReached(this.startXY, [e.changedTouches[0].clientX, e.changedTouches[0].clientY])) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Create and fire a click event on the target element
|
|
69
|
+
* https://developer.mozilla.org/en/DOM/event.initMouseEvent
|
|
70
|
+
*/
|
|
71
|
+
var touch = e.changedTouches[0],
|
|
72
|
+
evt = document.createEvent('MouseEvents');
|
|
73
|
+
evt.initMouseEvent('click', true, true, window, 0, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
|
|
74
|
+
evt.simulated = true; // distinguish from a normal (nonsimulated) click
|
|
75
|
+
e.target.dispatchEvent(evt);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* click
|
|
80
|
+
*
|
|
81
|
+
* Because we've already fired a click event in touchend,
|
|
82
|
+
* we need to listed for all native click events here
|
|
83
|
+
* and suppress them as necessary.
|
|
84
|
+
*/
|
|
85
|
+
click = function(e) {
|
|
86
|
+
/**
|
|
87
|
+
* Prevent ghost clicks by only allowing clicks we created
|
|
88
|
+
* in the click event we fired (look for e.simulated)
|
|
89
|
+
*/
|
|
90
|
+
var time = Date.now(),
|
|
91
|
+
timeDiff = time - lastClick.time,
|
|
92
|
+
x = e.clientX,
|
|
93
|
+
y = e.clientY,
|
|
94
|
+
xyDiff = [Math.abs(lastClick.x - x), Math.abs(lastClick.y - y)],
|
|
95
|
+
target = closest(e.target, 'A') || e.target, // needed for standalone apps
|
|
96
|
+
nodeName = target.nodeName,
|
|
97
|
+
isLink = nodeName === 'A',
|
|
98
|
+
standAlone = window.navigator.standalone && isLink && e.target.getAttribute("href");
|
|
99
|
+
|
|
100
|
+
lastClick.time = time;
|
|
101
|
+
lastClick.x = x;
|
|
102
|
+
lastClick.y = y;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Unfortunately Android sometimes fires click events without touch events (seen on Kindle Fire),
|
|
106
|
+
* so we have to add more logic to determine the time of the last click. Not perfect...
|
|
107
|
+
*
|
|
108
|
+
* Older, simpler check: if((!e.simulated) || standAlone)
|
|
109
|
+
*/
|
|
110
|
+
if((!e.simulated && (timeDiff < 500 || (timeDiff < 1500 && xyDiff[0] < 50 && xyDiff[1] < 50))) || standAlone) {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
e.stopPropagation();
|
|
113
|
+
if(!standAlone) return false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Special logic for standalone web apps
|
|
118
|
+
* See http://stackoverflow.com/questions/2898740/iphone-safari-web-app-opens-links-in-new-window
|
|
119
|
+
*/
|
|
120
|
+
if(standAlone) {
|
|
121
|
+
window.location = target.getAttribute("href");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Add an energize-focus class to the targeted link (mimics :focus behavior)
|
|
126
|
+
* TODO: test and/or remove? Does this work?
|
|
127
|
+
*/
|
|
128
|
+
if(!target || !target.classList) return;
|
|
129
|
+
target.classList.add("energize-focus");
|
|
130
|
+
window.setTimeout(function(){
|
|
131
|
+
target.classList.remove("energize-focus");
|
|
132
|
+
}, 150);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* closest
|
|
137
|
+
* @param {HTMLElement} node current node to start searching from.
|
|
138
|
+
* @param {string} tagName the (uppercase) name of the tag you're looking for.
|
|
139
|
+
*
|
|
140
|
+
* Find the closest ancestor tag of a given node.
|
|
141
|
+
*
|
|
142
|
+
* Starts at node and goes up the DOM tree looking for a
|
|
143
|
+
* matching nodeName, continuing until hitting document.body
|
|
144
|
+
*/
|
|
145
|
+
closest = function(node, tagName){
|
|
146
|
+
var curNode = node;
|
|
147
|
+
|
|
148
|
+
while(curNode !== document.body) { // go up the dom until we find the tag we're after
|
|
149
|
+
if(!curNode || curNode.nodeName === tagName) { return curNode; } // found
|
|
150
|
+
curNode = curNode.parentNode; // not found, so keep going up
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return null; // not found
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Add all delegated event listeners
|
|
158
|
+
*
|
|
159
|
+
* All the events we care about bubble up to document,
|
|
160
|
+
* so we can take advantage of event delegation.
|
|
161
|
+
*
|
|
162
|
+
* Note: no need to wait for DOMContentLoaded here
|
|
163
|
+
*/
|
|
164
|
+
document.addEventListener('touchstart', touchstart, false);
|
|
165
|
+
document.addEventListener('touchmove', touchmove, false);
|
|
166
|
+
document.addEventListener('touchend', touchend, false);
|
|
167
|
+
document.addEventListener('click', click, true); // TODO: why does this use capture?
|
|
168
|
+
|
|
169
|
+
})();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* imagesLoaded PACKAGED v3.1.8
|
|
3
|
+
* JavaScript is all like "You images are done yet or what?"
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
(function(){function e(){}function t(e,t){for(var n=e.length;n--;)if(e[n].listener===t)return n;return-1}function n(e){return function(){return this[e].apply(this,arguments)}}var i=e.prototype,r=this,o=r.EventEmitter;i.getListeners=function(e){var t,n,i=this._getEvents();if("object"==typeof e){t={};for(n in i)i.hasOwnProperty(n)&&e.test(n)&&(t[n]=i[n])}else t=i[e]||(i[e]=[]);return t},i.flattenListeners=function(e){var t,n=[];for(t=0;e.length>t;t+=1)n.push(e[t].listener);return n},i.getListenersAsObject=function(e){var t,n=this.getListeners(e);return n instanceof Array&&(t={},t[e]=n),t||n},i.addListener=function(e,n){var i,r=this.getListenersAsObject(e),o="object"==typeof n;for(i in r)r.hasOwnProperty(i)&&-1===t(r[i],n)&&r[i].push(o?n:{listener:n,once:!1});return this},i.on=n("addListener"),i.addOnceListener=function(e,t){return this.addListener(e,{listener:t,once:!0})},i.once=n("addOnceListener"),i.defineEvent=function(e){return this.getListeners(e),this},i.defineEvents=function(e){for(var t=0;e.length>t;t+=1)this.defineEvent(e[t]);return this},i.removeListener=function(e,n){var i,r,o=this.getListenersAsObject(e);for(r in o)o.hasOwnProperty(r)&&(i=t(o[r],n),-1!==i&&o[r].splice(i,1));return this},i.off=n("removeListener"),i.addListeners=function(e,t){return this.manipulateListeners(!1,e,t)},i.removeListeners=function(e,t){return this.manipulateListeners(!0,e,t)},i.manipulateListeners=function(e,t,n){var i,r,o=e?this.removeListener:this.addListener,s=e?this.removeListeners:this.addListeners;if("object"!=typeof t||t instanceof RegExp)for(i=n.length;i--;)o.call(this,t,n[i]);else for(i in t)t.hasOwnProperty(i)&&(r=t[i])&&("function"==typeof r?o.call(this,i,r):s.call(this,i,r));return this},i.removeEvent=function(e){var t,n=typeof e,i=this._getEvents();if("string"===n)delete i[e];else if("object"===n)for(t in i)i.hasOwnProperty(t)&&e.test(t)&&delete i[t];else delete this._events;return this},i.removeAllListeners=n("removeEvent"),i.emitEvent=function(e,t){var n,i,r,o,s=this.getListenersAsObject(e);for(r in s)if(s.hasOwnProperty(r))for(i=s[r].length;i--;)n=s[r][i],n.once===!0&&this.removeListener(e,n.listener),o=n.listener.apply(this,t||[]),o===this._getOnceReturnValue()&&this.removeListener(e,n.listener);return this},i.trigger=n("emitEvent"),i.emit=function(e){var t=Array.prototype.slice.call(arguments,1);return this.emitEvent(e,t)},i.setOnceReturnValue=function(e){return this._onceReturnValue=e,this},i._getOnceReturnValue=function(){return this.hasOwnProperty("_onceReturnValue")?this._onceReturnValue:!0},i._getEvents=function(){return this._events||(this._events={})},e.noConflict=function(){return r.EventEmitter=o,e},"function"==typeof define&&define.amd?define("eventEmitter/EventEmitter",[],function(){return e}):"object"==typeof module&&module.exports?module.exports=e:this.EventEmitter=e}).call(this),function(e){function t(t){var n=e.event;return n.target=n.target||n.srcElement||t,n}var n=document.documentElement,i=function(){};n.addEventListener?i=function(e,t,n){e.addEventListener(t,n,!1)}:n.attachEvent&&(i=function(e,n,i){e[n+i]=i.handleEvent?function(){var n=t(e);i.handleEvent.call(i,n)}:function(){var n=t(e);i.call(e,n)},e.attachEvent("on"+n,e[n+i])});var r=function(){};n.removeEventListener?r=function(e,t,n){e.removeEventListener(t,n,!1)}:n.detachEvent&&(r=function(e,t,n){e.detachEvent("on"+t,e[t+n]);try{delete e[t+n]}catch(i){e[t+n]=void 0}});var o={bind:i,unbind:r};"function"==typeof define&&define.amd?define("eventie/eventie",o):e.eventie=o}(this),function(e,t){"function"==typeof define&&define.amd?define(["eventEmitter/EventEmitter","eventie/eventie"],function(n,i){return t(e,n,i)}):"object"==typeof exports?module.exports=t(e,require("wolfy87-eventemitter"),require("eventie")):e.imagesLoaded=t(e,e.EventEmitter,e.eventie)}(window,function(e,t,n){function i(e,t){for(var n in t)e[n]=t[n];return e}function r(e){return"[object Array]"===d.call(e)}function o(e){var t=[];if(r(e))t=e;else if("number"==typeof e.length)for(var n=0,i=e.length;i>n;n++)t.push(e[n]);else t.push(e);return t}function s(e,t,n){if(!(this instanceof s))return new s(e,t);"string"==typeof e&&(e=document.querySelectorAll(e)),this.elements=o(e),this.options=i({},this.options),"function"==typeof t?n=t:i(this.options,t),n&&this.on("always",n),this.getImages(),a&&(this.jqDeferred=new a.Deferred);var r=this;setTimeout(function(){r.check()})}function f(e){this.img=e}function c(e){this.src=e,v[e]=this}var a=e.jQuery,u=e.console,h=u!==void 0,d=Object.prototype.toString;s.prototype=new t,s.prototype.options={},s.prototype.getImages=function(){this.images=[];for(var e=0,t=this.elements.length;t>e;e++){var n=this.elements[e];"IMG"===n.nodeName&&this.addImage(n);var i=n.nodeType;if(i&&(1===i||9===i||11===i))for(var r=n.querySelectorAll("img"),o=0,s=r.length;s>o;o++){var f=r[o];this.addImage(f)}}},s.prototype.addImage=function(e){var t=new f(e);this.images.push(t)},s.prototype.check=function(){function e(e,r){return t.options.debug&&h&&u.log("confirm",e,r),t.progress(e),n++,n===i&&t.complete(),!0}var t=this,n=0,i=this.images.length;if(this.hasAnyBroken=!1,!i)return this.complete(),void 0;for(var r=0;i>r;r++){var o=this.images[r];o.on("confirm",e),o.check()}},s.prototype.progress=function(e){this.hasAnyBroken=this.hasAnyBroken||!e.isLoaded;var t=this;setTimeout(function(){t.emit("progress",t,e),t.jqDeferred&&t.jqDeferred.notify&&t.jqDeferred.notify(t,e)})},s.prototype.complete=function(){var e=this.hasAnyBroken?"fail":"done";this.isComplete=!0;var t=this;setTimeout(function(){if(t.emit(e,t),t.emit("always",t),t.jqDeferred){var n=t.hasAnyBroken?"reject":"resolve";t.jqDeferred[n](t)}})},a&&(a.fn.imagesLoaded=function(e,t){var n=new s(this,e,t);return n.jqDeferred.promise(a(this))}),f.prototype=new t,f.prototype.check=function(){var e=v[this.img.src]||new c(this.img.src);if(e.isConfirmed)return this.confirm(e.isLoaded,"cached was confirmed"),void 0;if(this.img.complete&&void 0!==this.img.naturalWidth)return this.confirm(0!==this.img.naturalWidth,"naturalWidth"),void 0;var t=this;e.on("confirm",function(e,n){return t.confirm(e.isLoaded,n),!0}),e.check()},f.prototype.confirm=function(e,t){this.isLoaded=e,this.emit("confirm",this,t)};var v={};return c.prototype=new t,c.prototype.check=function(){if(!this.isChecked){var e=new Image;n.bind(e,"load",this),n.bind(e,"error",this),e.src=this.src,this.isChecked=!0}},c.prototype.handleEvent=function(e){var t="on"+e.type;this[t]&&this[t](e)},c.prototype.onload=function(e){this.confirm(!0,"onload"),this.unbindProxyEvents(e)},c.prototype.onerror=function(e){this.confirm(!1,"onerror"),this.unbindProxyEvents(e)},c.prototype.confirm=function(e,t){this.isConfirmed=!0,this.isLoaded=e,this.emit("confirm",this,t)},c.prototype.unbindProxyEvents=function(e){n.unbind(e.target,"load",this),n.unbind(e.target,"error",this)},s});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* jQuery Highlight plugin
|
|
3
|
+
*
|
|
4
|
+
* Based on highlight v3 by Johann Burkard
|
|
5
|
+
* http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
|
|
6
|
+
*
|
|
7
|
+
* Code a little bit refactored and cleaned (in my humble opinion).
|
|
8
|
+
* Most important changes:
|
|
9
|
+
* - has an option to highlight only entire words (wordsOnly - false by default),
|
|
10
|
+
* - has an option to be case sensitive (caseSensitive - false by default)
|
|
11
|
+
* - highlight element tag and class names can be specified in options
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* // wrap every occurrance of text 'lorem' in content
|
|
15
|
+
* // with <span class='highlight'> (default options)
|
|
16
|
+
* $('#content').highlight('lorem');
|
|
17
|
+
*
|
|
18
|
+
* // search for and highlight more terms at once
|
|
19
|
+
* // so you can save some time on traversing DOM
|
|
20
|
+
* $('#content').highlight(['lorem', 'ipsum']);
|
|
21
|
+
* $('#content').highlight('lorem ipsum');
|
|
22
|
+
*
|
|
23
|
+
* // search only for entire word 'lorem'
|
|
24
|
+
* $('#content').highlight('lorem', { wordsOnly: true });
|
|
25
|
+
*
|
|
26
|
+
* // don't ignore case during search of term 'lorem'
|
|
27
|
+
* $('#content').highlight('lorem', { caseSensitive: true });
|
|
28
|
+
*
|
|
29
|
+
* // wrap every occurrance of term 'ipsum' in content
|
|
30
|
+
* // with <em class='important'>
|
|
31
|
+
* $('#content').highlight('ipsum', { element: 'em', className: 'important' });
|
|
32
|
+
*
|
|
33
|
+
* // remove default highlight
|
|
34
|
+
* $('#content').unhighlight();
|
|
35
|
+
*
|
|
36
|
+
* // remove custom highlight
|
|
37
|
+
* $('#content').unhighlight({ element: 'em', className: 'important' });
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
* Copyright (c) 2009 Bartek Szopka
|
|
41
|
+
*
|
|
42
|
+
* Licensed under MIT license.
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
jQuery.extend({
|
|
47
|
+
highlight: function (node, re, nodeName, className) {
|
|
48
|
+
if (node.nodeType === 3) {
|
|
49
|
+
var match = node.data.match(re);
|
|
50
|
+
if (match) {
|
|
51
|
+
var highlight = document.createElement(nodeName || 'span');
|
|
52
|
+
highlight.className = className || 'highlight';
|
|
53
|
+
var wordNode = node.splitText(match.index);
|
|
54
|
+
wordNode.splitText(match[0].length);
|
|
55
|
+
var wordClone = wordNode.cloneNode(true);
|
|
56
|
+
highlight.appendChild(wordClone);
|
|
57
|
+
wordNode.parentNode.replaceChild(highlight, wordNode);
|
|
58
|
+
return 1; //skip added node in parent
|
|
59
|
+
}
|
|
60
|
+
} else if ((node.nodeType === 1 && node.childNodes) && // only element nodes that have children
|
|
61
|
+
!/(script|style)/i.test(node.tagName) && // ignore script and style nodes
|
|
62
|
+
!(node.tagName === nodeName.toUpperCase() && node.className === className)) { // skip if already highlighted
|
|
63
|
+
for (var i = 0; i < node.childNodes.length; i++) {
|
|
64
|
+
i += jQuery.highlight(node.childNodes[i], re, nodeName, className);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
jQuery.fn.unhighlight = function (options) {
|
|
72
|
+
var settings = { className: 'highlight', element: 'span' };
|
|
73
|
+
jQuery.extend(settings, options);
|
|
74
|
+
|
|
75
|
+
return this.find(settings.element + "." + settings.className).each(function () {
|
|
76
|
+
var parent = this.parentNode;
|
|
77
|
+
parent.replaceChild(this.firstChild, this);
|
|
78
|
+
parent.normalize();
|
|
79
|
+
}).end();
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
jQuery.fn.highlight = function (words, options) {
|
|
83
|
+
var settings = { className: 'highlight', element: 'span', caseSensitive: false, wordsOnly: false };
|
|
84
|
+
jQuery.extend(settings, options);
|
|
85
|
+
|
|
86
|
+
if (words.constructor === String) {
|
|
87
|
+
words = [words];
|
|
88
|
+
}
|
|
89
|
+
words = jQuery.grep(words, function(word, i){
|
|
90
|
+
return word != '';
|
|
91
|
+
});
|
|
92
|
+
words = jQuery.map(words, function(word, i) {
|
|
93
|
+
return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
94
|
+
});
|
|
95
|
+
if (words.length == 0) { return this; };
|
|
96
|
+
|
|
97
|
+
var flag = settings.caseSensitive ? "" : "i";
|
|
98
|
+
var pattern = "(" + words.join("|") + ")";
|
|
99
|
+
if (settings.wordsOnly) {
|
|
100
|
+
pattern = "\\b" + pattern + "\\b";
|
|
101
|
+
}
|
|
102
|
+
var re = new RegExp(pattern, flag);
|
|
103
|
+
|
|
104
|
+
return this.each(function () {
|
|
105
|
+
jQuery.highlight(this, re, settings.element, settings.className);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|