Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 72d266250b47fa6ac43030d02e4325558b629a6d 0 parents
@phlipper authored
17 .gitignore
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
1  .ruby-version
@@ -0,0 +1 @@
+1.9.3@chaves-rails
4 Gemfile
@@ -0,0 +1,4 @@
+source "https://rubygems.org"
+
+# Specify your gem's dependencies in chaves-rails.gemspec
+gemspec
20 LICENSE.txt
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+Copyright © 2012 Phil Cohen <github@phlippers.net>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the “Software”), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
66 README.md
@@ -0,0 +1,66 @@
+# chaves-rails
+
+[Chaves.js](https://github.com/jayroh/chaves.js), bundled for Rails 3.0 and up.
+
+
+## Rails 3.1+
+
+For Rails 3.1 and greater, the files will be added to the asset pipeline and available for you to use.
+
+To enable:
+
+* Add the following line to the file `app/assets/javascripts/application.js` (or other [sprockets](https://github.com/sstephenson/sprockets) manifest):
+
+``` javascript
+//= require jquery.chaves
+```
+
+
+### Installation
+
+* Add `chaves-rails` to your Gemfile
+* Run `bundle`
+
+Enjoy!
+
+
+## Rails 3.0
+
+This gem adds a single generator to Rails 3, `chaves:install`. Running the generator will install the JavaScript file necessary to use Chaves.
+
+### Installation
+
+* Add `chaves-rails` to your Gemfile
+* Run `bundle`
+* Invoke the generator: `rails generate chaves:install`
+* Add the following to your layout or view files:
+
+```erb
+<%= javascript_include_tag "jquery.chaves" %>
+```
+
+You're done!
+
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
+
+
+## License
+
+**chaves-rails**
+
+* Freely distributable and licensed under the [MIT license](http://phlipper.mit-license.org/2012/license.html).
+* Copyright (c) 2012 Phil Cohen (github@phlippers.net) [![endorse](http://api.coderwall.com/phlipper/endorsecount.png)](http://coderwall.com/phlipper)
+* http://phlippers.net/
+
+**Chaves.js**
+
+* Dual licensed under the MIT and GPL licenses.
+* Copyright (c) 2012 Joel Oliveira
+* https://github.com/jayroh/chaves.js
2  Rakefile
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
21 chaves-rails.gemspec
@@ -0,0 +1,21 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/chaves/rails/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Phil Cohen"]
+ gem.email = ["github@phlippers.net"]
+ gem.description = %q{chaves.js, bundled for Rails 3.0 and up.}
+ gem.summary = %q{chaves.js, bundled for Rails 3.0 and up.}
+ gem.homepage = "https://github.com/phlipper/chaves-rails"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "chaves-rails"
+ gem.require_paths = ["lib"]
+ gem.version = Chaves::Rails::VERSION
+
+ gem.add_dependency "railties", ">= 3.0.0"
+ gem.add_development_dependency "bundler", ">= 1.1.0"
+ gem.add_development_dependency "rake", "~> 0.9.2.2"
+end
1  lib/chaves-rails.rb
@@ -0,0 +1 @@
+require "chaves/rails"
6 lib/chaves/rails.rb
@@ -0,0 +1,6 @@
+module Chaves
+ module Rails
+ require "chaves/rails/engine"
+ require "chaves/rails/version"
+ end
+end
7 lib/chaves/rails/engine.rb
@@ -0,0 +1,7 @@
+# Configure Rails 3.1 to have assets in the load path
+module Chaves
+ module Rails
+ class Engine < ::Rails::Engine
+ end
+ end
+end
6 lib/chaves/rails/version.rb
@@ -0,0 +1,6 @@
+module Chaves
+ module Rails
+ VERSION = "0.1.0"
+ CHAVESJS_VERSION = "0.1.0"
+ end
+end
35 lib/generators/chaves/install/install_generator.rb
@@ -0,0 +1,35 @@
+require "rails"
+
+# Supply generator for Rails 3.0.x or if asset pipeline is not enabled
+if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
+ module Chaves
+ module Generators
+ class InstallGenerator < ::Rails::Generators::Base
+ desc "This generator installs jquery.chaves #{Chaves::Rails::CHAVESJS_VERSION}"
+ source_root File.expand_path("../../../../../vendor/assets", __FILE__)
+
+ def copy_javascript
+ say_status("copying", "jquery.chaves.js", :green)
+ copy_file "javascripts/jquery.chaves.js", "public/javascripts/jquery.chaves.js"
+ end
+ end
+ end
+ end
+else
+ module Chaves
+ module Generators
+ class InstallGenerator < ::Rails::Generators::Base
+ desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"
+
+ def do_nothing
+ say_status("deprecated", "You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed.")
+ say_status("", "The necessary files are already in your asset pipeline.")
+ say_status("", "Just add `//= require jquery.chaves` to your app/assets/javascripts/application.js")
+ say_status("", "If you upgraded your app from Rails 3.0 and still have jquery.chaves.js in your public assets folders, be sure to remove them.")
+ say_status("", "If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.")
+ # ok, nothing
+ end
+ end
+ end
+ end
+end
132 vendor/assets/javascripts/jquery.chaves.js
@@ -0,0 +1,132 @@
+// Generated by CoffeeScript 1.3.3
+(function() {
+
+ $.fn.extend({
+ chaves: function(options) {
+ var self;
+ self = $.fn.chaves;
+ options = $.extend({}, self.default_options, options);
+ return $(this).each(function(i, el) {
+ return self.init(el, options);
+ });
+ }
+ });
+
+ $.extend($.fn.chaves, {
+ version: '0.1.0',
+ default_options: {
+ activeClass: 'active',
+ bindings: [],
+ childSelector: '> *',
+ className: 'jquery-chaves',
+ enableUpDown: false,
+ helpModalClass: 'jquery-chaves-help',
+ linkSelector: 'a:first',
+ scope: 'all',
+ searchSelector: '.search,\
+ #search,\
+ input[type="text"][value*="earch"],\
+ input[type="text"][placeholder*="earch"]'
+ },
+ init: function(el, options) {
+ var addToHelp, clickActive, downkeys, goDown, goUp, hideHelp, register_all_bindings, searchFocus, showHelp, upkeys,
+ _this = this;
+ this.options = options;
+ this.bindings = $.extend([], options.bindings);
+ this.el = $(el).addClass(options.className);
+ this.children = this.el.find(options.childSelector);
+ this.active = this.children.first().addClass(options.activeClass);
+ this.help = this.findOrCreateHelp();
+ downkeys = 'j';
+ upkeys = 'k';
+ if (options.enableUpDown) {
+ downkeys += ", down";
+ upkeys += ", up";
+ }
+ register_all_bindings = function() {
+ var binding, _i, _len, _ref, _results;
+ _ref = _this.bindings;
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ binding = _ref[_i];
+ key(binding[0], _this.options.scope, binding[2]);
+ _results.push(addToHelp(binding[0], binding[1]));
+ }
+ return _results;
+ };
+ addToHelp = function(keys, description) {
+ return _this.help.find('dl').append("<dt>" + keys + "</dt><dd>" + description + "</dd>");
+ };
+ goUp = function() {
+ var prev;
+ if ((_this.active.prev().length)) {
+ prev = _this.active.prev().addClass(_this.options.activeClass);
+ _this.active.removeClass(_this.options.activeClass);
+ _this.active = prev;
+ return _this.readjust(150);
+ }
+ };
+ goDown = function() {
+ var next;
+ if ((_this.active.next().length)) {
+ next = _this.active.next().addClass(_this.options.activeClass);
+ _this.active.removeClass(_this.options.activeClass);
+ _this.active = next;
+ return _this.readjust(0);
+ }
+ };
+ showHelp = function() {
+ return _this.help.toggleClass('visible');
+ };
+ hideHelp = function() {
+ return _this.help.removeClass('visible');
+ };
+ searchFocus = function() {
+ _this.search = $(_this.options.searchSelector);
+ return window.setTimeout((function() {
+ return _this.search.focus();
+ }), 10);
+ };
+ clickActive = function() {
+ var link;
+ link = _this.active.find(_this.options.linkSelector);
+ if (link.trigger('click').attr('target') === '_blank') {
+ return window.open(link.attr('href'), 'popped');
+ } else {
+ return window.location.href = link.attr('href');
+ }
+ };
+ this.bindings.push([upkeys, 'Move selection up.', goUp]);
+ this.bindings.push([downkeys, 'Move selection down.', goDown]);
+ this.bindings.push(['shift+/', 'Toggle help dialog.', showHelp]);
+ this.bindings.push(['esc, escape', 'Close help dialog.', hideHelp]);
+ this.bindings.push(['/', 'Focus on search.', searchFocus]);
+ this.bindings.push(['enter', 'Open/click element.', clickActive]);
+ return register_all_bindings();
+ },
+ readjust: function(buffer) {
+ var top;
+ if (this.elementOutOfViewport(this.active[0])) {
+ top = this.active.offset().top - buffer;
+ return $(window).scrollTop(top).trigger('scroll');
+ }
+ },
+ elementOutOfViewport: function(el) {
+ var rect;
+ if (el) {
+ rect = el.getBoundingClientRect();
+ return !(rect.top >= 0 && rect.left >= 0 && rect.bottom <= window.innerHeight && rect.right <= window.innerWidth);
+ }
+ },
+ findOrCreateHelp: function() {
+ var help, helpSelector;
+ helpSelector = "." + this.options.helpModalClass;
+ if (!$(helpSelector).length) {
+ $('body').append("<div class=" + this.options.helpModalClass + "></div>");
+ help = $(helpSelector).append('<h3>Keyboard Shortcuts</h3><dl></dl>');
+ }
+ return $(helpSelector);
+ }
+ });
+
+}).call(this);
Please sign in to comment.
Something went wrong with that request. Please try again.