Permalink
Browse files

Changes the names of all jQuery functions for a more consistent and p…

…redicable API while placing them inside the ninjaui namespace. Also optimizes Ruby packaging.
  • Loading branch information...
1 parent 0198484 commit 21d5a0c3f4d60233d4dc65be61f12c3864a2dd87 Jamie Hoover committed Aug 23, 2010
View
@@ -2,6 +2,7 @@
# encoding: UTF-8
require 'fileutils'
+require 'pathname'
require 'sass'
require 'sprockets'
@@ -18,55 +19,62 @@ def application
class Application
def install
- lib = File.dirname(__FILE__) + '/ninjaui'
- lib_javascripts = "#{lib}/javascripts"
- lib_stylesheets = "#{lib}/stylesheets"
-
- public = 'public/ninjaui'
- public_images = "#{public}/images"
- public_javascripts = "#{public}/javascripts"
- public_stylesheets = "#{public}/stylesheets"
- public_scss = "#{public}/webjutsu.scss"
+ public_images = public_root + 'images'
+ public_javascripts = public_root + 'javascripts'
+ public_stylesheets = public_root + 'stylesheets'
# Remove outdated files
FileUtils.rm_rf public_images unless !File.exists?(public_images)
FileUtils.rm_rf public_javascripts unless !File.exists?(public_javascripts)
FileUtils.rm_rf public_stylesheets unless !File.exists?(public_stylesheets)
- # Create ninjaui directories under public
+ # Create directories under public
FileUtils.mkdir_p public_images
FileUtils.mkdir_p public_javascripts
FileUtils.mkdir_p public_stylesheets
- # Copy webjutsu.scss to ninjaui directory to allow user customization
- FileUtils.cp("#{lib_stylesheets}/webjutsu.scss", public_scss) unless File.exist?(public_scss)
+ # Copy webjutsu.scss to public directory to allow user customization
+ private_webjutsu = private_root + 'stylesheets/webjutsu.scss'
+ public_webjutsu = public_root + 'webjutsu.scss'
+ FileUtils.cp(private_webjutsu, public_webjutsu) unless File.exist?(public_webjutsu)
- # Compile scss sources to file under assets
- FileUtils.mkdir_p "#{lib}/assets/stylesheets"
- File.open("#{lib}/assets/stylesheets/ninjaui.css", 'w+:UTF-8') do |stylesheet|
+ # Compile SCSS sources to file under assets
+ File.open(public_stylesheets + 'ninjaui.css', 'w+:UTF-8') do |stylesheet|
stylesheet.write Sass::Engine.new(
- File.read(public_scss),
+ File.read(public_webjutsu),
:cache => false,
- :load_paths => [lib_stylesheets],
+ :load_paths => [private_root + 'stylesheets'],
:style => :compressed,
:syntax => :scss
).render
end
- # Compile javascript sources to file under public
+ # Compile JavaScript sources to file under public
+ private_javascript = private_root + 'javascripts/jquery.ninjaui.core.js'
+ public_javascript = public_javascripts + 'jquery.ninjaui.js'
javascript = Sprockets::Secretary.new(
- :asset_root => public,
- :source_files => ["#{lib_javascripts}/jquery.ninjaui.core.js"]
+ :asset_root => public_root.to_s,
+ :source_files => [private_javascript.to_s]
)
- javascript.concatenation.save_to("#{public_javascripts}/jquery.ninjaui.js")
+ javascript.concatenation.save_to(public_javascript.to_s)
- # Copy compiled css and images from assets to public
+ # Copy compiled CSS and images from assets to public
javascript.install_assets
- puts "Ninja ui can be found here: #{public}"
+ puts "Ninja ui can be found here: #{public_root}"
end
-
+
+ private
+
+ def private_root
+ Pathname.new(__FILE__).parent + 'ninjaui'
+ end
+
+ def public_root
+ Pathname.new 'public/ninjaui'
+ end
+
end
end
@@ -14,7 +14,42 @@
//= require "jquery.ui.draggable"
//= provide "../assets"
(function($){
-$.nui = {};
+ var config = {};
+ var global = {
+ selected:'',
+ selector:''
+ };
+ var init = $.prototype.init;
+ $.prototype.init = function(selector, context){
+ var r = init.apply(this, arguments);
+ if(selector && selector.selector){
+ r.context = selector.context;
+ r.selector = selector.selector;
+ }
+ if(typeof selector == 'string'){
+ r.context = context || document;
+ r.selector = selector;
+ global.selector = r.selector;
+ }
+ global.selected = r;
+ return r;
+ };
+ $.prototype.init.prototype = $.prototype;
+ $.fn.ninjaui = {
+ config:function(args){
+ setConfig($.extend({
+ 'default':'value'
+ }, args));
+ return(getConfig());
+ }
+ };
+ function setConfig(value){
+ config = value;
+ }
+ function getConfig(){
+ return config;
+ }
+ $.ninjaui = {};
//= require "jquery.ninjaui.drawers"
//= require "jquery.ninjaui.filmstrip"
//= require "jquery.ninjaui.folders"
@@ -1,4 +1,4 @@
-$.extend($.nui, {
+$.extend($.ninjaui, {
drawerClose: function(drawer){
var handle = $(drawer).prev('.nui-drawer-handle');
var icon = $('.nui-icon', handle);
@@ -16,38 +16,41 @@ $.extend($.nui, {
},
drawersClose: function(drawers){
$.each(drawers, function(i, drawer) {
- $.nui.drawerClose(drawer);
+ $.ninjaui.drawerClose(drawer);
});
},
drawersOpen: function(drawers){
$.each(drawers, function(i, drawer) {
- $.nui.drawerOpen(drawer);
+ $.ninjaui.drawerOpen(drawer);
});
}
});
-$.fn.nuiDrawers = function(customOptions) {
- var options = $.extend({}, customOptions);
- return this.each(function(i, drawers) {
- $(drawers).children('div').each(function(i, newDrawer) {
- $(newDrawer).addClass('nui-drawer');
- });
- $(drawers).addClass('nui nui-drawers');
- $('.nui-drawer:last', drawers).addClass('nui-last');
- $('.nui-drawer', drawers).each(function(i, drawer) {
- $(drawer).before('<div class="nui-drawer-handle"><span class="nui-icon nui-icon-right"></span> ' + $(drawer).attr('title') + '</div>');
- var handle = $(drawer).prev('.nui-drawer-handle');
- $(handle).toggleClass('nui-last', $(drawer).is('.nui-last'));
- $(drawer).hide();
- $(handle).click(function() {
- if($(handle).hasClass('nui-active')) {
- $.nui.drawerClose(drawer);
- }
- else {
- $.nui.drawerOpen(drawer);
- }
+$.extend($.fn.ninjaui, {
+ drawersCreate: function(customOptions){
+ var config = getConfig();
+ var options = $.extend({}, customOptions);
+ return global.selected.each(function(i, drawers) {
+ $(drawers).children('div').each(function(i, newDrawer) {
+ $(newDrawer).addClass('nui-drawer');
+ });
+ $(drawers).addClass('nui nui-drawers');
+ $('.nui-drawer:last', drawers).addClass('nui-last');
+ $('.nui-drawer', drawers).each(function(i, drawer) {
+ $(drawer).before('<div class="nui-drawer-handle"><span class="nui-icon nui-icon-right"></span> ' + $(drawer).attr('title') + '</div>');
+ var handle = $(drawer).prev('.nui-drawer-handle');
+ $(handle).toggleClass('nui-last', $(drawer).is('.nui-last'));
+ $(drawer).hide();
+ $(handle).click(function() {
+ if($(handle).hasClass('nui-active')) {
+ $.ninjaui.drawerClose(drawer);
+ }
+ else {
+ $.ninjaui.drawerOpen(drawer);
+ }
+ });
});
+ $('.nui-drawer-handle:first-child', drawers).addClass('nui-first');
});
- $('.nui-drawer-handle:first-child', drawers).addClass('nui-first');
- });
-};
+ }
+});
@@ -1,59 +1,62 @@
-$.fn.nuiFilmstrip = function(customOptions) {
- var options = $.extend({
- frameHeight:100,
- frameWidth:100,
- seconds:0,
- show:3,
- title:''
- }, customOptions);
- return this.each(function (i, filmstrip) {
- $(filmstrip).addClass('nui-filmstrip');
- var frameArray = $(filmstrip).find('> span');
- $(frameArray).wrapAll('<span class="nui-view"><span class="nui-reel"/></span>').each(function (i, frame) {
- $(frame).addClass('nui-frame').css({height:options.frameHeight,width:options.frameWidth});
- });
- var view = $(filmstrip).find('> .nui-view');
- var reel = $(view).find('> .nui-reel');
- var frameOuterHeight = options.frameHeight + 10;
- var frameOuterWidth = options.frameWidth + 11;
- $(reel).height(frameOuterHeight + 'px');
- $(view).height(frameOuterHeight + 'px').width((frameOuterWidth * options.show) - 1 + 'px');
- var pages = Math.ceil($(frameArray).length / options.show);
- var currentPage = 1;
- $(filmstrip).prepend('<div class="nui-bar"><button class="nui-button back"><span class="nui-icon nui-icon-left"></span></button>' + options.title + '<button class="nui-button forward"><span class="nui-icon nui-icon-right"></span></button></div>');
- var bar = $(filmstrip).find('> .nui-bar');
- $(bar).width((frameOuterWidth * options.show) - 1 + 'px');
- $('button.back', filmstrip).click(function () {
- if(currentPage == 1){
- $(reel).animate({left: '-=' + (frameOuterWidth * options.show * (pages -1))});
- currentPage = pages;
- }
- else {
- $(reel).animate({left: '+=' + (frameOuterWidth * options.show)});
- --currentPage;
- }
- });
- $('button.forward', filmstrip).click(function () {
- if(currentPage == pages){
- $(reel).animate({left:0});
- currentPage = 1;
- }
- else{
- $(reel).animate({left: '-=' + (frameOuterWidth * options.show)});
- ++currentPage;
+$.extend($.fn.ninjaui, {
+ filmstripCreate:function(customOptions) {
+ var config = getConfig();
+ var options = $.extend({
+ frameHeight:100,
+ frameWidth:100,
+ seconds:0,
+ show:3,
+ title:''
+ }, customOptions);
+ return global.selected.each(function (i, filmstrip) {
+ $(filmstrip).addClass('nui-filmstrip');
+ var frameArray = $(filmstrip).find('> span');
+ $(frameArray).wrapAll('<span class="nui-view"><span class="nui-reel"/></span>').each(function (i, frame) {
+ $(frame).addClass('nui-frame').css({height:options.frameHeight,width:options.frameWidth});
+ });
+ var view = $(filmstrip).find('> .nui-view');
+ var reel = $(view).find('> .nui-reel');
+ var frameOuterHeight = options.frameHeight + 10;
+ var frameOuterWidth = options.frameWidth + 11;
+ $(reel).height(frameOuterHeight + 'px');
+ $(view).height(frameOuterHeight + 'px').width((frameOuterWidth * options.show) - 1 + 'px');
+ var pages = Math.ceil($(frameArray).length / options.show);
+ var currentPage = 1;
+ $(filmstrip).prepend('<div class="nui-bar"><button class="nui-button back"><span class="nui-icon nui-icon-left"></span></button>' + options.title + '<button class="nui-button forward"><span class="nui-icon nui-icon-right"></span></button></div>');
+ var bar = $(filmstrip).find('> .nui-bar');
+ $(bar).width((frameOuterWidth * options.show) - 1 + 'px');
+ $('button.back', filmstrip).click(function () {
+ if(currentPage == 1){
+ $(reel).animate({left: '-=' + (frameOuterWidth * options.show * (pages -1))});
+ currentPage = pages;
+ }
+ else {
+ $(reel).animate({left: '+=' + (frameOuterWidth * options.show)});
+ --currentPage;
+ }
+ });
+ $('button.forward', filmstrip).click(function () {
+ if(currentPage == pages){
+ $(reel).animate({left:0});
+ currentPage = 1;
+ }
+ else{
+ $(reel).animate({left: '-=' + (frameOuterWidth * options.show)});
+ ++currentPage;
+ }
+ });
+ if(options.seconds > 0) {
+ var milliseconds = options.seconds * 1000;
+ var page = 0;
+ (function advance() {
+ setTimeout(function() {
+ if (page++ < pages) {
+ $('button.forward', filmstrip).click();
+ advance();
+ }
+ }, milliseconds);
+ })();
}
});
- if(options.seconds > 0) {
- var milliseconds = options.seconds * 1000;
- var page = 0;
- (function advance() {
- setTimeout(function() {
- if (page++ < pages) {
- $('button.forward', filmstrip).click();
- advance();
- }
- }, milliseconds);
- })();
- }
- });
-};
+ }
+});
@@ -1,5 +1,5 @@
-$.extend($.nui, {
- folderToggle: function(position, folders){
+$.extend($.ninjaui, {
+ foldersToggle: function(position, folders){
var tabs = $('.nui-tabs', folders);
$('.nui-tab', tabs).each(function(i, tab) {
if(i == position) {
@@ -20,28 +20,31 @@ $.extend($.nui, {
}
});
-$.fn.nuiFolders = function(customOptions) {
- var options = $.extend({direction:'horizontal'}, customOptions);
- return this.each(function(i, folders) {
- $(folders).children('div').each(function(i, folder) {
- $(folder).addClass('nui-folder');
- });
- $(folders).addClass('nui nui-folders nui-' + options.direction).prepend('<div class="nui-tabs"></div>');
- var tabs = $('.nui-tabs', folders);
- var folderArray = $('.nui-folder', folders);
- $(folderArray).each(function(i, folder) {
- $(tabs).append('<span class="nui-tab">' + $(folder).attr('title') + '</span>')
- });
- $('.nui-tab:first-child', tabs).addClass('nui-first');
- $('.nui-tab:last-child', tabs).addClass('nui-last');
- $(folderArray).each(function(i, folder) {
- $(folder).css('min-height', $(tabs).height());
- });
- $('.nui-tab', tabs).each(function(i, tab) {
- $(tab).click(function() {
- $.nui.folderToggle(i, folders);
+$.extend($.fn.ninjaui, {
+ foldersCreate:function(customOptions) {
+ var config = getConfig();
+ var options = $.extend({direction:'horizontal'}, customOptions);
+ return global.selected.each(function(i, folders) {
+ $(folders).children('div').each(function(i, folder) {
+ $(folder).addClass('nui-folder');
});
+ $(folders).addClass('nui nui-folders nui-' + options.direction).prepend('<div class="nui-tabs"></div>');
+ var tabs = $('.nui-tabs', folders);
+ var folderArray = $('.nui-folder', folders);
+ $(folderArray).each(function(i, folder) {
+ $(tabs).append('<span class="nui-tab">' + $(folder).attr('title') + '</span>');
+ });
+ $('.nui-tab:first-child', tabs).addClass('nui-first');
+ $('.nui-tab:last-child', tabs).addClass('nui-last');
+ $(folderArray).each(function(i, folder) {
+ $(folder).css('min-height', $(tabs).height());
+ });
+ $('.nui-tab', tabs).each(function(i, tab) {
+ $(tab).click(function() {
+ $.ninjaui.foldersToggle(i, folders);
+ });
+ });
+ $.ninjaui.foldersToggle(0, folders);
});
- $.nui.folderToggle(0, folders);
- });
-};
+ }
+});
Oops, something went wrong.

0 comments on commit 21d5a0c

Please sign in to comment.