From fe1c57b458ce6fb04b1821e098f7f304b1f47a6b Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 8 Oct 2016 16:42:34 +0800 Subject: [PATCH] further updates - make Enter update bip fields whaaat --- app/assets/javascripts/lib/jquery.purr.js | 180 ---------------------- app/assets/stylesheets/base.css.erb | 1 + frontend/src/Metamaps/Map/InfoBox.js | 7 + frontend/src/Metamaps/SynapseCard.js | 6 + frontend/src/Metamaps/TopicCard.js | 13 ++ 5 files changed, 27 insertions(+), 180 deletions(-) delete mode 100644 app/assets/javascripts/lib/jquery.purr.js diff --git a/app/assets/javascripts/lib/jquery.purr.js b/app/assets/javascripts/lib/jquery.purr.js deleted file mode 100644 index 1972165b..00000000 --- a/app/assets/javascripts/lib/jquery.purr.js +++ /dev/null @@ -1,180 +0,0 @@ -/** - * jquery.purr.js - * Copyright (c) 2008 Net Perspective (net-perspective.com) - * Licensed under the MIT License (http://www.opensource.org/licenses/mit-license.php) - * - * @author R.A. Ray - * @projectDescription jQuery plugin for dynamically displaying unobtrusive messages in the browser. Mimics the behavior of the MacOS program "Growl." - * @version 0.1.0 - * - * @requires jquery.js (tested with 1.2.6) - * - * @param fadeInSpeed int - Duration of fade in animation in miliseconds - * default: 500 - * @param fadeOutSpeed int - Duration of fade out animationin miliseconds - default: 500 - * @param removeTimer int - Timeout, in miliseconds, before notice is removed once it is the top non-sticky notice in the list - default: 4000 - * @param isSticky bool - Whether the notice should fade out on its own or wait to be manually closed - default: false - * @param usingTransparentPNG bool - Whether or not the notice is using transparent .png images in its styling - default: false - */ - -( function( $ ) { - - $.purr = function ( notice, options ) - { - // Convert notice to a jQuery object - notice = $( notice ); - - // Add a class to denote the notice as not sticky - if ( !options.isSticky ) - { - notice.addClass( 'not-sticky' ); - }; - - // Get the container element from the page - var cont = document.getElementById( 'purr-container' ); - - // If the container doesn't yet exist, we need to create it - if ( !cont ) - { - cont = '
'; - } - - // Convert cont to a jQuery object - cont = $( cont ); - - // Add the container to the page - $( 'body' ).append( cont ); - - notify(); - - function notify () - { - // Set up the close button - var close = document.createElement( 'a' ); - $( close ).attr( - { - className: 'close', - href: '#close', - innerHTML: 'Close' - } - ) - .appendTo( notice ) - .click( function () - { - removeNotice(); - - return false; - } - ); - - // Add the notice to the page and keep it hidden initially - notice.appendTo( cont ) - .hide(); - - if ( jQuery.browser.msie && options.usingTransparentPNG ) - { - // IE7 and earlier can't handle the combination of opacity and transparent pngs, so if we're using transparent pngs in our - // notice style, we'll just skip the fading in. - notice.show(); - } - else - { - //Fade in the notice we just added - notice.fadeIn( options.fadeInSpeed ); - } - - // Set up the removal interval for the added notice if that notice is not a sticky - if ( !options.isSticky ) - { - var topSpotInt = setInterval( function () - { - // Check to see if our notice is the first non-sticky notice in the list - if ( notice.prevAll( '.not-sticky' ).length == 0 ) - { - // Stop checking once the condition is met - clearInterval( topSpotInt ); - - // Call the close action after the timeout set in options - setTimeout( function () - { - removeNotice(); - }, options.removeTimer - ); - } - }, 200 ); - } - } - - function removeNotice () - { - // IE7 and earlier can't handle the combination of opacity and transparent pngs, so if we're using transparent pngs in our - // notice style, we'll just skip the fading out. - if ( jQuery.browser.msie && options.usingTransparentPNG ) - { - notice.css( { opacity: 0 } ) - .animate( - { - height: '0px' - }, - { - duration: options.fadeOutSpeed, - complete: function () - { - notice.remove(); - } - } - ); - } - else - { - // Fade the object out before reducing its height to produce the sliding effect - notice.animate( - { - opacity: '0' - }, - { - duration: options.fadeOutSpeed, - complete: function () - { - notice.animate( - { - height: '0px' - }, - { - duration: options.fadeOutSpeed, - complete: function () - { - notice.remove(); - } - } - ); - } - } - ); - } - }; - }; - - $.fn.purr = function ( options ) - { - options = options || {}; - options.fadeInSpeed = options.fadeInSpeed || 500; - options.fadeOutSpeed = options.fadeOutSpeed || 500; - options.removeTimer = options.removeTimer || 4000; - options.isSticky = options.isSticky || false; - options.usingTransparentPNG = options.usingTransparentPNG || false; - - this.each( function() - { - new $.purr( this, options ); - } - ); - - return this; - }; -})( jQuery ); - diff --git a/app/assets/stylesheets/base.css.erb b/app/assets/stylesheets/base.css.erb index 1e5d68e8..6cfb6b57 100644 --- a/app/assets/stylesheets/base.css.erb +++ b/app/assets/stylesheets/base.css.erb @@ -143,6 +143,7 @@ margin-top:5px; } +.CardOnGraph .desc ol, .CardOnGraph .desc ul { margin-left: 1em; diff --git a/frontend/src/Metamaps/Map/InfoBox.js b/frontend/src/Metamaps/Map/InfoBox.js index ddfd72c3..79fa6c4d 100644 --- a/frontend/src/Metamaps/Map/InfoBox.js +++ b/frontend/src/Metamaps/Map/InfoBox.js @@ -173,6 +173,13 @@ const InfoBox = { Active.Map.trigger('saved') }) + $('.mapInfoDesc .best_in_place_desc, .mapInfoName .best_in_place_name').unbind('keypress').keypress(function(e) { + const ENTER = 13 + if (e.which === ENTER) { + $(this).data('bestInPlaceEditor').update() + } + }) + $('.yourMap .mapPermission').unbind().click(self.onPermissionClick) // .yourMap in the unbind/bind is just a namespace for the events // not a reference to the class .yourMap on the .mapInfoBox diff --git a/frontend/src/Metamaps/SynapseCard.js b/frontend/src/Metamaps/SynapseCard.js index b1810dac..303b98cf 100644 --- a/frontend/src/Metamaps/SynapseCard.js +++ b/frontend/src/Metamaps/SynapseCard.js @@ -97,6 +97,12 @@ const SynapseCard = { } } + $('#edit_synapse_desc').keypress(function (e) { + const ENTER = 13 + if (e.which === ENTER) { + $(this).data('bestInPlaceEditor').update() + } + }) $('#edit_synapse_desc').bind('ajax:success', function () { var desc = $(this).html() if (desc == data_nil) { diff --git a/frontend/src/Metamaps/TopicCard.js b/frontend/src/Metamaps/TopicCard.js index f74cf18f..0956c07b 100644 --- a/frontend/src/Metamaps/TopicCard.js +++ b/frontend/src/Metamaps/TopicCard.js @@ -265,6 +265,12 @@ const TopicCard = { bipName.bind('best_in_place:deactivate', function () { $('.nameCounter.forTopic').remove() }) + bipName.keypress(function(e) { + const ENTER = 13 + if (e.which === ENTER) { // enter + $(this).data('bestInPlaceEditor').update() + } + }) // bind best_in_place ajax callbacks bipName.bind('ajax:success', function () { @@ -284,6 +290,13 @@ const TopicCard = { this.innerHTML = Util.mdToHTML(desc) topic.trigger('saved') }) + bipDesc.keypress(function(e) { + // allow typing Enter with Shift+Enter + const ENTER = 13 + if (e.shiftKey === false && e.which === ENTER) { + $(this).data('bestInPlaceEditor').update() + } + }) } var permissionLiClick = function (event) {