Skip to content

Commit

Permalink
Merge pull request #24 from esmero/ISSUE-23
Browse files Browse the repository at this point in the history
ISSUE-23: New Panorama Builder Webform Element and Other Webform related improvements. Each commit adds its little tiny details. All for beta2
  • Loading branch information
DiegoPino committed Feb 7, 2020
2 parents 0c13a04 + d838e65 commit 7885a2c
Show file tree
Hide file tree
Showing 15 changed files with 2,115 additions and 100 deletions.
40 changes: 40 additions & 0 deletions css/scenebuilder_format_strawberryfield.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.hotspot_marker_wrapper {
background-color: deepskyblue;
border-radius: 50%;
position: absolute;
top: 0px;
left: 0px;
display: none;
opacity: 0;
-moz-transition: opacity .3s ease-in-out;
-webkit-transition: opacity .3s ease-in-out;
-o-transition: opacity .3s ease-in-out;
-ms-transition: opacity .3s ease-in-out;
transition: opacity .3s ease-in-out;
z-index: 1
}
.hotspot_editor_marker {
border-radius: 50%;
background-color: deepskyblue;
width: 150px;
height: 150px;
position: absolute;
left:-75px;
top:-75px;
opacity: 0;
animation: scaleIn 4s infinite cubic-bezier(.36, .11, .89, .32);
}
@keyframes scaleIn {
from {
transform: scale(.5, .5);
opacity: .5;
}
to {
transform: scale(2.5, 2.5);
opacity: 0;
}
}




