jquery-bootstrap-pagination 1.0.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.
@@ -0,0 +1,17 @@
1
+ src_files:
2
+ - "spec/javascripts/support/jquery.js"
3
+ - "spec/javascripts/support/jquery-jasmine.js"
4
+ - "spec/javascripts/helpers/spec_helper.coffee"
5
+ - "src/**/*.coffee"
6
+
7
+ helpers:
8
+ - "spec/javascripts/helpers/**/*.coffee"
9
+ - "spec/javascripts/helpers/**/*.js"
10
+
11
+ spec_files:
12
+ - /**/*_spec.coffee
13
+ - /**/*_spec.js
14
+
15
+ src_dir: "./"
16
+
17
+ spec_dir: spec/javascripts
@@ -0,0 +1,546 @@
1
+ var readFixtures = function() {
2
+ return jasmine.getFixtures().proxyCallTo_('read', arguments)
3
+ }
4
+
5
+ var preloadFixtures = function() {
6
+ jasmine.getFixtures().proxyCallTo_('preload', arguments)
7
+ }
8
+
9
+ var loadFixtures = function() {
10
+ jasmine.getFixtures().proxyCallTo_('load', arguments)
11
+ }
12
+
13
+ var appendLoadFixtures = function() {
14
+ jasmine.getFixtures().proxyCallTo_('appendLoad', arguments)
15
+ }
16
+
17
+ var setFixtures = function(html) {
18
+ jasmine.getFixtures().proxyCallTo_('set', arguments)
19
+ }
20
+
21
+ var appendSetFixtures = function() {
22
+ jasmine.getFixtures().proxyCallTo_('appendSet', arguments)
23
+ }
24
+
25
+ var sandbox = function(attributes) {
26
+ return jasmine.getFixtures().sandbox(attributes)
27
+ }
28
+
29
+ var spyOnEvent = function(selector, eventName) {
30
+ return jasmine.JQuery.events.spyOn(selector, eventName)
31
+ }
32
+
33
+ var preloadStyleFixtures = function() {
34
+ jasmine.getStyleFixtures().proxyCallTo_('preload', arguments)
35
+ }
36
+
37
+ var loadStyleFixtures = function() {
38
+ jasmine.getStyleFixtures().proxyCallTo_('load', arguments)
39
+ }
40
+
41
+ var appendLoadStyleFixtures = function() {
42
+ jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments)
43
+ }
44
+
45
+ var setStyleFixtures = function(html) {
46
+ jasmine.getStyleFixtures().proxyCallTo_('set', arguments)
47
+ }
48
+
49
+ var appendSetStyleFixtures = function(html) {
50
+ jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments)
51
+ }
52
+
53
+ var loadJSONFixtures = function() {
54
+ return jasmine.getJSONFixtures().proxyCallTo_('load', arguments)
55
+ }
56
+
57
+ var getJSONFixture = function(url) {
58
+ return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url]
59
+ }
60
+
61
+ jasmine.spiedEventsKey = function (selector, eventName) {
62
+ return [$(selector).selector, eventName].toString()
63
+ }
64
+
65
+ jasmine.getFixtures = function() {
66
+ return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures()
67
+ }
68
+
69
+ jasmine.getStyleFixtures = function() {
70
+ return jasmine.currentStyleFixtures_ = jasmine.currentStyleFixtures_ || new jasmine.StyleFixtures()
71
+ }
72
+
73
+ jasmine.Fixtures = function() {
74
+ this.containerId = 'jasmine-fixtures'
75
+ this.fixturesCache_ = {}
76
+ this.fixturesPath = 'spec/javascripts/fixtures'
77
+ }
78
+
79
+ jasmine.Fixtures.prototype.set = function(html) {
80
+ this.cleanUp()
81
+ this.createContainer_(html)
82
+ }
83
+
84
+ jasmine.Fixtures.prototype.appendSet= function(html) {
85
+ this.addToContainer_(html)
86
+ }
87
+
88
+ jasmine.Fixtures.prototype.preload = function() {
89
+ this.read.apply(this, arguments)
90
+ }
91
+
92
+ jasmine.Fixtures.prototype.load = function() {
93
+ this.cleanUp()
94
+ this.createContainer_(this.read.apply(this, arguments))
95
+ }
96
+
97
+ jasmine.Fixtures.prototype.appendLoad = function() {
98
+ this.addToContainer_(this.read.apply(this, arguments))
99
+ }
100
+
101
+ jasmine.Fixtures.prototype.read = function() {
102
+ var htmlChunks = []
103
+
104
+ var fixtureUrls = arguments
105
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
106
+ htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]))
107
+ }
108
+
109
+ return htmlChunks.join('')
110
+ }
111
+
112
+ jasmine.Fixtures.prototype.clearCache = function() {
113
+ this.fixturesCache_ = {}
114
+ }
115
+
116
+ jasmine.Fixtures.prototype.cleanUp = function() {
117
+ $('#' + this.containerId).remove()
118
+ }
119
+
120
+ jasmine.Fixtures.prototype.sandbox = function(attributes) {
121
+ var attributesToSet = attributes || {}
122
+ return $('<div id="sandbox" />').attr(attributesToSet)
123
+ }
124
+
125
+ jasmine.Fixtures.prototype.createContainer_ = function(html) {
126
+ var container
127
+ if(html instanceof $) {
128
+ container = $('<div id="' + this.containerId + '" />')
129
+ container.html(html)
130
+ } else {
131
+ container = '<div id="' + this.containerId + '">' + html + '</div>'
132
+ }
133
+ $('body').append(container)
134
+ }
135
+
136
+ jasmine.Fixtures.prototype.addToContainer_ = function(html){
137
+ var container = $('body').find('#'+this.containerId).append(html)
138
+ if(!container.length){
139
+ this.createContainer_(html)
140
+ }
141
+ }
142
+
143
+ jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
144
+ if (typeof this.fixturesCache_[url] === 'undefined') {
145
+ this.loadFixtureIntoCache_(url)
146
+ }
147
+ return this.fixturesCache_[url]
148
+ }
149
+
150
+ jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
151
+ var url = this.makeFixtureUrl_(relativeUrl)
152
+ var request = $.ajax({
153
+ type: "GET",
154
+ url: url + "?" + new Date().getTime(),
155
+ async: false
156
+ })
157
+ this.fixturesCache_[relativeUrl] = request.responseText
158
+ }
159
+
160
+ jasmine.Fixtures.prototype.makeFixtureUrl_ = function(relativeUrl){
161
+ return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
162
+ }
163
+
164
+ jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
165
+ return this[methodName].apply(this, passedArguments)
166
+ }
167
+
168
+
169
+ jasmine.StyleFixtures = function() {
170
+ this.fixturesCache_ = {}
171
+ this.fixturesNodes_ = []
172
+ this.fixturesPath = 'spec/javascripts/fixtures'
173
+ }
174
+
175
+ jasmine.StyleFixtures.prototype.set = function(css) {
176
+ this.cleanUp()
177
+ this.createStyle_(css)
178
+ }
179
+
180
+ jasmine.StyleFixtures.prototype.appendSet = function(css) {
181
+ this.createStyle_(css)
182
+ }
183
+
184
+ jasmine.StyleFixtures.prototype.preload = function() {
185
+ this.read_.apply(this, arguments)
186
+ }
187
+
188
+ jasmine.StyleFixtures.prototype.load = function() {
189
+ this.cleanUp()
190
+ this.createStyle_(this.read_.apply(this, arguments))
191
+ }
192
+
193
+ jasmine.StyleFixtures.prototype.appendLoad = function() {
194
+ this.createStyle_(this.read_.apply(this, arguments))
195
+ }
196
+
197
+ jasmine.StyleFixtures.prototype.cleanUp = function() {
198
+ while(this.fixturesNodes_.length) {
199
+ this.fixturesNodes_.pop().remove()
200
+ }
201
+ }
202
+
203
+ jasmine.StyleFixtures.prototype.createStyle_ = function(html) {
204
+ var styleText = $('<div></div>').html(html).text(),
205
+ style = $('<style>' + styleText + '</style>')
206
+
207
+ this.fixturesNodes_.push(style)
208
+
209
+ $('head').append(style)
210
+ }
211
+
212
+ jasmine.StyleFixtures.prototype.clearCache = jasmine.Fixtures.prototype.clearCache
213
+
214
+ jasmine.StyleFixtures.prototype.read_ = jasmine.Fixtures.prototype.read
215
+
216
+ jasmine.StyleFixtures.prototype.getFixtureHtml_ = jasmine.Fixtures.prototype.getFixtureHtml_
217
+
218
+ jasmine.StyleFixtures.prototype.loadFixtureIntoCache_ = jasmine.Fixtures.prototype.loadFixtureIntoCache_
219
+
220
+ jasmine.StyleFixtures.prototype.makeFixtureUrl_ = jasmine.Fixtures.prototype.makeFixtureUrl_
221
+
222
+ jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyCallTo_
223
+
224
+ jasmine.getJSONFixtures = function() {
225
+ return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures()
226
+ }
227
+
228
+ jasmine.JSONFixtures = function() {
229
+ this.fixturesCache_ = {}
230
+ this.fixturesPath = 'spec/javascripts/fixtures/json'
231
+ }
232
+
233
+ jasmine.JSONFixtures.prototype.load = function() {
234
+ this.read.apply(this, arguments)
235
+ return this.fixturesCache_
236
+ }
237
+
238
+ jasmine.JSONFixtures.prototype.read = function() {
239
+ var fixtureUrls = arguments
240
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
241
+ this.getFixtureData_(fixtureUrls[urlIndex])
242
+ }
243
+ return this.fixturesCache_
244
+ }
245
+
246
+ jasmine.JSONFixtures.prototype.clearCache = function() {
247
+ this.fixturesCache_ = {}
248
+ }
249
+
250
+ jasmine.JSONFixtures.prototype.getFixtureData_ = function(url) {
251
+ this.loadFixtureIntoCache_(url)
252
+ return this.fixturesCache_[url]
253
+ }
254
+
255
+ jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
256
+ var self = this
257
+ var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
258
+ $.ajax({
259
+ async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
260
+ cache: false,
261
+ dataType: 'json',
262
+ url: url,
263
+ success: function(data) {
264
+ self.fixturesCache_[relativeUrl] = data
265
+ },
266
+ error: function(jqXHR, status, errorThrown) {
267
+ throw Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
268
+ }
269
+ })
270
+ }
271
+
272
+ jasmine.JSONFixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
273
+ return this[methodName].apply(this, passedArguments)
274
+ }
275
+
276
+ jasmine.JQuery = function() {}
277
+
278
+ jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
279
+ return $('<div/>').append(html).html()
280
+ }
281
+
282
+ jasmine.JQuery.elementToString = function(element) {
283
+ var domEl = $(element).get(0)
284
+ if (domEl == undefined || domEl.cloneNode)
285
+ return $('<div />').append($(element).clone()).html()
286
+ else
287
+ return element.toString()
288
+ }
289
+
290
+ jasmine.JQuery.matchersClass = {}
291
+
292
+ !function(namespace) {
293
+ var data = {
294
+ spiedEvents: {},
295
+ handlers: []
296
+ }
297
+
298
+ namespace.events = {
299
+ spyOn: function(selector, eventName) {
300
+ var handler = function(e) {
301
+ data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = e
302
+ }
303
+ $(selector).bind(eventName, handler)
304
+ data.handlers.push(handler)
305
+ return {
306
+ selector: selector,
307
+ eventName: eventName,
308
+ handler: handler,
309
+ reset: function(){
310
+ delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
311
+ }
312
+ }
313
+ },
314
+
315
+ wasTriggered: function(selector, eventName) {
316
+ return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)])
317
+ },
318
+
319
+ wasPrevented: function(selector, eventName) {
320
+ return data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].isDefaultPrevented()
321
+ },
322
+
323
+ cleanUp: function() {
324
+ data.spiedEvents = {}
325
+ data.handlers = []
326
+ }
327
+ }
328
+ }(jasmine.JQuery)
329
+
330
+ !function(){
331
+ var jQueryMatchers = {
332
+ toHaveClass: function(className) {
333
+ return this.actual.hasClass(className)
334
+ },
335
+
336
+ toHaveCss: function(css){
337
+ for (var prop in css){
338
+ if (this.actual.css(prop) !== css[prop]) return false
339
+ }
340
+ return true
341
+ },
342
+
343
+ toBeVisible: function() {
344
+ return this.actual.is(':visible')
345
+ },
346
+
347
+ toBeHidden: function() {
348
+ return this.actual.is(':hidden')
349
+ },
350
+
351
+ toBeSelected: function() {
352
+ return this.actual.is(':selected')
353
+ },
354
+
355
+ toBeChecked: function() {
356
+ return this.actual.is(':checked')
357
+ },
358
+
359
+ toBeEmpty: function() {
360
+ return this.actual.is(':empty')
361
+ },
362
+
363
+ toExist: function() {
364
+ return $(document).find(this.actual).length
365
+ },
366
+
367
+ toHaveAttr: function(attributeName, expectedAttributeValue) {
368
+ return hasProperty(this.actual.attr(attributeName), expectedAttributeValue)
369
+ },
370
+
371
+ toHaveProp: function(propertyName, expectedPropertyValue) {
372
+ return hasProperty(this.actual.prop(propertyName), expectedPropertyValue)
373
+ },
374
+
375
+ toHaveId: function(id) {
376
+ return this.actual.attr('id') == id
377
+ },
378
+
379
+ toHaveHtml: function(html) {
380
+ return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html)
381
+ },
382
+
383
+ toContainHtml: function(html){
384
+ var actualHtml = this.actual.html()
385
+ var expectedHtml = jasmine.JQuery.browserTagCaseIndependentHtml(html)
386
+ return (actualHtml.indexOf(expectedHtml) >= 0)
387
+ },
388
+
389
+ toHaveText: function(text) {
390
+ var trimmedText = $.trim(this.actual.text())
391
+ if (text && $.isFunction(text.test)) {
392
+ return text.test(trimmedText)
393
+ } else {
394
+ return trimmedText == text
395
+ }
396
+ },
397
+
398
+ toHaveValue: function(value) {
399
+ return this.actual.val() == value
400
+ },
401
+
402
+ toHaveData: function(key, expectedValue) {
403
+ return hasProperty(this.actual.data(key), expectedValue)
404
+ },
405
+
406
+ toBe: function(selector) {
407
+ return this.actual.is(selector)
408
+ },
409
+
410
+ toContain: function(selector) {
411
+ return this.actual.find(selector).length
412
+ },
413
+
414
+ toBeDisabled: function(selector){
415
+ return this.actual.is(':disabled')
416
+ },
417
+
418
+ toBeFocused: function(selector) {
419
+ return this.actual.is(':focus')
420
+ },
421
+
422
+ toHandle: function(event) {
423
+
424
+ var events = $._data(this.actual.get(0), "events")
425
+
426
+ if(!events || !event || typeof event !== "string") {
427
+ return false
428
+ }
429
+
430
+ var namespaces = event.split(".")
431
+ var eventType = namespaces.shift()
432
+ var sortedNamespaces = namespaces.slice(0).sort()
433
+ var namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
434
+
435
+ if(events[eventType] && namespaces.length) {
436
+ for(var i = 0; i < events[eventType].length; i++) {
437
+ var namespace = events[eventType][i].namespace
438
+ if(namespaceRegExp.test(namespace)) {
439
+ return true
440
+ }
441
+ }
442
+ } else {
443
+ return events[eventType] && events[eventType].length > 0
444
+ }
445
+ },
446
+
447
+ // tests the existence of a specific event binding + handler
448
+ toHandleWith: function(eventName, eventHandler) {
449
+ var stack = $._data(this.actual.get(0), "events")[eventName]
450
+ for (var i = 0; i < stack.length; i++) {
451
+ if (stack[i].handler == eventHandler) return true
452
+ }
453
+ return false
454
+ }
455
+ }
456
+
457
+ var hasProperty = function(actualValue, expectedValue) {
458
+ if (expectedValue === undefined) return actualValue !== undefined
459
+ return actualValue == expectedValue
460
+ }
461
+
462
+ var bindMatcher = function(methodName) {
463
+ var builtInMatcher = jasmine.Matchers.prototype[methodName]
464
+
465
+ jasmine.JQuery.matchersClass[methodName] = function() {
466
+ if (this.actual
467
+ && (this.actual instanceof $
468
+ || jasmine.isDomNode(this.actual))) {
469
+ this.actual = $(this.actual)
470
+ var result = jQueryMatchers[methodName].apply(this, arguments)
471
+ var element
472
+ if (this.actual.get && (element = this.actual.get()[0]) && !$.isWindow(element) && element.tagName !== "HTML")
473
+ this.actual = jasmine.JQuery.elementToString(this.actual)
474
+ return result
475
+ }
476
+
477
+ if (builtInMatcher) {
478
+ return builtInMatcher.apply(this, arguments)
479
+ }
480
+
481
+ return false
482
+ }
483
+ }
484
+
485
+ for(var methodName in jQueryMatchers) {
486
+ bindMatcher(methodName)
487
+ }
488
+ }()
489
+
490
+ beforeEach(function() {
491
+ this.addMatchers(jasmine.JQuery.matchersClass)
492
+ this.addMatchers({
493
+ toHaveBeenTriggeredOn: function(selector) {
494
+ this.message = function() {
495
+ return [
496
+ "Expected event " + this.actual + " to have been triggered on " + selector,
497
+ "Expected event " + this.actual + " not to have been triggered on " + selector
498
+ ]
499
+ }
500
+ return jasmine.JQuery.events.wasTriggered(selector, this.actual)
501
+ }
502
+ })
503
+ this.addMatchers({
504
+ toHaveBeenTriggered: function(){
505
+ var eventName = this.actual.eventName,
506
+ selector = this.actual.selector
507
+ this.message = function() {
508
+ return [
509
+ "Expected event " + eventName + " to have been triggered on " + selector,
510
+ "Expected event " + eventName + " not to have been triggered on " + selector
511
+ ]
512
+ }
513
+ return jasmine.JQuery.events.wasTriggered(selector, eventName)
514
+ }
515
+ })
516
+ this.addMatchers({
517
+ toHaveBeenPreventedOn: function(selector) {
518
+ this.message = function() {
519
+ return [
520
+ "Expected event " + this.actual + " to have been prevented on " + selector,
521
+ "Expected event " + this.actual + " not to have been prevented on " + selector
522
+ ]
523
+ }
524
+ return jasmine.JQuery.events.wasPrevented(selector, this.actual)
525
+ }
526
+ })
527
+ this.addMatchers({
528
+ toHaveBeenPrevented: function() {
529
+ var eventName = this.actual.eventName,
530
+ selector = this.actual.selector
531
+ this.message = function() {
532
+ return [
533
+ "Expected event " + eventName + " to have been prevented on " + selector,
534
+ "Expected event " + eventName + " not to have been prevented on " + selector
535
+ ]
536
+ }
537
+ return jasmine.JQuery.events.wasPrevented(selector, eventName)
538
+ }
539
+ })
540
+ })
541
+
542
+ afterEach(function() {
543
+ jasmine.getFixtures().cleanUp()
544
+ jasmine.getStyleFixtures().cleanUp()
545
+ jasmine.JQuery.events.cleanUp()
546
+ })