tourguide 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45a517b7b127f03a7cdfc3f1c2fa8728d83d44b2
4
+ data.tar.gz: 6c851ebd84ffc0ba380204ed4d38af82712588e2
5
+ SHA512:
6
+ metadata.gz: 26253c4bc396fc8c31bae0a83fba19be146a3ada47448e9ecd5ad7dc0e9e9bca9b6c85290dee5b6d603263930b500547260256293cba604b34e3dda23dad62c1
7
+ data.tar.gz: d84396ae8b6bac73c297747f8263a48c4e7fe5ae8a08c0ecb8a30b7a2919322289707da33c05b3be96aab877da06b01f4fd536283ae755f09d5b17bea484190f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tourguide.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Adam Carlile
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Tourguide
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tourguide`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tourguide'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tourguide
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/tourguide/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1 @@
1
+ //= require tourguide/tourbus
@@ -0,0 +1 @@
1
+ @import 'tourguide/tourbus'
@@ -0,0 +1,11 @@
1
+ module Tourguide
2
+ module TourguideHelper
3
+
4
+ def tourbus id, options={}, &block
5
+ renderer = Tourguide::Renderers::Tourbus.new(self, id, options)
6
+ yield(renderer)
7
+ renderer.render
8
+ end
9
+
10
+ end
11
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tourguide"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ module Tourguide
2
+ class Engine < ::Rails::Engine
3
+
4
+ config.to_prepare do
5
+ ApplicationController.helper Tourguide::TourguideHelper
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,55 @@
1
+ module Tourguide
2
+ module Renderers
3
+ class Connections
4
+
5
+ attr_reader :options
6
+
7
+ def initialize(context, options={})
8
+ @context = context
9
+ @options = options.reverse_merge default_options
10
+ @connections = []
11
+ end
12
+
13
+ def render
14
+ xhtml = Builder::XmlMarkup.new target: out=(''), indent: 2
15
+ xhtml.nav nav_options do |nav|
16
+ nav << connections.map{ |x| x.render }.join("\n")
17
+ end
18
+ out.html_safe
19
+ end
20
+
21
+ def add(label, type)
22
+ @connections << Tourguide::Renderers::Link.new(@context, label, type)
23
+ end
24
+
25
+ def connections
26
+ @connections.any? ? @connections : default_connections
27
+ end
28
+
29
+ private
30
+
31
+ def nav_options
32
+ options.merge({class: css_classes})
33
+ end
34
+
35
+ def css_classes
36
+ out = []
37
+ out << ("connections-#{connections.count}")
38
+ out << options[:class]
39
+ out.compact.join(' ')
40
+ end
41
+
42
+ def default_options
43
+ {}
44
+ end
45
+
46
+ def default_connections
47
+ @default_connections ||= [
48
+ Tourguide::Renderers::Link.new(@context, 'Previous', :prev),
49
+ Tourguide::Renderers::Link.new(@context, 'Continue', :next)
50
+ ]
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,40 @@
1
+ module Tourguide
2
+ module Renderers
3
+ class Link
4
+
5
+ attr_reader :options, :label, :type
6
+
7
+ def initialize(context, label, type, options={})
8
+ @context = context
9
+ @label = label
10
+ @type = type
11
+ @options = options.reverse_merge default_options
12
+ end
13
+
14
+ def render
15
+ @context.link_to label.html_safe, options[:href], html_options
16
+ end
17
+
18
+ private
19
+
20
+ def default_options
21
+ {
22
+ href: 'javascript:void(0);',
23
+ class: nil
24
+ }
25
+ end
26
+
27
+ def html_options
28
+ options.except(:label, :href).merge({class: css_class})
29
+ end
30
+
31
+ def css_class
32
+ out = [options[:class]]
33
+ out << 'tour-link'
34
+ out << "tourbus-#{type}"
35
+ out.compact.join(' ')
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,68 @@
1
+ module Tourguide
2
+ module Renderers
3
+ class Stop
4
+
5
+ attr_reader :options
6
+
7
+ def initialize(context, options={})
8
+ @context = context
9
+ @options = options.reverse_merge(default_options[:tour]).reverse_merge(default_options.except(:tour))
10
+ end
11
+
12
+ def content &block
13
+ raise ArgumentError unless block_given?
14
+ @content = @context.capture(&block)
15
+ end
16
+
17
+ def connections(options={}, &block)
18
+ @connections ||= begin
19
+ renderer = Tourguide::Renderers::Connections.new(@context, options)
20
+ yield(renderer) if block_given?
21
+ renderer
22
+ end
23
+ end
24
+
25
+ def close
26
+ @close ||= Tourguide::Renderers::Link.new(@context, options[:close][:label], :stop, options[:close])
27
+ end
28
+
29
+ def render
30
+ @context.content_tag(:li, [close.render, @content, connections.render].join("\n").html_safe, li_options).html_safe
31
+ end
32
+
33
+ private
34
+
35
+ def li_options
36
+ {
37
+ data: data_options
38
+ }.merge(options[:wrapper])
39
+ end
40
+
41
+ def data_options
42
+ options.except(:wrapper, :close).reject { |k, v| v.blank? }
43
+ end
44
+
45
+ def default_options
46
+ {
47
+ wrapper: {},
48
+ tour: {
49
+ el: nil,
50
+ class: nil,
51
+ orientation: 'centered',
52
+ algin: 'left',
53
+ width: nil,
54
+ margin: nil,
55
+ top: nil,
56
+ left: nil,
57
+ arrow: nil,
58
+ zindex: nil,
59
+ },
60
+ close: {
61
+ label: "&times;"
62
+ }
63
+ }
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,50 @@
1
+ module Tourguide
2
+ module Renderers
3
+ class Tourbus
4
+
5
+ attr_reader :id, :options, :stops
6
+
7
+ def initialize(context, id, options={})
8
+ @context = context
9
+ @id = id
10
+ @options = options.reverse_merge(default_options)
11
+ @stops = []
12
+ end
13
+
14
+ def stop(options={}, &block)
15
+ renderer = Tourguide::Renderers::Stop.new(@context, options)
16
+ yield(renderer) if block_given?
17
+ stops << renderer
18
+ end
19
+
20
+ def render
21
+ xhtml = Builder::XmlMarkup.new target: out=(''), indent: 2
22
+ xhtml.ul(ul_options) do |ul|
23
+ ul << stops.map { |x| x.render }.join("\n")
24
+ end
25
+ out.html_safe
26
+ end
27
+
28
+ private
29
+
30
+ def ul_options
31
+ {
32
+ id: id,
33
+ class: css_classes
34
+ }.merge(options.except(:class))
35
+ end
36
+
37
+ def css_classes
38
+ out = []
39
+ out << 'tourbus-legs'
40
+ out << options[:class]
41
+ out.compact.join(' ')
42
+ end
43
+
44
+ def default_options
45
+ {}
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module Tourguide
2
+ VERSION = "0.1.0"
3
+ end
data/lib/tourguide.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'sass-rails'
2
+ require 'coffee-rails'
3
+ require 'builder'
4
+
5
+ require "tourguide/version"
6
+ require "tourguide/engine" if defined? Rails
7
+
8
+ require "tourguide/renderers/tourbus"
9
+ require "tourguide/renderers/link"
10
+ require "tourguide/renderers/connections"
11
+ require "tourguide/renderers/stop"
12
+
13
+ module Tourguide
14
+
15
+ end
data/tourguide.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tourguide/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tourguide"
8
+ spec.version = Tourguide::VERSION
9
+ spec.authors = ["Adam Carlile"]
10
+ spec.email = ["adam@benchmedia.co.uk"]
11
+
12
+ spec.summary = "Tourbus"
13
+ spec.description = "Tourbus"
14
+ spec.homepage = "http://www.github.com/boardiq/tourbus"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "sass-rails", ">= 4"
23
+ spec.add_runtime_dependency "coffee-rails", ">= 4"
24
+ spec.add_runtime_dependency "builder"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.8"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
@@ -0,0 +1,593 @@
1
+ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+ //@ sourceMappingURL=jquery-tourbus.map
3
+ (function() {
4
+ var $, Bus, Leg, methods, tourbus,
5
+ __slice = [].slice;
6
+
7
+ $ = jQuery;
8
+
9
+ Bus = require('./modules/bus');
10
+
11
+ Leg = require('./modules/leg');
12
+
13
+ tourbus = $.tourbus = function() {
14
+ var args, method;
15
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
16
+ method = args[0];
17
+ if (methods.hasOwnProperty(method)) {
18
+ args = args.slice(1);
19
+ } else if (method instanceof $) {
20
+ method = 'build';
21
+ } else if (typeof method === 'string') {
22
+ method = 'build';
23
+ args[0] = $(args[0]);
24
+ } else {
25
+ $.error("Unknown method of $.tourbus --", args);
26
+ }
27
+ return methods[method].apply(this, args);
28
+ };
29
+
30
+ $.fn.tourbus = function() {
31
+ var args;
32
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
33
+ return this.each(function() {
34
+ args.unshift($(this));
35
+ tourbus.apply(null, ['build'].concat(__slice.call(args)));
36
+ return this;
37
+ });
38
+ };
39
+
40
+ methods = {
41
+ build: function(el, options) {
42
+ var built;
43
+ if (options == null) {
44
+ options = {};
45
+ }
46
+ options = $.extend(true, {}, tourbus.defaults, options);
47
+ built = [];
48
+ if (!(el instanceof $)) {
49
+ el = $(el);
50
+ }
51
+ el.each(function() {
52
+ return built.push(new Bus(this, options));
53
+ });
54
+ if (built.length === 0) {
55
+ $.error("" + el.selector + " was not found!");
56
+ }
57
+ if (built.length === 1) {
58
+ return built[0];
59
+ }
60
+ return built;
61
+ },
62
+ destroyAll: function() {
63
+ var bus, index, _ref, _results;
64
+ _ref = Bus._busses;
65
+ _results = [];
66
+ for (index in _ref) {
67
+ bus = _ref[index];
68
+ _results.push(bus.destroy());
69
+ }
70
+ return _results;
71
+ },
72
+ expose: function(global) {
73
+ return global.tourbus = {
74
+ Bus: Bus,
75
+ Leg: Leg
76
+ };
77
+ }
78
+ };
79
+
80
+ tourbus.defaults = {
81
+ debug: false,
82
+ autoDepart: false,
83
+ container: 'body',
84
+ "class": null,
85
+ startAt: 0,
86
+ onDepart: function() {
87
+ return null;
88
+ },
89
+ onStop: function() {
90
+ return null;
91
+ },
92
+ onLegStart: function() {
93
+ return null;
94
+ },
95
+ onLegEnd: function() {
96
+ return null;
97
+ },
98
+ leg: {
99
+ "class": null,
100
+ scrollTo: null,
101
+ scrollSpeed: 150,
102
+ scrollContext: 100,
103
+ orientation: 'bottom',
104
+ align: 'left',
105
+ width: 'auto',
106
+ margin: 10,
107
+ top: null,
108
+ left: null,
109
+ zindex: 9999,
110
+ arrow: "50%"
111
+ }
112
+ };
113
+
114
+ }).call(this);
115
+
116
+ },{"./modules/bus":2,"./modules/leg":3}],2:[function(require,module,exports){
117
+ //@ sourceMappingURL=bus.map
118
+ (function() {
119
+ var $, Bus, Leg, utils,
120
+ __slice = [].slice;
121
+
122
+ $ = jQuery;
123
+
124
+ Leg = require('./leg');
125
+
126
+ utils = require('./utils');
127
+
128
+ module.exports = Bus = (function() {
129
+ Bus._busses = {};
130
+
131
+ Bus._tours = 0;
132
+
133
+ Bus.uniqueId = function() {
134
+ return this._tours++;
135
+ };
136
+
137
+ function Bus(el, options) {
138
+ this.options = options;
139
+ this.id = this.constructor.uniqueId();
140
+ this.elId = "tourbus-" + this.id;
141
+ this.constructor._busses[this.id] = this;
142
+ this.$original = $(el);
143
+ this.rawData = this.$original.data();
144
+ this.$container = $(utils.dataProp(this.rawData.container, this.options.container));
145
+ this.$original.data({
146
+ tourbus: this
147
+ });
148
+ this.currentLegIndex = null;
149
+ this.legs = [];
150
+ this.legEls = this.$original.children('li');
151
+ this.totalLegs = this.legEls.length;
152
+ this._configureElement();
153
+ this._setupEvents();
154
+ if (utils.dataProp(this.rawData.autoDepart, this.options.autoDepart)) {
155
+ this.$original.trigger('depart.tourbus');
156
+ }
157
+ this._log('built tourbus with el', el.toString(), 'and options', this.options);
158
+ }
159
+
160
+ Bus.prototype.depart = function() {
161
+ this.running = true;
162
+ this.options.onDepart(this);
163
+ this._log('departing', this);
164
+ this.currentLegIndex = utils.dataProp(this.rawData.startAt, this.options.startAt);
165
+ return this.showLeg();
166
+ };
167
+
168
+ Bus.prototype.stop = function() {
169
+ if (!this.running) {
170
+ return;
171
+ }
172
+ $.each(this.legs, $.proxy(this.hideLeg, this));
173
+ this.currentLegIndex = null;
174
+ this.options.onStop(this);
175
+ return this.running = false;
176
+ };
177
+
178
+ Bus.prototype.on = function(event, selector, fn) {
179
+ return this.$container.on(event, selector, fn);
180
+ };
181
+
182
+ Bus.prototype.currentLeg = function() {
183
+ if (this.currentLegIndex === null) {
184
+ return null;
185
+ }
186
+ return this.legs[this.currentLegIndex];
187
+ };
188
+
189
+ Bus.prototype.buildLeg = function(i) {
190
+ var $legEl, data, leg;
191
+ $legEl = $(this.legEls[i]);
192
+ data = $legEl.data();
193
+ this.legs[i] = leg = new Leg({
194
+ bus: this,
195
+ original: $legEl,
196
+ target: data.el || 'body',
197
+ index: i,
198
+ rawData: data
199
+ });
200
+ leg.render();
201
+ this.$el.append(leg.$el);
202
+ leg._position();
203
+ leg.hide();
204
+ return leg;
205
+ };
206
+
207
+ Bus.prototype.showLeg = function(index) {
208
+ var leg, preventDefault;
209
+ if (index == null) {
210
+ index = this.currentLegIndex;
211
+ }
212
+ leg = this.legs[index] || this.buildLeg(index);
213
+ this._log('showLeg:', leg);
214
+ preventDefault = this.options.onLegStart(leg, this);
215
+ if (preventDefault !== false) {
216
+ leg.show();
217
+ }
218
+ if (++index < this.totalLegs && !this.legs[index]) {
219
+ return this.buildLeg(index);
220
+ }
221
+ };
222
+
223
+ Bus.prototype.hideLeg = function(index) {
224
+ var leg, preventDefault;
225
+ if (index == null) {
226
+ index = this.currentLegIndex;
227
+ }
228
+ leg = this.legs[index];
229
+ if (leg && leg.visible) {
230
+ this._log('hideLeg:', leg);
231
+ preventDefault = this.options.onLegEnd(leg, this);
232
+ if (preventDefault !== false) {
233
+ leg.hide();
234
+ }
235
+ }
236
+ if (--index > 0 && !this.legs[index]) {
237
+ return this.buildLeg(index);
238
+ }
239
+ };
240
+
241
+ Bus.prototype.repositionLegs = function() {
242
+ return $.each(this.legs, function() {
243
+ return this.reposition();
244
+ });
245
+ };
246
+
247
+ Bus.prototype.next = function() {
248
+ this.hideLeg();
249
+ this.currentLegIndex++;
250
+ if (this.currentLegIndex > this.totalLegs - 1) {
251
+ return this.$original.trigger('stop.tourbus');
252
+ } else {
253
+ return this.showLeg();
254
+ }
255
+ };
256
+
257
+ Bus.prototype.prev = function(cb) {
258
+ this.hideLeg();
259
+ this.currentLegIndex--;
260
+ if (this.currentLegIndex < 0) {
261
+ return this.$original.trigger('stop.tourbus');
262
+ } else {
263
+ return this.showLeg();
264
+ }
265
+ };
266
+
267
+ Bus.prototype.destroy = function() {
268
+ $.each(this.legs, function() {
269
+ return this.destroy();
270
+ });
271
+ this.legs = [];
272
+ delete this.constructor._busses[this.id];
273
+ this._teardownEvents();
274
+ this.$original.removeData('tourbus');
275
+ return this.$el.remove();
276
+ };
277
+
278
+ Bus.prototype._configureElement = function() {
279
+ this.$el = $("<div class='tourbus-container'></div>");
280
+ this.el = this.$el[0];
281
+ this.$el.attr({
282
+ id: this.elId
283
+ });
284
+ this.$el.addClass(utils.dataProp(this.rawData["class"], this.options["class"]));
285
+ return this.$container.append(this.$el);
286
+ };
287
+
288
+ Bus.prototype._log = function() {
289
+ if (!utils.dataProp(this.rawData.debug, this.options.debug)) {
290
+ return;
291
+ }
292
+ return console.log.apply(console, ["TOURBUS " + this.id + ":"].concat(__slice.call(arguments)));
293
+ };
294
+
295
+ Bus.prototype._setupEvents = function() {
296
+ this.$original.on('depart.tourbus', $.proxy(this.depart, this));
297
+ this.$original.on('stop.tourbus', $.proxy(this.stop, this));
298
+ this.$original.on('next.tourbus', $.proxy(this.next, this));
299
+ return this.$original.on('prev.tourbus', $.proxy(this.prev, this));
300
+ };
301
+
302
+ Bus.prototype._teardownEvents = function() {
303
+ return this.$original.off('.tourbus');
304
+ };
305
+
306
+ return Bus;
307
+
308
+ })();
309
+
310
+ }).call(this);
311
+
312
+ },{"./leg":3,"./utils":4}],3:[function(require,module,exports){
313
+ //@ sourceMappingURL=leg.map
314
+ (function() {
315
+ var $, Leg, utils, _addRule;
316
+
317
+ $ = jQuery;
318
+
319
+ utils = require('./utils');
320
+
321
+ module.exports = Leg = (function() {
322
+ function Leg(options) {
323
+ this.options = options;
324
+ this.$original = this.options.original;
325
+ this.bus = this.options.bus;
326
+ this.rawData = this.options.rawData;
327
+ this.index = this.options.index;
328
+ this.$target = $(this.options.target);
329
+ this.id = "" + this.bus.id + "-" + this.options.index;
330
+ this.elId = "tourbus-leg-" + this.id;
331
+ this.visible = false;
332
+ if (this.$target.length === 0) {
333
+ throw "" + this.$target.selector + " is not an element!";
334
+ }
335
+ this.content = this.$original.html();
336
+ this._setupOptions();
337
+ this._configureElement();
338
+ this._configureTarget();
339
+ this._configureScroll();
340
+ this._setupEvents();
341
+ this.bus._log("leg " + this.index + " made with options", this.options);
342
+ }
343
+
344
+ Leg.prototype.render = function() {
345
+ var arrowClass, html;
346
+ arrowClass = this.options.orientation === 'centered' ? '' : 'tourbus-arrow';
347
+ this.$el.addClass(" " + arrowClass + " tourbus-arrow-" + this.options.orientation + " ");
348
+ html = "<div class='tourbus-leg-inner'>\n " + this.content + "\n</div>";
349
+ this.$el.css({
350
+ width: this.options.width,
351
+ zIndex: this.options.zindex
352
+ }).html(html);
353
+ return this;
354
+ };
355
+
356
+ Leg.prototype.destroy = function() {
357
+ this.$el.remove();
358
+ return this._teardownEvents();
359
+ };
360
+
361
+ Leg.prototype.reposition = function() {
362
+ this._configureTarget();
363
+ return this._position();
364
+ };
365
+
366
+ Leg.prototype._position = function() {
367
+ var css, keys, rule, selector;
368
+ if (this.options.orientation !== 'centered') {
369
+ rule = {};
370
+ keys = {
371
+ top: 'left',
372
+ bottom: 'left',
373
+ left: 'top',
374
+ right: 'top'
375
+ };
376
+ if (typeof this.options.arrow === 'number') {
377
+ this.options.arrow += 'px';
378
+ }
379
+ rule[keys[this.options.orientation]] = this.options.arrow;
380
+ selector = "#" + this.elId + ".tourbus-arrow";
381
+ this.bus._log("adding rule for " + this.elId, rule);
382
+ _addRule("" + selector + ":before, " + selector + ":after", rule);
383
+ }
384
+ css = this._offsets();
385
+ this.bus._log('setting offsets on leg', css);
386
+ return this.$el.css(css);
387
+ };
388
+
389
+ Leg.prototype.show = function() {
390
+ this.visible = true;
391
+ this.$el.css({
392
+ visibility: 'visible',
393
+ opacity: 1.0,
394
+ zIndex: this.options.zindex
395
+ });
396
+ return this.scrollIntoView();
397
+ };
398
+
399
+ Leg.prototype.hide = function() {
400
+ this.visible = false;
401
+ if (this.bus.options.debug) {
402
+ return this.$el.css({
403
+ visibility: 'visible',
404
+ opacity: 0.4,
405
+ zIndex: 0
406
+ });
407
+ } else {
408
+ return this.$el.css({
409
+ visibility: 'hidden'
410
+ });
411
+ }
412
+ };
413
+
414
+ Leg.prototype.scrollIntoView = function() {
415
+ var scrollTarget;
416
+ if (!this.willScroll) {
417
+ return;
418
+ }
419
+ scrollTarget = utils.dataProp(this.options.scrollTo, this.$el);
420
+ this.bus._log('scrolling to', scrollTarget, this.scrollSettings);
421
+ return $.scrollTo(scrollTarget, this.scrollSettings);
422
+ };
423
+
424
+ Leg.prototype._setupOptions = function() {
425
+ var dataProps, globalOptions, prop, _i, _len, _results;
426
+ globalOptions = this.bus.options.leg;
427
+ dataProps = ['class', 'top', 'left', 'scrollTo', 'scrollSpeed', 'scrollContext', 'margin', 'arrow', 'align', 'width', 'zindex', 'orientation'];
428
+ _results = [];
429
+ for (_i = 0, _len = dataProps.length; _i < _len; _i++) {
430
+ prop = dataProps[_i];
431
+ _results.push(this.options[prop] = utils.dataProp(this.rawData[prop], globalOptions[prop]));
432
+ }
433
+ return _results;
434
+ };
435
+
436
+ Leg.prototype._configureElement = function() {
437
+ this.$el = $("<div class='tourbus-leg'></div>");
438
+ this.el = this.$el[0];
439
+ this.$el.attr({
440
+ id: this.elId
441
+ });
442
+ this.$el.addClass(this.options["class"]);
443
+ return this.$el.css({
444
+ zIndex: this.options.zindex
445
+ });
446
+ };
447
+
448
+ Leg.prototype._setupEvents = function() {
449
+ this.$el.on('click', '.tourbus-next', $.proxy(this.bus.next, this.bus));
450
+ this.$el.on('click', '.tourbus-prev', $.proxy(this.bus.prev, this.bus));
451
+ return this.$el.on('click', '.tourbus-stop', $.proxy(this.bus.stop, this.bus));
452
+ };
453
+
454
+ Leg.prototype._teardownEvents = function() {
455
+ return this.$el.off('click');
456
+ };
457
+
458
+ Leg.prototype._configureTarget = function() {
459
+ this.targetOffset = this.$target.offset();
460
+ if (utils.dataProp(this.options.top, false)) {
461
+ this.targetOffset.top = this.options.top;
462
+ }
463
+ if (utils.dataProp(this.options.left, false)) {
464
+ this.targetOffset.left = this.options.left;
465
+ }
466
+ this.targetWidth = this.$target.outerWidth();
467
+ return this.targetHeight = this.$target.outerHeight();
468
+ };
469
+
470
+ Leg.prototype._configureScroll = function() {
471
+ this.willScroll = $.fn.scrollTo && this.options.scrollTo !== false;
472
+ return this.scrollSettings = {
473
+ offset: -this.options.scrollContext,
474
+ easing: 'linear',
475
+ axis: 'y',
476
+ duration: this.options.scrollSpeed
477
+ };
478
+ };
479
+
480
+ Leg.prototype._offsets = function() {
481
+ var dimension, elHalf, elHeight, elWidth, offsets, targetHalf, targetHeightOverride, validOrientations;
482
+ elHeight = this.$el.height();
483
+ elWidth = this.$el.width();
484
+ offsets = {};
485
+ switch (this.options.orientation) {
486
+ case 'centered':
487
+ targetHeightOverride = $(window).height();
488
+ offsets.top = this.options.top;
489
+ if (!utils.dataProp(offsets.top, false)) {
490
+ offsets.top = (targetHeightOverride / 2) - (elHeight / 2);
491
+ }
492
+ offsets.left = (this.targetWidth / 2) - (elWidth / 2);
493
+ break;
494
+ case 'left':
495
+ offsets.top = this.targetOffset.top;
496
+ offsets.left = this.targetOffset.left - elWidth - this.options.margin;
497
+ break;
498
+ case 'right':
499
+ offsets.top = this.targetOffset.top;
500
+ offsets.left = this.targetOffset.left + this.targetWidth + this.options.margin;
501
+ break;
502
+ case 'top':
503
+ offsets.top = this.targetOffset.top - elHeight - this.options.margin;
504
+ offsets.left = this.targetOffset.left;
505
+ break;
506
+ case 'bottom':
507
+ offsets.top = this.targetOffset.top + this.targetHeight + this.options.margin;
508
+ offsets.left = this.targetOffset.left;
509
+ }
510
+ validOrientations = {
511
+ top: ['left', 'right'],
512
+ bottom: ['left', 'right'],
513
+ left: ['top', 'bottom'],
514
+ right: ['top', 'bottom']
515
+ };
516
+ if (utils.include(this.options.orientation, validOrientations[this.options.align])) {
517
+ switch (this.options.align) {
518
+ case 'right':
519
+ offsets.left += this.targetWidth - elWidth;
520
+ break;
521
+ case 'bottom':
522
+ offsets.top += this.targetHeight - elHeight;
523
+ }
524
+ } else if (this.options.align === 'center') {
525
+ if (utils.include(this.options.orientation, validOrientations.left)) {
526
+ targetHalf = this.targetWidth / 2;
527
+ elHalf = elWidth / 2;
528
+ dimension = 'left';
529
+ } else {
530
+ targetHalf = this.targetHeight / 2;
531
+ elHalf = elHeight / 2;
532
+ dimension = 'top';
533
+ }
534
+ if (targetHalf > elHalf) {
535
+ offsets[dimension] += targetHalf - elHalf;
536
+ } else {
537
+ offsets[dimension] -= elHalf - targetHalf;
538
+ }
539
+ }
540
+ return offsets;
541
+ };
542
+
543
+ return Leg;
544
+
545
+ })();
546
+
547
+ _addRule = (function(styleTag) {
548
+ var sheet;
549
+ styleTag.type = 'text/css';
550
+ document.getElementsByTagName('head')[0].appendChild(styleTag);
551
+ sheet = document.styleSheets[document.styleSheets.length - 1];
552
+ return function(selector, css) {
553
+ var key, propText;
554
+ propText = $.map((function() {
555
+ var _results;
556
+ _results = [];
557
+ for (key in css) {
558
+ _results.push(key);
559
+ }
560
+ return _results;
561
+ })(), function(p) {
562
+ return "" + p + ":" + css[p];
563
+ }).join(';');
564
+ try {
565
+ if (sheet.insertRule) {
566
+ sheet.insertRule("" + selector + " { " + propText + " }", (sheet.cssRules || sheet.rules).length);
567
+ } else {
568
+ sheet.addRule(selector, propText);
569
+ }
570
+ } catch (_error) {}
571
+ };
572
+ })(document.createElement('style'));
573
+
574
+ }).call(this);
575
+
576
+ },{"./utils":4}],4:[function(require,module,exports){
577
+ //@ sourceMappingURL=utils.map
578
+ (function() {
579
+ module.exports = {
580
+ dataProp: function(possiblyFalsy, alternative) {
581
+ if (possiblyFalsy === null || typeof possiblyFalsy === 'undefined') {
582
+ return alternative;
583
+ }
584
+ return possiblyFalsy;
585
+ },
586
+ include: function(value, array) {
587
+ return $.inArray(value, array || []) !== -1;
588
+ }
589
+ };
590
+
591
+ }).call(this);
592
+
593
+ },{}]},{},[1,2,3,4]);
@@ -0,0 +1,150 @@
1
+ /* Tourbus leg definitions element */
2
+ .tourbus-legs {
3
+ display: none;
4
+ }
5
+
6
+ .tour-overlay {
7
+ display: none;
8
+ background: #000000;
9
+ opacity: 0.7;
10
+ z-index: 9997;
11
+ min-height: 100%;
12
+ height: 100%;
13
+ position: fixed;
14
+ top: 0; right: 0; bottom: 0; left: 0;
15
+ }
16
+ .tour-highlight {
17
+ background: white;
18
+ position: relative;
19
+ box-shadow: inset 0 0 2px rgba( 0, 0, 0, 0.2 );
20
+ z-index: 9998;
21
+ }
22
+
23
+ /* Container for tourbus leg */
24
+ .tourbus-leg {
25
+ position: absolute;
26
+ visibility: hidden;
27
+ top: 0;
28
+ border: 1px solid #E5E5E5;
29
+ box-shadow: 0 0 2px rgba(0, 0, 0, 0.15);
30
+ border-radius: 2px;
31
+ background: white;
32
+ }
33
+ /* Interior of leg, clearfixed */
34
+ .tourbus-leg-inner {
35
+ padding: 20px;
36
+ position: relative;
37
+ zoom: 1;
38
+ }
39
+ .tourbus-leg-inner:before,
40
+ .tourbus-leg-inner:after {
41
+ content: "\0020";
42
+ display: block;
43
+ height: 0;
44
+ overflow: hidden;
45
+ }
46
+ .tourbus-leg-inner:after {
47
+ clear: both;
48
+ }
49
+ /*
50
+ remove top padding/margin on headings
51
+ because the interior of the leg has padding
52
+ */
53
+ .tourbus-leg h1,
54
+ .tourbus-leg h2,
55
+ .tourbus-leg h3,
56
+ .tourbus-leg h4,
57
+ .tourbus-leg h5,
58
+ .tourbus-leg h6 {
59
+ margin-top: 0;
60
+ padding-top: 0;
61
+ }
62
+ /* Tourbus leg arrow */
63
+ .tourbus-arrow:before,
64
+ .tourbus-arrow:after {
65
+ border: solid rgba(0, 0, 0, 0);
66
+ content: " ";
67
+ height: 0;
68
+ width: 0;
69
+ position: absolute;
70
+ pointer-events: none;
71
+ border-color: transparent;
72
+ }
73
+ /* set the :after to be the _interior_ size of the arrow */
74
+ /* set the :before to be the _interior + desired border width_ */
75
+ .tourbus-arrow:after {
76
+ border-width: 14px;
77
+ }
78
+ .tourbus-arrow:before {
79
+ border-width: 16px;
80
+ }
81
+ /* Arrow background and border colors */
82
+ /*
83
+ change margin-top/left values here to
84
+ match the border width for :after above
85
+
86
+ border colors here are for the _interior_ of the arrow
87
+ */
88
+ .tourbus-arrow-right:after {
89
+ border-right-color: #ffffff;
90
+ margin-top: -14px;
91
+ top: 50%;
92
+ }
93
+ .tourbus-arrow-left:after {
94
+ border-left-color: #ffffff;
95
+ margin-top: -14px;
96
+ top: 50%;
97
+ }
98
+ .tourbus-arrow-bottom:after {
99
+ border-bottom-color: #ffffff;
100
+ margin-left: -14px;
101
+ left: 50%;
102
+ }
103
+ .tourbus-arrow-top:after {
104
+ border-top-color: #ffffff;
105
+ margin-left: -14px;
106
+ left: 50%;
107
+ }
108
+ /*
109
+ change margin-top/left values here to
110
+ match the border width for :before above
111
+
112
+ border colors here are for the _border_ of the arrow
113
+ */
114
+ .tourbus-arrow-right:before {
115
+ border-right-color: #e5e5e5;
116
+ margin-top: -16px;
117
+ top: 50%;
118
+ }
119
+ .tourbus-arrow-left:before {
120
+ border-left-color: #e5e5e5;
121
+ margin-top: -16px;
122
+ top: 50%;
123
+ }
124
+ .tourbus-arrow-bottom:before {
125
+ border-bottom-color: #e5e5e5;
126
+ margin-left: -16px;
127
+ left: 50%;
128
+ }
129
+ .tourbus-arrow-top:before {
130
+ border-top-color: #e5e5e5;
131
+ margin-left: -16px;
132
+ left: 50%;
133
+ }
134
+ /* you shouldn't need to change these */
135
+ .tourbus-arrow-right:after,
136
+ .tourbus-arrow-right:before {
137
+ right: 100%;
138
+ }
139
+ .tourbus-arrow-left:after,
140
+ .tourbus-arrow-left:before {
141
+ left: 100%;
142
+ }
143
+ .tourbus-arrow-bottom:after,
144
+ .tourbus-arrow-bottom:before {
145
+ bottom: 100%;
146
+ }
147
+ .tourbus-arrow-top:after,
148
+ .tourbus-arrow-top:before {
149
+ top: 100%;
150
+ }
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tourguide
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Carlile
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sass-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coffee-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: builder
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Tourbus
84
+ email:
85
+ - adam@benchmedia.co.uk
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - app/assets/javascripts/tourguide.js
97
+ - app/assets/stylesheets/tourguide.css.sass
98
+ - app/helpers/tourguide/tourguide_helper.rb
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/tourguide.rb
102
+ - lib/tourguide/engine.rb
103
+ - lib/tourguide/renderers/connections.rb
104
+ - lib/tourguide/renderers/link.rb
105
+ - lib/tourguide/renderers/stop.rb
106
+ - lib/tourguide/renderers/tourbus.rb
107
+ - lib/tourguide/version.rb
108
+ - tourguide.gemspec
109
+ - vendor/assets/javascripts/tourguide/tourbus.js
110
+ - vendor/assets/stylesheets/tourguide/tourbus.css
111
+ homepage: http://www.github.com/boardiq/tourbus
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.5
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Tourbus
135
+ test_files: []