focus_watcher 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: af69da41e1021e6c3419b5bbe9617cd2562759c8
4
+ data.tar.gz: 2ef573de6ad528ea0e21db8cfec4180eb9a76b5a
5
+ SHA512:
6
+ metadata.gz: 40b2a272ae705b029bb92d9f97531c82ecfbb804e61462d9154861024aaef658a5a9453f0ef1e9d837b03cf5e0dd6f432e7a0425ad8de35a1ab41decbba02479
7
+ data.tar.gz: 3e7ff0a62c187df8109302fea69b3a2d7adf12b13302f685421c757f2c2ee29e715fdcba31d68f0c47e93c91182db44ac8ed1228ffcaf341b3ff84041bfc694a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
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.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = FocusWatcher
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'FocusWatcher'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,49 @@
1
+ class FocusWatcher
2
+ elements: []
3
+ focus: {
4
+ current: null
5
+ currentParents: []
6
+ currentObserved: []
7
+ previous: null
8
+ previousParents: []
9
+ previousObserved: []
10
+ }
11
+
12
+ register: (element) ->
13
+ @elements.push(element) for element in $(element)
14
+
15
+ constructor: ->
16
+ $(document).on 'click', (e) => @_changeFocus(e.target)
17
+
18
+ _changeFocus: (target) ->
19
+ return unless target?
20
+ cleanTarget = if target instanceof jQuery then target.get(0) else target
21
+ return if @focus.current == cleanTarget
22
+ # Копируем предыдущий элемент
23
+ @focus.previous = @focus.current
24
+ @focus.current = cleanTarget
25
+ # Копируем предыдущих предков
26
+ @focus.previousParents = @focus.currentParents
27
+ @focus.currentParents = $(@focus.current).parents().toArray()
28
+ # Копируем предыдущие контроллируемые элементы
29
+ @focus.previousObserved = @focus.currentObserved
30
+ @focus.currentObserved = []
31
+ for parent in @focus.currentParents
32
+ @focus.currentObserved.push(parent) if @elements.indexOf(parent) > -1
33
+ @_processChange()
34
+ @focus.current
35
+
36
+ _processChange: ->
37
+ @_sendDefocused(parent) for parent in @focus.previousObserved
38
+ @_sendFocused(parent) for parent in @focus.currentObserved
39
+
40
+
41
+ _sendFocused: (target) =>
42
+ console.log(target, 'focused')
43
+ $(target).trigger('focused', [@focus.previous, @focus.current])
44
+
45
+ _sendDefocused: (target) =>
46
+ console.log(target, 'defocused')
47
+ $(target).trigger('defocused', [@focus.previous, @focus.current])
48
+
49
+ window.FocusWatcher = new FocusWatcher
@@ -0,0 +1,5 @@
1
+ module FocusWatcher
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace FocusWatcher
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module FocusWatcher
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'focus_watcher/engine'
2
+
3
+ module FocusWatcher
4
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: focus_watcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Gorbunov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description: Gem for tracking the receipt and loss focus of dom elements
28
+ email:
29
+ - lexgorbunov@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - app/assets/javascripts/focus_watcher.js.coffee
38
+ - lib/focus_watcher.rb
39
+ - lib/focus_watcher/engine.rb
40
+ - lib/focus_watcher/version.rb
41
+ homepage: https://github.com/lexgorbunov/focus_watcher
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.2.2
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Gem for tracking the receipt and loss focus of dom elements
65
+ test_files: []