From 16ef39ef130acaa84679fec9437abce15e35a3ad Mon Sep 17 00:00:00 2001 From: William Panting Date: Fri, 27 Sep 2013 10:51:23 -0300 Subject: [PATCH 1/6] spinny goodness --- includes/ingest.form.inc | 6 +++++ js/ingesting_object.js | 47 ++++++++++++++++++++++++++++++++++++++++ js/spin/LICENSE.txt | 21 ++++++++++++++++++ js/spin/README.md | 11 ++++++++++ js/spin/spin.min.js | 1 + 5 files changed, 86 insertions(+) create mode 100755 js/ingesting_object.js create mode 100644 js/spin/LICENSE.txt create mode 100755 js/spin/README.md create mode 100644 js/spin/spin.min.js diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 7edd0f60..2d27905c 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -693,6 +693,12 @@ function islandora_ingest_form_ingest_button(array &$form_state) { $validate = function_exists($validate_callback) ? array($validate_callback) : NULL; $submit_callback = $form_id . '_submit'; $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_submit') : array('islandora_ingest_form_submit'); + + $islandora_path = drupal_get_path('module', 'islandora'); + + drupal_add_js($islandora_path . '/js/spin/spin.min.js'); + drupal_add_js($islandora_path . '/js/ingesting_object.js'); + return array( '#type' => 'submit', '#name' => 'ingest', diff --git a/js/ingesting_object.js b/js/ingesting_object.js new file mode 100755 index 00000000..e55870d1 --- /dev/null +++ b/js/ingesting_object.js @@ -0,0 +1,47 @@ +/** + * @file + * Adds some spinny goodness user-feedback after the user clicks Ingest. + */ + +(function ($) { + function islandora_start_ingest_feedback() { + $('#islandora-ingest-form').after('
' + + Drupal.t('Please wait while the object is ingested.') + + '
'); + + var opts = { + lines: 10, + length: 20, + width: 10, + radius: 30, + corners: 1, + rotate: 0, + direction: 1, + color: '#000', + speed: 1, + trail: 60, + shadow: false, + hwaccel: false, + className: 'spinner', + zIndex: 2e9, + top: 'auto', + left: 'auto' + }; + var target = document.getElementById('islandora_is_working'); + var spinner = new Spinner(opts).spin(target); + } + + $(document).ready(function() { + // Safari is having issues with stalling JS execution that was preventing this from running. + if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) { + $('#edit-next').mousedown(function() { + islandora_start_ingest_feedback() + }); + } + else { + $('#islandora-ingest-form').submit(function() { + islandora_start_ingest_feedback() + }); + } + }); +})(jQuery); diff --git a/js/spin/LICENSE.txt b/js/spin/LICENSE.txt new file mode 100644 index 00000000..61480614 --- /dev/null +++ b/js/spin/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2011 Felix Gnass [fgnass at neteye dot de] + +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. \ No newline at end of file diff --git a/js/spin/README.md b/js/spin/README.md new file mode 100755 index 00000000..f88c257b --- /dev/null +++ b/js/spin/README.md @@ -0,0 +1,11 @@ +CONTENTS OF THIS FILE +--------------------- + + * summary + +SUMMARY +------- + +This directory contains the spin.js library: http://fgnass.github.io/spin.js/ +downloaded from http://fgnass.github.io/spin.js/dist/spin.min.js on Sept 27th +2013. This project is under version control: https://github.com/fgnass/spin.js. diff --git a/js/spin/spin.min.js b/js/spin/spin.min.js new file mode 100644 index 00000000..d4283919 --- /dev/null +++ b/js/spin/spin.min.js @@ -0,0 +1 @@ +(function(t,e){if(typeof exports=="object")module.exports=e();else if(typeof define=="function"&&define.amd)define(e);else t.Spinner=e()})(this,function(){"use strict";var t=["webkit","Moz","ms","O"],e={},i;function o(t,e){var i=document.createElement(t||"div"),o;for(o in e)i[o]=e[o];return i}function n(t){for(var e=1,i=arguments.length;e>1):parseInt(n.left,10)+s)+"px",top:(n.top=="auto"?l.y-a.y+(t.offsetHeight>>1):parseInt(n.top,10)+s)+"px"})}r.setAttribute("role","progressbar");e.lines(r,e.opts);if(!i){var d=0,p=(n.lines-1)*(1-n.direction)/2,c,h=n.fps,m=h/n.speed,y=(1-n.opacity)/(m*n.trail/100),g=m/n.lines;(function v(){d++;for(var t=0;t>1)+"px"})}for(;r',e)}r.addRule(".spin-vml","behavior:url(#default#VML)");c.prototype.lines=function(e,i){var o=i.length+i.width,r=2*o;function s(){return f(t("group",{coordsize:r+" "+r,coordorigin:-o+" "+-o}),{width:r,height:r})}var a=-(i.width+i.length)*2+"px",l=f(s(),{position:"absolute",top:a,left:a}),u;function p(e,r,a){n(l,n(f(s(),{rotation:360/i.lines*e+"deg",left:~~r}),n(f(t("roundrect",{arcsize:i.corners}),{width:o,height:i.width,left:i.radius,top:-i.width>>1,filter:a}),t("fill",{color:d(i.color,e),opacity:i.opacity}),t("stroke",{opacity:0}))))}if(i.shadow)for(u=1;u<=i.lines;u++)p(u,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(u=1;u<=i.lines;u++)p(u);return n(e,l)};c.prototype.opacity=function(t,e,i,o){var n=t.firstChild;o=o.shadow&&o.lines||0;if(n&&e+o Date: Fri, 27 Sep 2013 10:54:22 -0300 Subject: [PATCH 2/6] license line ending for git --- js/spin/LICENSE.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/spin/LICENSE.txt b/js/spin/LICENSE.txt index 61480614..b0a7912e 100644 --- a/js/spin/LICENSE.txt +++ b/js/spin/LICENSE.txt @@ -18,4 +18,4 @@ 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. \ No newline at end of file +THE SOFTWARE. From 06a17da8f3e120dd36d0ccc893b0a2c095fee0cc Mon Sep 17 00:00:00 2001 From: William Panting Date: Fri, 27 Sep 2013 17:27:24 -0300 Subject: [PATCH 3/6] handling more user issues --- includes/ingest.form.inc | 7 ++++--- js/ingesting_object.js | 33 ++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 2d27905c..0b8546b2 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -696,10 +696,11 @@ function islandora_ingest_form_ingest_button(array &$form_state) { $islandora_path = drupal_get_path('module', 'islandora'); - drupal_add_js($islandora_path . '/js/spin/spin.min.js'); - drupal_add_js($islandora_path . '/js/ingesting_object.js'); - return array( + '#attached' => array('js' => array( + "$islandora_path/js/spin/spin.min.js", + "$islandora_path/js/ingesting_object.js", + )), '#type' => 'submit', '#name' => 'ingest', '#value' => t('Ingest'), diff --git a/js/ingesting_object.js b/js/ingesting_object.js index e55870d1..913e5be9 100755 --- a/js/ingesting_object.js +++ b/js/ingesting_object.js @@ -6,7 +6,7 @@ (function ($) { function islandora_start_ingest_feedback() { $('#islandora-ingest-form').after('
' + - Drupal.t('Please wait while the object is ingested.') + + Drupal.t('Please be patient while the the page loads.') + '
'); var opts = { @@ -29,19 +29,26 @@ }; var target = document.getElementById('islandora_is_working'); var spinner = new Spinner(opts).spin(target); + // Don't want to do this in Safari, can't submit after form errors. + if (!(navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1)) { + $('#edit-next').hide(); + $('#edit-prev').hide(); + } } - $(document).ready(function() { - // Safari is having issues with stalling JS execution that was preventing this from running. - if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) { - $('#edit-next').mousedown(function() { - islandora_start_ingest_feedback() - }); - } - else { - $('#islandora-ingest-form').submit(function() { - islandora_start_ingest_feedback() - }); + Drupal.behaviors.islandoraIngestingObject = { + attach: function(context, settings) { + // Safari is having issues with stalling JS execution that was preventing this from running. + if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) { + $('#edit-next').one('mousedown', function() { + islandora_start_ingest_feedback() + }); + } + else { + $('#islandora-ingest-form').one('submit', function() { + islandora_start_ingest_feedback() + }); + } } - }); + }; })(jQuery); From 3ba7e638c95d319d40b0a11a31819844545134c7 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Mon, 30 Sep 2013 12:32:39 +0000 Subject: [PATCH 4/6] Changed to allow for submits via pressing enter in Safari, and restructured to follow Drupal conventions. --- includes/ingest.form.inc | 44 ++++++++++++++++++++++++++------ js/ingesting_object.js | 54 ---------------------------------------- js/spinner.js | 54 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 61 deletions(-) delete mode 100755 js/ingesting_object.js create mode 100755 js/spinner.js diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 0b8546b2..c17a1806 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -693,22 +693,52 @@ function islandora_ingest_form_ingest_button(array &$form_state) { $validate = function_exists($validate_callback) ? array($validate_callback) : NULL; $submit_callback = $form_id . '_submit'; $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_submit') : array('islandora_ingest_form_submit'); - - $islandora_path = drupal_get_path('module', 'islandora'); - return array( - '#attached' => array('js' => array( - "$islandora_path/js/spin/spin.min.js", - "$islandora_path/js/ingesting_object.js", - )), '#type' => 'submit', '#name' => 'ingest', '#value' => t('Ingest'), + '#process' => array('islandora_ingest_form_ingest_button_process'), '#validate' => $validate, '#submit' => $submit, ); } +/** + * Process hook for the ingest button, adds the please wait spinning icon. + */ +function islandora_ingest_form_ingest_button_process(array $element) { + $settings['spinner'][$element['#id']] = array( + 'message' => t('Please be patient while the the page loads.'), + 'options' => array( + 'lines' => 10, + 'length' => 20, + 'width' => 10, + 'radius' => 30, + 'corners' => 1, + 'rotate' => 0, + 'direction' => 1, + 'color' => '#000', + 'speed' => 1, + 'trail' => 60, + 'shadow' => FALSE, + 'hwaccel' => FALSE, + 'className' => 'spinner', + 'zIndex' => 2000000000, + 'top' => 'auto', + 'left' => 'auto' + ), + ); + drupal_add_js($settings, 'setting'); + $islandora_path = drupal_get_path('module', 'islandora'); + $element['#attached'] = array( + 'js' => array( + "$islandora_path/js/spin/spin.min.js", + "$islandora_path/js/spinner.js", + ), + ); + return $element; +} + /** * The submit handler for the ingest form. * diff --git a/js/ingesting_object.js b/js/ingesting_object.js deleted file mode 100755 index 913e5be9..00000000 --- a/js/ingesting_object.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @file - * Adds some spinny goodness user-feedback after the user clicks Ingest. - */ - -(function ($) { - function islandora_start_ingest_feedback() { - $('#islandora-ingest-form').after('
' + - Drupal.t('Please be patient while the the page loads.') + - '
'); - - var opts = { - lines: 10, - length: 20, - width: 10, - radius: 30, - corners: 1, - rotate: 0, - direction: 1, - color: '#000', - speed: 1, - trail: 60, - shadow: false, - hwaccel: false, - className: 'spinner', - zIndex: 2e9, - top: 'auto', - left: 'auto' - }; - var target = document.getElementById('islandora_is_working'); - var spinner = new Spinner(opts).spin(target); - // Don't want to do this in Safari, can't submit after form errors. - if (!(navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1)) { - $('#edit-next').hide(); - $('#edit-prev').hide(); - } - } - - Drupal.behaviors.islandoraIngestingObject = { - attach: function(context, settings) { - // Safari is having issues with stalling JS execution that was preventing this from running. - if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) { - $('#edit-next').one('mousedown', function() { - islandora_start_ingest_feedback() - }); - } - else { - $('#islandora-ingest-form').one('submit', function() { - islandora_start_ingest_feedback() - }); - } - } - }; -})(jQuery); diff --git a/js/spinner.js b/js/spinner.js new file mode 100755 index 00000000..165077a5 --- /dev/null +++ b/js/spinner.js @@ -0,0 +1,54 @@ +/** + * @file + * Triggers the display of a spinning icon when the form is submitted. + */ +(function ($) { + + Drupal.behaviors.spinner = { + attach: function(context, settings) { + // Store what triggered the submit. + $('form').once('submit-resolver', function() { + $(this).click(function(event) { + $(this).data('clicked', $(event.target)); + }); + $(this).keypress(function(event) { + // On enter the first submit button is assumed as is most often the + // case and this is part of the HTML 5 specification, although some + // Browsers may choose the button with the lowest tab-index. + if (event.which == 13) { + $(this).data('clicked', $(':submit', this).first()); + } + }); + }); + for (var base in settings.spinner) { + var id = '#' + base; + $(id, context).once('spinner', function () { + var spinner = new Spinner(settings.spinner[base].opts); + $(id).parents('form').one('submit', function(event) { + if ($(this).data('clicked').is(id)) { + event.preventDefault(); + // Add Message. + var message = $('
').text(settings.spinner[base].message); + $(id).after(message); + // Activate Spinner + spinner.spin(this); + // Submit the form after a set timeout, this handles problems with + // safari, in that safari submit's immediately.. + $(':submit').attr('disabled', 'disabled'); + setTimeout(function() { + // Allow for the button to be clicked, then click it then + // prevent the default behavoir. + $(id).removeAttr('disabled') + .click() + .click(function(event) { + event.preventDefault(); + }); + }, 500); + } + return true; + }); + }); + } + } + }; +})(jQuery); From 327c9b05cc62ef1dd14a04ee25c805f9691a7438 Mon Sep 17 00:00:00 2001 From: William Panting Date: Mon, 30 Sep 2013 10:41:18 -0300 Subject: [PATCH 5/6] coder --- includes/ingest.form.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index c17a1806..f9ed2b21 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -725,7 +725,7 @@ function islandora_ingest_form_ingest_button_process(array $element) { 'className' => 'spinner', 'zIndex' => 2000000000, 'top' => 'auto', - 'left' => 'auto' + 'left' => 'auto', ), ); drupal_add_js($settings, 'setting'); From 11712df2d774cfe1bfda20f334f10650e6a98cb4 Mon Sep 17 00:00:00 2001 From: William Panting Date: Mon, 30 Sep 2013 10:53:59 -0300 Subject: [PATCH 6/6] re-hiding buttons to prevent errors, only preventing submit on safari --- js/spinner.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/spinner.js b/js/spinner.js index 165077a5..a755bcb4 100755 --- a/js/spinner.js +++ b/js/spinner.js @@ -30,11 +30,15 @@ // Add Message. var message = $('
').text(settings.spinner[base].message); $(id).after(message); - // Activate Spinner + // Make UI changes. spinner.spin(this); + $('#edit-next').hide(); + $('#edit-prev').hide(); // Submit the form after a set timeout, this handles problems with // safari, in that safari submit's immediately.. - $(':submit').attr('disabled', 'disabled'); + if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) { + $(':submit').attr('disabled', 'disabled'); + } setTimeout(function() { // Allow for the button to be clicked, then click it then // prevent the default behavoir.