diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb
index ac5f417..b626975 100644
--- a/app/controllers/public/search_controller.rb
+++ b/app/controllers/public/search_controller.rb
@@ -52,8 +52,8 @@ class SearchController < ApplicationController
@tagged = @tag.taggings.map(&:taggable)
end
- def advanced_search
-
+ def popup
+ render :action => 'popup', :layout => false
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index c7f7286..e8832b4 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,7 +1,10 @@
# Methods added to this helper will be available to all templates in the
# application.
module ApplicationHelper
+
include PermissionName
+
+ include LightboxHelper
# Displays context help. You can pass the content of the help message as the
# first parameter or using template code inside a block passed to this
@@ -110,6 +113,8 @@ module ApplicationHelper
end
def shortcut_header_links
+ search_link = ( lightbox_link_to content_tag('span', _('Search')), { :controller => 'search', :action => 'popup' }, { :id => 'open_search'} )
+
if logged_in?
[
( link_to_homepage '
Search'
+ search_link,
]
else
[
( link_to _("%s's home") % @environment.name, { :controller=>"home" }, :id=>"link_to_envhome" ),
( link_to content_tag('span', _('Login')), { :controller => 'account', :action => 'login' }, :id => 'link_login' ),
- 'Search'
+ search_link,
]
end.join(" ")
end
diff --git a/app/helpers/lightbox_helper.rb b/app/helpers/lightbox_helper.rb
new file mode 100644
index 0000000..f61361f
--- /dev/null
+++ b/app/helpers/lightbox_helper.rb
@@ -0,0 +1,19 @@
+module LightboxHelper
+
+ def include_lightbox_header
+ stylesheet_link_tag('lightbox') + javascript_include_tag('lightbox')
+ end
+
+ def lightbox_link_to(text, url, options = {})
+ the_class = 'lbOn'
+ the_class << " #{options[:class]}" if options.has_key?(:class)
+ link_to(text, url, options.merge(:class => the_class ))
+ end
+
+ def lightbox_close(text, options = {})
+ the_class = 'lbAction'
+ the_class << " #{options[:class]}" if options.has_key?(:class)
+ link_to(text, '#', options.merge({ :class => the_class, :rel => 'deactivate' }))
+ end
+
+end
diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml
index ecaa7d7..52534bc 100644
--- a/app/views/layouts/application.rhtml
+++ b/app/views/layouts/application.rhtml
@@ -17,6 +17,7 @@
<%= stylesheet_link_tag 'button' %>
<%= stylesheet_link_tag 'search' %>
<%= javascript_include_tag 'menu' %>
+ <%= include_lightbox_header %>
<%# cms stuff %>
<% if params[:controller] == 'cms' %>
<%= javascript_include_tag 'cms' %>
diff --git a/app/views/search/popup.rhtml b/app/views/search/popup.rhtml
new file mode 100644
index 0000000..04f9613
--- /dev/null
+++ b/app/views/search/popup.rhtml
@@ -0,0 +1,21 @@
+
<%= _('Search %s') % @environment.name %>
+
+<% form_tag(:action => 'index') do%>
+
+ <%= text_field_tag('query', '', :style => 'width: 70%;') %>
+ <%= submit_tag(_('Search')) %>
+
+
+ <%= _('Search options') %>
+
+
+
+ <%= submit_tag(_('Search')) %>
+ <%= lightbox_close(_('Close')) %>
+
+
+<% end %>
+
+
diff --git a/public/javascripts/lightbox.js b/public/javascripts/lightbox.js
new file mode 100644
index 0000000..569f528
--- /dev/null
+++ b/public/javascripts/lightbox.js
@@ -0,0 +1,202 @@
+/*
+Created By: Chris Campbell
+Website: http://particletree.com
+Date: 2/1/2006
+
+Inspired by the lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
+*/
+
+/*-------------------------------GLOBAL VARIABLES------------------------------------*/
+
+var detect = navigator.userAgent.toLowerCase();
+var OS,browser,version,total,thestring;
+
+/*-----------------------------------------------------------------------------------------------*/
+
+//Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/
+
+function getBrowserInfo() {
+ if (checkIt('konqueror')) {
+ browser = "Konqueror";
+ OS = "Linux";
+ }
+ else if (checkIt('safari')) browser = "Safari"
+ else if (checkIt('omniweb')) browser = "OmniWeb"
+ else if (checkIt('opera')) browser = "Opera"
+ else if (checkIt('webtv')) browser = "WebTV";
+ else if (checkIt('icab')) browser = "iCab"
+ else if (checkIt('msie')) browser = "Internet Explorer"
+ else if (!checkIt('compatible')) {
+ browser = "Netscape Navigator"
+ version = detect.charAt(8);
+ }
+ else browser = "An unknown browser";
+
+ if (!version) version = detect.charAt(place + thestring.length);
+
+ if (!OS) {
+ if (checkIt('linux')) OS = "Linux";
+ else if (checkIt('x11')) OS = "Unix";
+ else if (checkIt('mac')) OS = "Mac"
+ else if (checkIt('win')) OS = "Windows"
+ else OS = "an unknown operating system";
+ }
+}
+
+function checkIt(string) {
+ place = detect.indexOf(string) + 1;
+ thestring = string;
+ return place;
+}
+
+/*-----------------------------------------------------------------------------------------------*/
+
+Event.observe(window, 'load', initialize, false);
+Event.observe(window, 'load', getBrowserInfo, false);
+Event.observe(window, 'unload', Event.unloadCache, false);
+
+var lightbox = Class.create();
+
+lightbox.prototype = {
+
+ yPos : 0,
+ xPos : 0,
+
+ initialize: function(ctrl) {
+ this.content = ctrl.href;
+ Event.observe(ctrl, 'click', this.activate.bindAsEventListener(this), false);
+ ctrl.onclick = function(){return false;};
+ },
+
+ // Turn everything on - mainly the IE fixes
+ activate: function(){
+ if (browser == 'Internet Explorer'){
+ this.getScroll();
+ this.prepareIE('100%', 'hidden');
+ this.setScroll(0,0);
+ this.hideSelects('hidden');
+ }
+ this.displayLightbox("block");
+ },
+
+ // Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox
+ prepareIE: function(height, overflow){
+ bod = document.getElementsByTagName('body')[0];
+ bod.style.height = height;
+ bod.style.overflow = overflow;
+
+ htm = document.getElementsByTagName('html')[0];
+ htm.style.height = height;
+ htm.style.overflow = overflow;
+ },
+
+ // In IE, select elements hover on top of the lightbox
+ hideSelects: function(visibility){
+ selects = document.getElementsByTagName('select');
+ for(i = 0; i < selects.length; i++) {
+ selects[i].style.visibility = visibility;
+ }
+ },
+
+ // Taken from lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
+ getScroll: function(){
+ if (self.pageYOffset) {
+ this.yPos = self.pageYOffset;
+ } else if (document.documentElement && document.documentElement.scrollTop){
+ this.yPos = document.documentElement.scrollTop;
+ } else if (document.body) {
+ this.yPos = document.body.scrollTop;
+ }
+ },
+
+ setScroll: function(x, y){
+ window.scrollTo(x, y);
+ },
+
+ displayLightbox: function(display){
+ $('overlay').style.display = display;
+ $('lightbox').style.display = display;
+ if(display != 'none') this.loadInfo();
+ },
+
+ // Begin Ajax request based off of the href of the clicked linked
+ loadInfo: function() {
+ var myAjax = new Ajax.Request(
+ this.content,
+ {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)}
+ );
+
+ },
+
+ // Display Ajax response
+ processInfo: function(response){
+ info = "" + response.responseText + "
";
+ new Insertion.Before($('lbLoadMessage'), info)
+ $('lightbox').className = "done";
+ this.actions();
+ },
+
+ // Search through new links within the lightbox, and attach click event
+ actions: function(){
+ lbActions = document.getElementsByClassName('lbAction');
+
+ for(i = 0; i < lbActions.length; i++) {
+ Event.observe(lbActions[i], 'click', this[lbActions[i].rel].bindAsEventListener(this), false);
+ lbActions[i].onclick = function(){return false;};
+ }
+
+ },
+
+ // Example of creating your own functionality once lightbox is initiated
+ insert: function(e){
+ link = Event.element(e).parentNode;
+ Element.remove($('lbContent'));
+
+ var myAjax = new Ajax.Request(
+ link.href,
+ {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)}
+ );
+
+ },
+
+ // Example of creating your own functionality once lightbox is initiated
+ deactivate: function(){
+ Element.remove($('lbContent'));
+
+ if (browser == "Internet Explorer"){
+ this.setScroll(0,this.yPos);
+ this.prepareIE("auto", "auto");
+ this.hideSelects("visible");
+ }
+
+ this.displayLightbox("none");
+ }
+}
+
+/*-----------------------------------------------------------------------------------------------*/
+
+// Onload, make all links that need to trigger a lightbox active
+function initialize(){
+ addLightboxMarkup();
+ lbox = document.getElementsByClassName('lbOn');
+ for(i = 0; i < lbox.length; i++) {
+ valid = new lightbox(lbox[i]);
+ }
+}
+
+// Add in markup necessary to make this work. Basically two divs:
+// Overlay holds the shadow
+// Lightbox is the centered square that the content is put into.
+function addLightboxMarkup() {
+ bod = document.getElementsByTagName('body')[0];
+ overlay = document.createElement('div');
+ overlay.id = 'overlay';
+ lb = document.createElement('div');
+ lb.id = 'lightbox';
+ lb.className = 'loading';
+ lb.innerHTML = '';
+ bod.appendChild(overlay);
+ bod.appendChild(lb);
+}
\ No newline at end of file
diff --git a/public/stylesheets/lightbox.css b/public/stylesheets/lightbox.css
new file mode 100644
index 0000000..56c5d0f
--- /dev/null
+++ b/public/stylesheets/lightbox.css
@@ -0,0 +1,62 @@
+/* - - - - - - - - - - - - - - - - - - - - -
+
+Title : Lightbox CSS
+Author : Kevin Hale
+URL : http://particletree.com/features/lightbox-gone-wild/
+
+Created : January 13, 2006
+Modified : February 1, 2006
+
+- - - - - - - - - - - - - - - - - - - - - */
+
+#lightbox{
+ display:none;
+ position: absolute;
+ top:50%;
+ left:50%;
+ z-index:9999;
+ width:500px;
+ height:400px;
+ margin:-220px 0 0 -250px;
+ border:1px solid #fff;
+ background:#FDFCE9;
+ text-align:left;
+}
+#lightbox[id]{
+ position:fixed;
+}
+
+#overlay{
+ display:none;
+ position:absolute;
+ top:0;
+ left:0;
+ width:100%;
+ height:100%;
+ z-index:5000;
+ background-color:#000;
+ -moz-opacity: 0.8;
+ opacity:.80;
+ filter: alpha(opacity=80);
+}
+#overlay[id]{
+ position:fixed;
+}
+
+#lightbox.done #lbLoadMessage{
+ display:none;
+}
+#lightbox.done #lbContent{
+ display:block;
+}
+#lightbox.loading #lbContent{
+ display:none;
+}
+#lightbox.loading #lbLoadMessage{
+ display:block;
+}
+
+#lightbox.done img{
+ width:100%;
+ height:100%;
+}
\ No newline at end of file
diff --git a/test/unit/lightbox_helper_text.rb b/test/unit/lightbox_helper_text.rb
new file mode 100644
index 0000000..9085a5d
--- /dev/null
+++ b/test/unit/lightbox_helper_text.rb
@@ -0,0 +1,41 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class LightboxHelperTest < Test::Unit::TestCase
+
+ include LightboxHelper
+
+ should 'include lightbox properly' do
+ expects(:stylesheet_link_tag).with('lightbox').returns('[lightbox.css]')
+ expects(:javascript_include_tag).with('lightbox').returns('[lightbox.js]')
+ assert_equal '[lightbox.css][lightbox.js]', include_lightbox_header
+ end
+
+ should 'provide the needed files' do
+ assert File.exists?(File.join(RAILS_ROOT, 'public', 'stylesheets', 'lightbox.css')), 'lightbox.css expected to be in public/stylesheets, but not found'
+ assert File.exists?(File.join(RAILS_ROOT, 'public', 'javascripts', 'lightbox.js')), 'lightbox.js expected to be in public/javascripts, but not found'
+ end
+
+ should 'provide lightbox_link_to helper' do
+ expects(:link_to).with('text', { :action => 'view', :id => '1' }, { :class => 'lbOn', :id => 'my-link' }).returns('[link]')
+ assert_equal '[link]', lightbox_link_to('text', { :action => 'view', :id => '1'}, { :id => 'my-link' })
+ end
+
+ should 'merge existing :class option in lightbox_link_to' do
+ expects(:link_to).with('text', { :action => 'view', :id => '1' }, { :class => 'lbOn my-button', :id => 'my-link' }).returns('[link]')
+ assert_equal '[link]', lightbox_link_to('text', { :action => 'view', :id => '1'}, { :class => 'my-button', :id => 'my-link' })
+
+ end
+
+ should 'provide link to close lightbox' do
+ expects(:link_to).with('text', '#', { :class => 'lbAction', :rel => 'deactivate', :id => 'my-id' }).returns('[close-lightbox]')
+
+ assert_equal '[close-lightbox]', lightbox_close('text', :id => 'my-id')
+ end
+
+ should 'merge existing :class option in lightbox_close' do
+ expects(:link_to).with('text', '#', { :class => 'lbAction my-class', :rel => 'deactivate', :id => 'my-id' }).returns('[close-lightbox]')
+
+ assert_equal '[close-lightbox]', lightbox_close('text', :class => 'my-class', :id => 'my-id' )
+ end
+
+end
--
libgit2 0.21.2