8 changes: 4 additions & 4 deletions js/hidenodeaction-webform_strawberryfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
if ($('.path-node fieldset[data-strawberryfield-selector="strawberry-webform-widget"]').length) {
if ($('.webform-confirmation',context).length) {
// Exclude webform own edit-actions containter
$('.path-node div[data-drupal-selector="edit-actions"]').not('.webform-actions').show();
$('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').show();
} else if ($('div.field--widget-strawberryfield-webform-inline-widget').length) {
$('.path-node div[data-drupal-selector="edit-actions"]').not('.webform-actions').hide();
$('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').hide();
}


var $moderationstate = $('select[data-drupal-selector="edit-moderation-state-0-state"]', context).once('show-hide-actions');
if ($moderationstate.length) {

var $select = $moderationstate.on('change', function () {
$('.path-node div[data-drupal-selector="edit-actions"]').not('.webform-actions').show();
$('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').show();

});
}
var $nodetitle = $('input[data-drupal-selector="edit-title-0-value"]', context).once('show-hide-actions');
if ($nodetitle.length) {
var $select = $nodetitle.on('input', function () {
$('.path-node div[data-drupal-selector="edit-actions"]').not('.webform-actions').show();
$('.path-node .node-form div[data-drupal-selector="edit-actions"]').not('.webform-actions').show();

});
}
Expand Down
111 changes: 111 additions & 0 deletions js/scenebuilder-pannellum_strawberryfield.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
(function ($, Drupal, drupalSettings, pannellum) {



function marker(event, $marker, $container) {
var pos = mousePosition(event,$container);
$marker.css("left", pos.x + 'px');
$marker.css("top", pos.y + 'px');
$marker.css("opacity", '1.0');
$marker.css("display", 'block');
$marker.fadeIn('slow');
$marker.fadeOut('slow');
}


function mousePosition(event,$container) {
var bounds = $container.getBoundingClientRect();
var pos = {};
// pageX / pageY needed for iOS
pos.x = (event.clientX || event.pageX) - bounds.left;
pos.y = (event.clientY || event.pageY) - bounds.top;
return pos;
}

Drupal.AjaxCommands.prototype.webform_strawberryfield_pannellum_editor_addHotSpot = function(ajax, response, status) {
console.log('adding hotspot');
// we need to find the first '.strawberry-panorama-item' id that is child of data-drupal-selector="edit-panorama-tour-hotspots"
console.log(response.selector);
$targetScene = $(response.selector).find('.strawberry-panorama-item').attr("id");
console.log($targetScene);
if (response.hasOwnProperty('hotspot')) {
$scene = Drupal.FormatStrawberryfieldPanoramas.panoramas.get($targetScene);
// add click handlers for new Hotspots if they have an URL.
// Empty URLs are handled by Drupal.FormatStrawberryfieldhotspotPopUp()
console.log(response);
if (response.hotspot.hasOwnProperty('URL')) {
response.hotspot.clickHandlerFunc = Drupal.FormatStrawberryfieldhotspotPopUp;
response.hotspot.clickHandlerArgs = response.hotspot.URL;
}

$scene.panorama.addHotSpot(response.hotspot);
}
};


Drupal.behaviors.webform_strawberryfield_pannellum_editor = {
attach: function(context, settings) {
$('.strawberry-panorama-item[data-iiif-image]').once('attache_pne')
.each(function (index, value) {
var hotspots = [];
// Get the node uuid for this element
var element_id = $(this).attr("id");
console.log('Checking for loaded Panoramatour builder Hotspots');
console.log(drupalSettings.webform_strawberryfield.WebformPanoramaTour);
// Feed with existing Hotspots comming from the Webform Element data.
for (var parentselector in drupalSettings.webform_strawberryfield.WebformPanoramaTour) {
if (Object.prototype.hasOwnProperty.call(drupalSettings.webform_strawberryfield.WebformPanoramaTour, parentselector)) {
$targetScene = $("[data-webform_strawberryfield-selector='" + parentselector + "']").find('.strawberry-panorama-item').attr("id");
console.log(parentselector);
console.log($targetScene);
$scene = Drupal.FormatStrawberryfieldPanoramas.panoramas.get($targetScene);
if ((typeof $scene !== 'undefined')) {
if (drupalSettings.webform_strawberryfield.WebformPanoramaTour[parentselector]!== null
&& typeof drupalSettings.webform_strawberryfield.WebformPanoramaTour[parentselector][Symbol.iterator] === 'function'
) {
drupalSettings.webform_strawberryfield.WebformPanoramaTour[parentselector].forEach(function (hotspotdata, key) {
console.log(hotspotdata);
if (hotspotdata.hasOwnProperty('URL')) {
hotspotdata.clickHandlerFunc = Drupal.FormatStrawberryfieldhotspotPopUp;
hotspotdata.clickHandlerArgs = hotspotdata.URL;
}
$scene.panorama.addHotSpot(hotspotdata);
});
}
}
}
}

// Check if we got some data passed via Drupal settings.
if (typeof(drupalSettings.format_strawberryfield.pannellum[element_id]) != 'undefined') {
console.log('initializing Panellum Panorama Builder')
console.log(Drupal.FormatStrawberryfieldPanoramas.panoramas);
Drupal.FormatStrawberryfieldPanoramas.panoramas.forEach(function(item, key) {

var element_id_marker = element_id + '_marker';
var $newmarker = $( "<div class='hotspot_marker_wrapper'><div class='hotspot_editor_marker' id='" + element_id_marker +"'></div></div>");

$("#" +element_id+ " .pnlm-ui").append( $newmarker );

item.panorama.on('mousedown', function clicker(e) {

$hotspot_cors = item.panorama.mouseEventToCoords(e);
console.log(item.panorama.getHfov());
var $jquerycontainer = $(item.panorama.getContainer());

$button_container = $jquerycontainer.closest("[data-drupal-selector='edit-panorama-tour-hotspots-temp']");

$button_container.find("[ data-drupal-hotspot-property='yaw']").val($hotspot_cors[1]);
$button_container.find("[ data-drupal-hotspot-property='pitch']").val($hotspot_cors[0]);
$button_container.find("[ data-drupal-hotspot-property='hfov']").val(item.panorama.getHfov());

marker(e,$newmarker,item.panorama.getContainer());

}
);
});
}

})}}

})(jQuery, Drupal, drupalSettings, window.pannellum);
63 changes: 63 additions & 0 deletions src/Ajax/AddHotSpotCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Created by PhpStorm.
* User: dpino
* Date: 10/1/19
* Time: 11:30 AM
*/

namespace Drupal\webform_strawberryfield\Ajax;
use Drupal\Core\Ajax\CommandInterface;
class AddHotSpotCommand implements CommandInterface
{

/**
* The Hotspot
*
* @var \stdClass;
*/
protected $hotspot;


/**
* The Scene ID
*
* @var string
*/
protected $sceneid;

/**
* The JQuery() selector
*
* @var string
*/
protected $selector;

/**
* Constructs an AlertCommand object.
*
* @param string $text
* The text to be displayed in the alert box.
*/
public function __construct($selector, $hotspot, $sceneid) {
$this->selector = $selector;
$this->hotspot = $hotspot;
$this->sceneid = $sceneid;

}

/**
* Implements Drupal\Core\Ajax\CommandInterface:render().
*/
public function render() {

return [
'command' => 'webform_strawberryfield_pannellum_editor_addHotSpot',
'selector' => $this->selector,
'hotspot' => $this->hotspot,
'sceneid' => $this->sceneid,
];
}

}

6 changes: 3 additions & 3 deletions src/Element/WebformNominatim.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static function processWebformComposite(
'display_name' => t('Display Name'),
'category' => t('Category'),
];

$table_options = [];
foreach($nominatim_features as $key => $feature) {

$table_options[$key+1] = [
Expand Down Expand Up @@ -411,8 +411,8 @@ public static function nominatimTableSubmit(
// Lat and Long are in http://en.wikipedia.org/wiki/en:WGS-84
$values = [
'value' => $nominatim_features[$selected_option]->label,
'lat' => $nominatim_features[$selected_option]->value->geometry->coordinates[0],
'lng' => $nominatim_features[$selected_option]->value->geometry->coordinates[1],
'lat' => $nominatim_features[$selected_option]->value->geometry->coordinates[1],
'lng' => $nominatim_features[$selected_option]->value->geometry->coordinates[0],
'category' => $nominatim_features[$selected_option]->value->properties->category,
'display_name' => $nominatim_features[$selected_option]->label,
'osm_id' => $nominatim_features[$selected_option]->value->properties->osm_id,
Expand Down
Loading

0 comments on commit 7885a2c

Please sign in to comment.