ui_guiders 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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.1.3"
10
+ gem "jeweler", "~> 1.8.3"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.3)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.6.6)
11
+ rake (0.9.2.2)
12
+ rdoc (3.12)
13
+ json (~> 1.4)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.1.3)
20
+ jeweler (~> 1.8.3)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Roman Snitko
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,96 @@
1
+ UIGuiders
2
+ =========
3
+
4
+ *Visual guiders for website UIs*
5
+ It's like "Guiders-JS", but easily customizable and less js-centric.
6
+
7
+ Why?
8
+ ----
9
+ Because I wanted an easy soulution that wouldn't be all javascript. I don't think it's a good idea to assign
10
+ guiders on the js-level, like Guiders.js does. Instead, it should be in the views. The javascript part
11
+ only handles proper positioning and effects part, while remaining uninvolved into the styles/content business.
12
+
13
+ If you wish, you may just use the js part and use it outside of the Rails app.
14
+ (Actually, it's written in coffeescript, so you'd have to compile it first).
15
+
16
+ The javascript part will correctly determine which part of the screen the target DOM-element is positioned and
17
+ then choose how to display the guider - what side the arrow should be on and should the guider be on top or
18
+ at the bottom of the target DOM-element. No need to manually specify any options.
19
+
20
+ See Screenshot.png file for a small demonstration of how it looks.
21
+
22
+ INSTALLATION
23
+ ------------
24
+
25
+ 1. gem install ui_guiders
26
+
27
+ 2.
28
+ (a) Add to your scss: `@import "ui_guiders";` OR
29
+ (b) Add to your layout: `stylesheet_link_tag 'ui_guiders'`
30
+
31
+ 3.
32
+ (a) Add to your application.js.coffee `#= require lib/ui_guiders` OR
33
+ (b) Add to your layout: `javascript_include_tag "lib/ui_guiders"`
34
+
35
+
36
+ Usage
37
+ -----
38
+
39
+ This is what you put in your views (haml example):
40
+
41
+ = ui_guider :target => "header .menuItem1", :autoshow => true, :event => "click", :show_once => true, :id => "menu_item_1_guider", :class => "myclass" do
42
+ text explaining
43
+ this awesome menuitem
44
+
45
+ That's it. Now when your page is loaded a shiny yellow guider will appear pointing at the DOM element you specified with the :target option.
46
+ Other options explanation:
47
+
48
+ `:autoshow` if true, js-part of the plugin will force the guider to appear up
49
+ immediately after the page loads. Default is false.
50
+
51
+ `:autohide` if true, it hides the guider whenever the `mouseout` event happens on the target element.
52
+ The close ico does not appear if this option is enabled (because this option also adds `autohide` class to
53
+ the .uiGuider element, and default css sets a `display` property of `img.close` in it to `none`).
54
+
55
+ `:show_once` Saves cookie with the id of the guider. Next time the user visits, the guider is not shown.
56
+ Default is false.
57
+
58
+ `:event` jQuery event (for example `click` or `mouseover`) which is binded to the target and on which the guider is shown.
59
+
60
+ `:side_arrow` Normally the arrow would appear either on top or the bottom side of the guider, but with this option set to true, you can an arrow
61
+ on either left or right side of the guider. Use with caution, as this may force horizontal scrollbars to appear if your targer is
62
+ placed to close the edge of the screen.
63
+
64
+ `:target_edge` Sets a horizontal location on the target for the arrow to point to, possible values are "left", "right" or "middle"
65
+ (default is "middle").
66
+
67
+ `:id`
68
+ `:class` Both are applied to the html-element.
69
+
70
+
71
+ Customization
72
+ -------------
73
+ * Want different styles?
74
+ copy `app/assets/stylesheets/ui_guiders.css.scss` from the gem dir and change it.
75
+
76
+ * Replacing images?
77
+ You guessed it right. Copy `app/assets/images/ui_guiders/` from the gem dir and change it.
78
+
79
+ For images and stylesheets make sure your `app/assets` dir loads last, so that Rails loads *your* files.
80
+ I managed to do it with
81
+
82
+ config.assets.paths << "#{Rails.root}/app/assets/stylesheets/"
83
+ config.assets.paths << "#{Rails.root}/app/assets/images/"
84
+
85
+ in my `config/application.rb`
86
+
87
+ * Want a different markup?
88
+ copy `app/assets/views/shared/_ui_guider.haml` from the plugin dir and change it.
89
+
90
+
91
+ Requirements
92
+ ------------
93
+
94
+ * Rails 3.1 (sorry, no 3.0 support, using assets)
95
+ * jQuery (tested on 1.5.2)
96
+ * jquery.cookie.js
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ui_guiders"
18
+ gem.homepage = "http://github.com/snitko/ui_guiders"
19
+ gem.license = "MIT"
20
+ gem.summary = "Visual guiders for website UIs."
21
+ gem.description = "It's like \"Guiders-JS\", but easily customizable and less js-centric."
22
+ gem.email = "roman.snitko@gmail.com"
23
+ gem.authors = ["Roman Snitko"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
data/Screenshot.png ADDED
Binary file
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,159 @@
1
+ jQuery ($) ->
2
+
3
+ window.UIGuider = class UIGuider
4
+
5
+ constructor: (block) ->
6
+ @block = $(block)
7
+ @target = $($(@block).attr("data-target-element"))
8
+ @arrows = {
9
+ top: @block.children(".arrow.top")
10
+ bottom: @block.children(".arrow.bottom")
11
+ left: @block.children(".arrow.side.left")
12
+ right: @block.children(".arrow.side.right")
13
+ }
14
+ @state = "hidden"
15
+
16
+ @hide_arrows = () ->
17
+ for a in @arrows
18
+ a.hide()
19
+
20
+ # Places arrow to the right corner of the Guider.
21
+ # It's top/bottom and left/right position is always equal to that
22
+ # of a target.
23
+ @place_arrow = (pos, options={}) ->
24
+ @hide_arrows()
25
+ if options.side_arrow
26
+ @arrows[pos.x].css(top: @block.height()/2 - @arrows.left.height()).show()
27
+ else
28
+ @arrows[pos.y].show().addClass(pos.x)
29
+
30
+ # Places Guider so that its arrow always points to the target.
31
+ # Depending on the position of the target the guider will appear on the left
32
+ # or on the right side of the target.
33
+ #
34
+ # To set a horizontal location on the target for the arrow to point to,
35
+ # use "edge" option for that with "left", "right" or "middle" (default is "middle").
36
+ #
37
+ # To set the type of arrow (side arrow or arrows appearing on the top or the bottom of the guider),
38
+ # set "side_arrow" option to true.
39
+ @place_guider = (pos, options={}) ->
40
+
41
+ if options.side_arrow
42
+ arrow = @arrows.left
43
+ arrow_offset_sign = 1
44
+ else
45
+ arrow = @arrows.top
46
+ arrow_offset_sign = -1
47
+
48
+ if options.side_arrow
49
+ top_offset = @target.offset().top + @target.height()/2 - @block.height()/2
50
+ else if pos.y == "top"
51
+ top_offset = @target.offset().top + @target.height() + arrow.height()
52
+ else
53
+ top_offset = @target.offset().top - @block.height() - arrow.height()
54
+
55
+ if pos.x == "left"
56
+ pos_left_offset = @target.offset().left + arrow.width()*arrow_offset_sign
57
+ if options.edge == "left"
58
+ width_left_offset = 0
59
+ else if options.edge == "right"
60
+ width_left_offset = @target.width()
61
+ else
62
+ width_left_offset = @target.width()/2
63
+ else
64
+ arrow_offset_sign = -arrow_offset_sign
65
+ pos_left_offset = @target.offset().left + arrow.width()*arrow_offset_sign
66
+ if options.edge == "left"
67
+ width_left_offset = -@block.width()
68
+ else if options.edge == "right"
69
+ width_left_offset = -@block.width() + @target.width()
70
+ else
71
+ width_left_offset = -@block.width() + @target.width()/2
72
+
73
+
74
+ @block.css { top: top_offset }
75
+ @block.css { left: pos_left_offset + width_left_offset }
76
+
77
+
78
+ @set_cookie = () ->
79
+ $.cookie("UIGuider_#{@block.attr("id")}", "1", { expires: 3560 }) if @block.hasClass("show_once") and @block.attr("id")
80
+
81
+ # Finds which part of the screen the target is located,
82
+ # top/bottom and left/right. It is later used to position
83
+ # the Guider and its arrow.
84
+ @target_location = () ->
85
+ return @target_location_cached if @target_location_cached
86
+ if $(document).width()/2 - @target.offset().left < 0
87
+ x = "right"
88
+ else
89
+ x = "left"
90
+ if $(document).height()/2 - @target.offset().top < 0
91
+ y = "bottom"
92
+ else
93
+ y = "top"
94
+ @target_location_cached = { x: x, y: y }
95
+
96
+ show: (options={}) ->
97
+ return if @hiding
98
+ UIGuidersCollection.hide_all()
99
+ return if $.cookie("UIGuider_#{@block.attr("id")}")
100
+
101
+ options["side_arrow"] = true if @block.hasClass("side_arrow")
102
+ options["edge"] = @block.attr("data-target-edge") if @block.attr("data-target-edge")
103
+ @target = options.target if options.target
104
+
105
+ @place_arrow @target_location(), options
106
+ @place_guider @target_location(), options
107
+
108
+ @set_cookie()
109
+ @block.find(".content").html(options["content"]) if options["content"]
110
+ @block.fadeIn(300)
111
+ @state = "visible"
112
+
113
+ hide: () ->
114
+ return if @hiding
115
+ @hiding = true
116
+ @block.fadeOut 300, () =>
117
+ @hiding = false
118
+ @state = "hidden"
119
+
120
+
121
+ class _UIGuidersCollection
122
+
123
+
124
+ constructor: () ->
125
+
126
+ @ui_guiders = []
127
+ for g in $(".uiGuider")
128
+ @ui_guiders.push new UIGuider(g)
129
+
130
+ for g in @ui_guiders
131
+ if g.block.hasClass("autoshow")
132
+ setTimeout () ->
133
+ g.show()
134
+ , 1000
135
+
136
+ if g.block.hasClass("autohide")
137
+ g.target.bind "mouseleave", { guider: g }, (event) ->
138
+ event.data.guider.hide()
139
+
140
+ if g.block.attr("data-event-name") && g.block.attr("data-event-name").length > 0
141
+ g.target.bind g.block.attr("data-event-name"), { guider: g }, (event) =>
142
+ event.data.guider.show(target: $(event.currentTarget)) unless event.data.guider.state == "visible"
143
+
144
+ g.block.find(".close").click () ->
145
+ g.hide()
146
+
147
+
148
+ find: (id) ->
149
+ result = null
150
+ for guider in @ui_guiders
151
+ result = guider if guider.block.attr("id") == id
152
+ result
153
+
154
+ hide_all: () ->
155
+ for guider in @ui_guiders
156
+ guider.hide()
157
+
158
+ window._UIGuidersCollection = _UIGuidersCollection
159
+ window.UIGuidersCollection = new _UIGuidersCollection()
@@ -0,0 +1,34 @@
1
+ @mixin clearfix {
2
+ display: block;
3
+ &:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
4
+ }
5
+
6
+ .uiGuider {
7
+
8
+ display: none; position: absolute; z-index: 2000;
9
+ width: 350px; color: #000; font-size: 0px;
10
+ background: #eecf84 asset_url("ui_guiders/box_bgrnd.png", "image"); background-repeat: repeat-x;
11
+
12
+ .content {
13
+ padding: 1em; margin: -5px 0 0 0; font-size: 11px;
14
+ a, a:visited { color: #a20000; }
15
+ }
16
+
17
+ img.arrow { position: relative; display: none; height: 5px; width: 13px; }
18
+ img.arrow.top { @include clearfix; }
19
+ img.arrow.top.left { top: -5px; left: 5px; margin: 0 0 0 0; }
20
+ img.arrow.top.right { top: -5px; left: -5px; float: right; margin: 0 0 0 0; }
21
+ img.arrow.bottom.left { top: 0; left: 5px; margin: 0 0 -5px 0; }
22
+ img.arrow.bottom.right { top: 0; left: -5px; float: right; margin: 0 0 -5px 0; }
23
+
24
+ img.arrow.side { width: 5px; height: 13px; margin-bottom: -13px; }
25
+ img.arrow.side.left { left: -5px; }
26
+ img.arrow.side.right { float: right; right: -5px; }
27
+
28
+
29
+ img.close { position: relative; cursor: pointer; float: right; right: 8px; top: 8px; opacity: 0.3; filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=30); margin: 0 0 15px 15px; }
30
+ img.close:hover { opacity: 0.5; filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50); }
31
+
32
+ &.autohide img.close { display: none; }
33
+
34
+ }
@@ -0,0 +1,20 @@
1
+ module UiGuidersHelper
2
+
3
+ def ui_guider(options={}, &block)
4
+ return if cookies["UIGuider_#{options[:id]}"]
5
+ if block_given?
6
+ content = capture(&block)
7
+ elsif options[:template]
8
+ content = render(options[:template])
9
+ else
10
+ content = options[:text].html_safe
11
+ end
12
+ options[:class] = "" unless options[:class]
13
+ options[:class] += " autoshow" if options[:autoshow]
14
+ options[:class] += " autohide" if options[:autohide]
15
+ options[:class] += " show_once" if options[:show_once]
16
+ options[:class] += " side_arrow" if options[:side_arrow]
17
+ render :partial => "shared/ui_guider", :locals => { :content => content, :options => options }
18
+ end
19
+
20
+ end
@@ -0,0 +1,11 @@
1
+ .uiGuider{ "data-target-element" => options[:target], "data-event-name" => options[:event], :class => options[:class], :id => options[:id], "data-target-edge" => options[:target_edge] }
2
+
3
+ = image_tag "ui_guiders/top_arrow.png", :class => "arrow top"
4
+ = image_tag "ui_guiders/left_arrow.png", :class => "arrow side left"
5
+ = image_tag "ui_guiders/right_arrow.png", :class => "arrow side right"
6
+ = image_tag "ui_guiders/close_ico.png", :class => "close"
7
+
8
+ .content
9
+ = content
10
+
11
+ = image_tag "ui_guiders/bottom_arrow.png", :class => "arrow bottom"
data/lib/ui_guiders.rb ADDED
@@ -0,0 +1,6 @@
1
+ module UIGuiders
2
+
3
+ class Engine < Rails::Engine
4
+ end
5
+
6
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ui_guiders
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Roman Snitko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.3
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: jeweler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.8.3
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.8.3
46
+ description: It's like "Guiders-JS", but easily customizable and less js-centric.
47
+ email: roman.snitko@gmail.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files:
51
+ - LICENSE.txt
52
+ - README.markdown
53
+ files:
54
+ - .document
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE.txt
58
+ - README.markdown
59
+ - Rakefile
60
+ - Screenshot.png
61
+ - VERSION
62
+ - app/assets/images/ui_guiders/bottom_arrow.png
63
+ - app/assets/images/ui_guiders/box_bgrnd.png
64
+ - app/assets/images/ui_guiders/close_ico.png
65
+ - app/assets/images/ui_guiders/left_arrow.png
66
+ - app/assets/images/ui_guiders/right_arrow.png
67
+ - app/assets/images/ui_guiders/top_arrow.png
68
+ - app/assets/javascripts/lib/ui_guiders.js.coffee
69
+ - app/assets/stylesheets/ui_guiders.css.scss
70
+ - app/helpers/ui_guiders_helper.rb
71
+ - app/views/shared/_ui_guider.haml
72
+ - lib/ui_guiders.rb
73
+ homepage: http://github.com/snitko/ui_guiders
74
+ licenses:
75
+ - MIT
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ segments:
87
+ - 0
88
+ hash: -648122855321890561
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.21
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Visual guiders for website UIs.
101
+ test_files: []