diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index bd4eade3..6a02b580 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -17,6 +17,7 @@
//= require modernizr.custom.15012
//= require jquery.sortChildren
//= require bootstrap-sprockets
+//= require jquery-migrate-1.1.1
//= require_tree .
//
( function($){
@@ -170,79 +171,6 @@
}
});
},
- observeTagCloudControls: function(){
- var sort_tags_on_change = function(e){
- var sort_by = $('#sort-tags-by').val();
- var sort = $("#sort-tags-direction").val();
- var mapping_function = function(elem) {
- var tag_frequency = $(elem).find('.tag').data('tag-frequency'),
- tag_text = $(elem).find('.tag').data('tag-name'),
- attributes = {};
-
- attributes.frequency = tag_frequency;
- attributes.name = tag_text.toString();
-
- return attributes;
- };
- var compare_function = function(a,b) {
- if(sort_by == "frequency" && sort == "desc") {
- return (b.value.frequency - a.value.frequency) || (b.value.frequency === a.value.frequency && a.value.name.localeCompare(b.value.name));
- }
- else if(sort_by == "frequency" && sort == "asc") {
- return (a.value.frequency - b.value.frequency) || (b.value.frequency === a.value.frequency && a.value.name.localeCompare(b.value.name));
- }
- else if(sort_by == "alpha" && sort == "asc") {
- return a.value.name.localeCompare(b.value.name);
- }
- else if(sort_by == "alpha" && sort == "desc") {
- return b.value.name.localeCompare(a.value.name);
- }
- else {
- return null;
- }
- };
- $("#tag-cloud").detach(function() {
- $(this).sortChildren(mapping_function, compare_function);
- });
- };
- $('#sort-tags-by').change(sort_tags_on_change);
- $('#sort-tags-direction').change(sort_tags_on_change);
-
- $('#reset-filter').click(function(e){
- $('#tag-cloud li').show();
- $('#filter-by').val('');
- });
-
- var filterStuff = function(e){
- if(e != ''){
- e.preventDefault();
- }
- $('#tag-cloud li').show();
- var filterVal = $('#filter-by').val();
- var filterregex = new RegExp(filterVal,'i');
- $('#tag-cloud li').each(function(){
- if(! $(this).find('.tag').html().match(filterregex)){
- $(this).hide();
- }
- });
- };
-
- $('#filter-button').click(filterStuff);
- $('#filter-by').observe_field(1,filterStuff);
-
- $('#tag_slider').slider({
- value: 0,
- min: 0,
- max: 9,
- step: 1,
- slide: function(event, ui){
- $('.tag').show();
- for(var i = 1; i <= ui.value; i=i+1){
- $('.s' + i).hide();
- }
- }
- });
- },
initEditor: function(textArea){
CKEDITOR.replace(textArea);
},
diff --git a/app/assets/javascripts/hubs/tags-filter.js b/app/assets/javascripts/hubs/tags-filter.js
new file mode 100644
index 00000000..60638c5e
--- /dev/null
+++ b/app/assets/javascripts/hubs/tags-filter.js
@@ -0,0 +1,27 @@
+/* globals $ */
+this.observeTagFilterControls = function () {
+ $('#reset-filter').click(function (e) {
+ $('#tag-cloud li').show()
+ $('#filter-by').val('')
+ })
+
+ var filterStuff = function (e) {
+ if (e !== '') {
+ e.preventDefault()
+ }
+
+ $('#tag-cloud li').show()
+
+ var filterVal = $('#filter-by').val()
+ var filterregex = new RegExp(filterVal, 'i')
+
+ $('#tag-cloud li').each(function () {
+ if (!$(this).find('.tag').html().match(filterregex)) {
+ $(this).hide()
+ }
+ })
+ }
+
+ $('#filter-button').click(filterStuff)
+ $('#filter-by').observe_field(1, filterStuff)
+}
diff --git a/app/assets/javascripts/hubs/tags-sort.js b/app/assets/javascripts/hubs/tags-sort.js
new file mode 100644
index 00000000..bfdee44f
--- /dev/null
+++ b/app/assets/javascripts/hubs/tags-sort.js
@@ -0,0 +1,37 @@
+/* globals $ */
+this.observeTagSortControls = function () {
+ var sortTagsOnChange = function (e) {
+ var sortBy = $('#sort-tags-by').val()
+ var sort = $('#sort-tags-direction').val()
+
+ var mappingFunction = function (elem) {
+ var attributes = {}
+
+ attributes.frequency = $(elem).find('.tag').data('tag-frequency')
+ attributes.name = $(elem).find('.tag').data('tag-name').toString()
+
+ return attributes
+ }
+
+ var compareFunction = function (a, b) {
+ if (sortBy === 'frequency' && sort === 'desc') {
+ return (b.value.frequency - a.value.frequency) || (b.value.frequency === a.value.frequency && a.value.name.localeCompare(b.value.name))
+ } else if (sortBy === 'frequency' && sort === 'asc') {
+ return (a.value.frequency - b.value.frequency) || (b.value.frequency === a.value.frequency && a.value.name.localeCompare(b.value.name))
+ } else if (sortBy === 'alpha' && sort === 'asc') {
+ return a.value.name.localeCompare(b.value.name)
+ } else if (sortBy === 'alpha' && sort === 'desc') {
+ return b.value.name.localeCompare(a.value.name)
+ } else {
+ return null
+ }
+ }
+
+ $('#tag-cloud').detach(function () {
+ $(this).sortChildren(mappingFunction, compareFunction)
+ })
+ }
+
+ $('#sort-tags-by').change(sortTagsOnChange)
+ $('#sort-tags-direction').change(sortTagsOnChange)
+}
diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml
index b0a882b0..e5951338 100644
--- a/app/views/layouts/application.html.haml
+++ b/app/views/layouts/application.html.haml
@@ -6,7 +6,6 @@
= stylesheet_link_tag 'application', media: 'all'
= javascript_include_tag 'application'
= csrf_meta_tag
- %script{ src: 'http://code.jquery.com/jquery-migrate-1.1.1.js' }
%link{ href: "#{root_url}humans.txt", rel: 'author' }
%link{ href: asset_path('favicon.png'), rel: 'icon', type: 'image/png' }
- unless @show_auto_discovery_params.blank?
diff --git a/app/views/tags/index.html.haml b/app/views/tags/index.html.haml
index 3d17866d..6a86a872 100644
--- a/app/views/tags/index.html.haml
+++ b/app/views/tags/index.html.haml
@@ -29,4 +29,9 @@
= render partial: 'tags/graph_item', as: :tag, collection: @tags,
locals: { hub: @hub, hub_feed: @hub_feed, max_count: @tags.empty? ? 0 : @tags.first.count }
:javascript
- $(document).ready(function(){$.observeTagCloudControls()});
+ $(document).ready(
+ function () {
+ observeTagFilterControls()
+ observeTagSortControls()
+ }
+ );
diff --git a/vendor/assets/javascripts/jquery-migrate-1.1.1.js b/vendor/assets/javascripts/jquery-migrate-1.1.1.js
new file mode 100644
index 00000000..942cb8b4
--- /dev/null
+++ b/vendor/assets/javascripts/jquery-migrate-1.1.1.js
@@ -0,0 +1,511 @@
+/*!
+ * jQuery Migrate - v1.1.1 - 2013-02-16
+ * https://github.com/jquery/jquery-migrate
+ * Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors; Licensed MIT
+ */
+(function( jQuery, window, undefined ) {
+// See http://bugs.jquery.com/ticket/13335
+// "use strict";
+
+
+var warnedAbout = {};
+
+// List of warnings already given; public read only
+jQuery.migrateWarnings = [];
+
+// Set to true to prevent console output; migrateWarnings still maintained
+// jQuery.migrateMute = false;
+
+// Show a message on the console so devs know we're active
+if ( !jQuery.migrateMute && window.console && console.log ) {
+ console.log("JQMIGRATE: Logging is active");
+}
+
+// Set to false to disable traces that appear with warnings
+if ( jQuery.migrateTrace === undefined ) {
+ jQuery.migrateTrace = true;
+}
+
+// Forget any warnings we've already given; public
+jQuery.migrateReset = function() {
+ warnedAbout = {};
+ jQuery.migrateWarnings.length = 0;
+};
+
+function migrateWarn( msg) {
+ if ( !warnedAbout[ msg ] ) {
+ warnedAbout[ msg ] = true;
+ jQuery.migrateWarnings.push( msg );
+ if ( window.console && console.warn && !jQuery.migrateMute ) {
+ console.warn( "JQMIGRATE: " + msg );
+ if ( jQuery.migrateTrace && console.trace ) {
+ console.trace();
+ }
+ }
+ }
+}
+
+function migrateWarnProp( obj, prop, value, msg ) {
+ if ( Object.defineProperty ) {
+ // On ES5 browsers (non-oldIE), warn if the code tries to get prop;
+ // allow property to be overwritten in case some other plugin wants it
+ try {
+ Object.defineProperty( obj, prop, {
+ configurable: true,
+ enumerable: true,
+ get: function() {
+ migrateWarn( msg );
+ return value;
+ },
+ set: function( newValue ) {
+ migrateWarn( msg );
+ value = newValue;
+ }
+ });
+ return;
+ } catch( err ) {
+ // IE8 is a dope about Object.defineProperty, can't warn there
+ }
+ }
+
+ // Non-ES5 (or broken) browser; just set the property
+ jQuery._definePropertyBroken = true;
+ obj[ prop ] = value;
+}
+
+if ( document.compatMode === "BackCompat" ) {
+ // jQuery has never supported or tested Quirks Mode
+ migrateWarn( "jQuery is not compatible with Quirks Mode" );
+}
+
+
+var attrFn = jQuery( "", { size: 1 } ).attr("size") && jQuery.attrFn,
+ oldAttr = jQuery.attr,
+ valueAttrGet = jQuery.attrHooks.value && jQuery.attrHooks.value.get ||
+ function() { return null; },
+ valueAttrSet = jQuery.attrHooks.value && jQuery.attrHooks.value.set ||
+ function() { return undefined; },
+ rnoType = /^(?:input|button)$/i,
+ rnoAttrNodeType = /^[238]$/,
+ rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
+ ruseDefault = /^(?:checked|selected)$/i;
+
+// jQuery.attrFn
+migrateWarnProp( jQuery, "attrFn", attrFn || {}, "jQuery.attrFn is deprecated" );
+
+jQuery.attr = function( elem, name, value, pass ) {
+ var lowerName = name.toLowerCase(),
+ nType = elem && elem.nodeType;
+
+ if ( pass ) {
+ // Since pass is used internally, we only warn for new jQuery
+ // versions where there isn't a pass arg in the formal params
+ if ( oldAttr.length < 4 ) {
+ migrateWarn("jQuery.fn.attr( props, pass ) is deprecated");
+ }
+ if ( elem && !rnoAttrNodeType.test( nType ) &&
+ (attrFn ? name in attrFn : jQuery.isFunction(jQuery.fn[name])) ) {
+ return jQuery( elem )[ name ]( value );
+ }
+ }
+
+ // Warn if user tries to set `type`, since it breaks on IE 6/7/8; by checking
+ // for disconnected elements we don't warn on $( "