window.okeReviewsWidgetOnInit = function() {
setupWidget();
var observer = new MutationObserver(function(records) {
setupWidget();
});
var reviewMainElement = document.querySelector('.js-okeReviews-reviews-main');
observer.observe(reviewMainElement, {
childList: true
});
}
function setupWidget() {
createHolderDiv();
moveDiv('.js-okeReviews-writeReview','.okeReviews-reviewsAggregate-controls');
moveDiv('.okeReviews-reviews-controls-select','.okeReviews-reviewsAggregate-controls');
moveDiv('.okeReviews-reviewsAggregate-recommends','.okeReviews-reviewsAggregate-side-inner');
}
function moveDiv(targetSelector, destinationSelector, prepend) {
var destination = document.querySelector(destinationSelector);
var objectToMove = document.querySelector(targetSelector);
if (objectToMove && destination) {
prepend ? destination.prepend(objectToMove) : destination.append(objectToMove);
}
}
function createHolderDiv() {
var existingHolderDiv = document.querySelector('.okeReviews-reviewsAggregate-controls');
if (!existingHolderDiv) {
var aggregateControlDiv = document.createElement("div");
var destination = document.querySelector('.okeReviews-reviewsAggregate-primary');
aggregateControlDiv.setAttribute('class','okeReviews-reviewsAggregate-controls');
if (destination) {
destination.append(aggregateControlDiv);
}
}
}