Origin commit

This commit is contained in:
Hoang Huu
2019-09-10 11:27:33 +07:00
commit 499e068e4f
844 changed files with 188705 additions and 0 deletions

186
assets/js/frontend/dashboard.js Executable file
View File

@@ -0,0 +1,186 @@
;(function ($, settings) {
"use strict";
if (window.Opalestate === undefined) {
window.Opalestate = {};
}
/**
* GooglemapSearch
*/
var AgencyUpdateProfile = Opalestate.AgencyUpdateProfile = function ( form ) {
/**
* Create Google Map In Single Property Only
*/
function getFormData () {
var formData = new FormData();
formData.append('section', 'general');
$(".cmb2-uploader-files").each( function(){
var file_btn = $( 'input.select-file', this );
var files = $(".uploader-item-preview", this );
var name = $(this).data( 'name' );
var issingle = $( this ).data('single');
$(files).each( function( i , element ){
var file = $(this).prop( 'file');
if( file ) {
if( issingle ){
formData.append( name, file );
} else {
formData.append( name+"["+i+"]", file );
}
}
} );
});
return formData;
}
function toggleSubmit ( _this ){
if( $( _this ).attr('disabled') == "disabled" ){
$( _this ).removeAttr( 'disabled' );
$(_this).find('i').remove( );
} else {
$( _this ).attr('disabled','disabled');
$(_this).append( ' <i class="fa fa-spinner fa-spin"></i> ' );
}
};
function makeAjax( formData, $submit_btn ) {
$.ajax({
url : opalesateJS.ajaxurl,
data : formData,
type : 'POST',
processData: false,
contentType: false,
dataType: "json",
success : function( response ){
if( response.status == true ){
if( response.redirect ){
window.location.href = response.redirect;
}
var myToast = $.toast({
heading: response.heading,
text: response.message,
icon: 'success',
position: 'bottom-right',
hideAfter: 5000,
showHideTransition: 'fade',
});
} else {
toggleSubmit( $submit_btn );
var myToast = $.toast({
heading: response.heading,
text: response.message,
icon: 'error',
position: 'bottom-right',
hideAfter: 5000,
showHideTransition: 'fade'
});
}
}
});
}
var init = function ( form ){
$( form ).on( "submit", function(){
if( typeof(tinyMCE) != "undefined" ) {
tinyMCE.triggerSave();
}
toggleSubmit( $("button:submit" , form ) ) ;
var formData = getFormData();
var dataSubmit = $( form ).serializeArray();
$.each( dataSubmit, function ( key, input ) {
formData.append( input.name, input.value );
});
makeAjax( formData, $("button:submit" , form ) )
return false;
} );
}
init( form );
}
/////
$(document).ready(function () {
/// update agency profile
if( $("#opalestate_ofe_front").length > 0 ){
new AgencyUpdateProfile( $("#opalestate_ofe_front") );
}
// update agent profile
if( $("#opalestate_agt_front").length > 0 ){
new AgencyUpdateProfile( $("#opalestate_agt_front") );
}
if( $("#opalestate_user_front").length > 0 ){
new AgencyUpdateProfile( $("#opalestate_user_front") );
}
if( $("#opalestate-add-team-form").length > 0 ){
function formatRepo (repo) {
if ( repo.loading ) {
return repo.text;
}
var markup = "<div class='select2-search-member clearfix'>" +
"<div class='avatar'><img width=\"50\" src='" + repo.avatar_url + "' /></div>" +
"<div class='member-meta'>" +
"<div class='member-title'>" + repo.full_name + "</div>";
markup += "</div></div>";
return markup;
}
function formatRepoSelection (repo) {
return repo.full_name || repo.text;
}
function load_select2_member ( id, action ) {
$( id ).select2({
width: '100%',
ajax: {
url: opalesateJS.ajaxurl+"?action="+action,
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, params) {
params.page = params.page || 1;
return {
results: data.items,
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: true
},
placeholder: 'Search for a repository',
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 1,
templateResult: formatRepo,
templateSelection: formatRepoSelection
});
}
load_select2_member( ".opalesate-find-user", 'opalestate_search_property_users');
}
} );
})(jQuery);

86
assets/js/frontend/elementor.js Executable file
View File

@@ -0,0 +1,86 @@
(function ($ ) {
"use strict";
var carouselSlick = function( $scope , $selector, elementorFrontend ) {
var slidesToShow = 0;
var elementSettings = $scope.data('settings');
if( elementSettings === undefined ){
var elementSettings = $scope.find(".elementor-opal-slick-slider").data('settings');
}
// console.log( elementSettings );
if( elementSettings === undefined ){
return true;
}
var slidesToShow =+ elementSettings.slides_to_show || 3,
isSingleSlide = 1 === slidesToShow,
breakpoints = elementorFrontend.config.breakpoints;
var slickOptions = {
slidesToShow: slidesToShow,
autoplay: 'yes' === elementSettings.autoplay,
autoplaySpeed: elementSettings.autoplay_speed,
infinite: 'yes' === elementSettings.infinite,
pauseOnHover: 'yes' === elementSettings.pause_on_hover,
speed: elementSettings.speed,
arrows: -1 !== [ 'arrows', 'both' ].indexOf( elementSettings.navigation ),
dots: -1 !== [ 'dots', 'both' ].indexOf( elementSettings.navigation ),
rtl: 'rtl' === elementSettings.direction,
responsive: [
{
breakpoint: breakpoints.lg,
settings: {
slidesToShow: +elementSettings.slides_to_show_tablet || ( isSingleSlide ? 1 : 2 ),
slidesToScroll: 1,
},
},
{
breakpoint: breakpoints.md,
settings: {
slidesToShow: +elementSettings.slides_to_show_mobile || 1,
slidesToScroll: 1,
},
},
],
};
if ( isSingleSlide ) {
slickOptions.fade = 'fade' === elementSettings.effect;
} else {
slickOptions.slidesToScroll = +elementSettings.slides_to_scroll;
}
var $carousel = $scope.find( $selector );
// $carousel.removeClass('products');
$carousel.slick( slickOptions );
// $carousel.addClass('products');
}
/// // / / / /
$(window).on('elementor/frontend/init', function(){
elementorFrontend.hooks.addAction( 'frontend/element_ready/opalestate-agent-collection.default', function( $scope ) {
if( $scope.find(".elementor-opal-slick-slider") ) {
carouselSlick( $scope, '.elementor-slick-slider-row.row-items', elementorFrontend );
}
} );
elementorFrontend.hooks.addAction( 'frontend/element_ready/opalestate-property-collection.default', function( $scope ) {
if( $scope.find(".elementor-opal-slick-slider") ) {
carouselSlick( $scope, '.elementor-slick-slider-row.row-items' , elementorFrontend );
}
} );
elementorFrontend.hooks.addAction( 'frontend/element_ready/opalestate-category-list.default', function( $scope ) {
if( $scope.find(".elementor-opal-slick-slider") ) {
carouselSlick( $scope, '.elementor-slick-slider-row.row-items' , elementorFrontend );
}
} );
});
})( jQuery );

621
assets/js/frontend/googlemaps.js Executable file
View File

@@ -0,0 +1,621 @@
;(function ($, settings) {
"use strict";
if (window.Opalestate === undefined) {
window.Opalestate = {};
}
/**
* GooglemapSearch
*/
var GooglemapSingle = Opalestate.GooglemapSingle = function ( data , id ) {
/**
* Create Google Map In Single Property Only
*/
var initializePropertyMap = function ( data , id ){
var propertyMarkerInfo = data;
var enable = true ;
var url = propertyMarkerInfo.icon;
var size = new google.maps.Size( 42, 57 );
var allMarkers = [];
var setMapOnAll = function (markers, map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap( map );
}
}
// retina
if( window.devicePixelRatio > 1.5 ) {
if ( propertyMarkerInfo.retinaIcon ) {
url = propertyMarkerInfo.retinaIcon;
size = new google.maps.Size( 83, 113 );
}
}
var propertyLocation = new google.maps.LatLng( propertyMarkerInfo.latitude, propertyMarkerInfo.longitude );
var propertyMapOptions = {
center: propertyLocation,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: false
};
var propertyMap = new google.maps.Map( document.getElementById( id ), propertyMapOptions );
/**
*
*/
var createMarker = function ( position, icon ) {
var image = {
url: icon,
size: size,
scaledSize: new google.maps.Size( 32, 57 ),
origin: new google.maps.Point( 0, 0 ),
anchor: new google.maps.Point( 21, 56 )
};
var _marker = new google.maps.Marker({
map: propertyMap,
position: position,
icon: image
});
return _marker;
}
var infowindow = new google.maps.InfoWindow();
createMarker( propertyLocation, url );
/**
* Places near with actived types
*/
if( enable ){
var $navs = $("#"+id).parent().find( '.property-search-places' );
$(' .btn-map-search', $navs ).unbind('click').bind( 'click', function(){
var service = new google.maps.places.PlacesService( propertyMap ) ;
var type = $(this).data('type');
var $this = $(this).parent();
var icon = {
url: opalesateJS.mapiconurl+$(this).data('icon'),
scaledSize: new google.maps.Size( 28, 28 ),
anchor: new google.maps.Point( 21, 16 ),
origin: new google.maps.Point( 0, 0 )
};
if( !allMarkers[type] || allMarkers[type].length <= 0 ){
var markers = [] ;
var bounds = propertyMap.getBounds();
var $this = $(this);
service.nearbySearch({
location: propertyLocation,
radius: 2000,
bounds: bounds,
type: type
}, callbackNearBy);
function callbackNearBy(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarkerNearBy(results[i]);
}
$('.nearby-counter',$this).remove();
$('span',$this).append( $('<em class="nearby-counter">'+markers.length+'</em>') );
allMarkers[type] = markers;
}
}
function abc(){
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
var marker = new google.maps.Marker({
map: propertyMap,
position: place.geometry.location,
icon: icon,
visible: true
});
marker.setMap( propertyMap );
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent( place.name );
infowindow.open(propertyMap, this);
});
markers.push( marker );
}
$('.nearby-counter',$this).remove();
$('span',$this).append( $('<em class="nearby-counter">'+markers.length+'</em>') );
allMarkers[type] = markers;
//console.log( place );
}
}
function createMarkerNearBy(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: propertyMap,
position: place.geometry.location,
icon: icon,
visible: true
});
marker.setMap( propertyMap );
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(propertyMap, this);
});
markers.push( marker );
}
}else {
for( var i=0 ; i < allMarkers[type].length; i++ ){
allMarkers[type][i].setMap( null );
}
allMarkers[type] = [];
}
$(this).toggleClass('active');
} );
}
}
initializePropertyMap( data , id );
}
var GoogleMapSearch = Opalestate.GooglemapSingle = function ( data ) {
var initializePropertiesMap = function ( properties ) {
// Properties Array
var mapOptions = {
zoom: 12,
maxZoom: 16,
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
panControl: false,
zoomControl: true,
mapTypeControl: false,
scaleControl: false,
streetViewControl: true,
overviewMapControl: false,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.RIGHT_TOP
},
streetViewControlOptions: {
position: google.maps.ControlPosition.RIGHT_TOP
}
};
var map = new google.maps.Map( document.getElementById( "opalestate-map-preview" ), mapOptions );
var bounds = new google.maps.LatLngBounds();
// Loop to generate marker and infowindow based on properties array
var markers = new Array();
for ( var i=0; i < properties.length; i++ ) {
// console.log( properties[i] );
var url = properties[i].icon;
var size = new google.maps.Size( 42, 57 );
if( window.devicePixelRatio > 1.5 ) {
if ( properties[i].retinaIcon ) {
url = properties[i].retinaIcon;
size = new google.maps.Size( 83, 113 );
}
}
var image = {
url: url,
size: size,
scaledSize: new google.maps.Size( 30, 51 ),
origin: new google.maps.Point( 0, 0 ),
anchor: new google.maps.Point( 21, 56 )
};
markers[i] = new google.maps.Marker({
position: new google.maps.LatLng( properties[i].lat, properties[i].lng ),
map: map,
icon: image,
title: properties[i].title,
animation: google.maps.Animation.DROP,
visible: true
});
bounds.extend( markers[i].getPosition() );
var boxText = document.createElement( "div" );
var pricelabel = '';
if( properties[i].pricelabel ){
pricelabel = ' / ' + properties[i].pricelabel;
}
// console.log( properties[i] );
boxText.className = 'map-info-preview media';
var meta = '<ul class="list-inline property-meta-list">';
if( properties[i].metas ){
for ( var x in properties[i].metas ){
var m = properties[i].metas[x];
meta += '<li><i class="icon-property-'+x+'"></i>' + m.value +'<span class="label-property">' + m.label + '</span></li>'
}
}
meta += '</ul>';
boxText.innerHTML = '<div class="media-top"><a class="thumb-link" href="' + properties[i].url + '">' +
'<img class="prop-thumb" src="' + properties[i].thumb + '" alt="' + properties[i].title + '"/>' +
'</a>'+ properties[i].status +'</div>' +
'<div class="info-container media-body">' +
'<h5 class="prop-title"><a class="title-link" href="' + properties[i].url + '">' + properties[i].title +
'</a></h5><p class="prop-address"><em>' + properties[i].address + '</em></p><p><span class="price text-primary">' + properties[i].pricehtml + pricelabel +
'</span></p>'+meta+'</div>'+'<div class="arrow-down"></div>';
var myOptions = {
content: boxText,
disableAutoPan: true,
maxWidth: 0,
alignBottom: true,
pixelOffset: new google.maps.Size( -122, -48 ),
zIndex: null,
closeBoxMargin: "0 0 -16px -16px",
closeBoxURL: opalesateJS.mapiconurl+"close.png",
infoBoxClearance: new google.maps.Size( 1, 1 ),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
var ib = new InfoBox( myOptions );
attachInfoBoxToMarker( map, markers[i], ib, i );
}
var last = null ;
$('body').delegate( '[data-related="map"]', 'mouseenter', function(){
if( $(this).hasClass('map-active') ){
return true;
}
var i = $(this).data( 'id' );
$( '[data-related="map"]' ).removeClass( 'map-active' );
$(this).addClass( 'active' );
map.setZoom( 65536 );// alert( scale );
if( markers[i] ){
var marker = markers[i];
google.maps.event.trigger( markers[i], 'click' );
var scale = Math.pow( 2, map.getZoom() );
var offsety = ( (100/scale) || 0 );
var projection = map.getProjection();
var markerPosition = marker.getPosition();
var markerScreenPosition = projection.fromLatLngToPoint( markerPosition );
var pointHalfScreenAbove = new google.maps.Point( markerScreenPosition.x, markerScreenPosition.y - offsety );
var aboveMarkerLatLng = projection.fromPointToLatLng( pointHalfScreenAbove );
map.setZoom( scale );
map.setCenter( aboveMarkerLatLng );
}
return false;
});
map.fitBounds(bounds);
/* Marker Clusters */
var markerClustererOptions = {
ignoreHidden: true,
maxZoom: 14,
styles: [{
textColor: '#000000',
url: opalesateJS.mapiconurl+"cluster-icon.png",
height: 51,
width: 30
}]
};
var markerClusterer = new MarkerClusterer( map, markers, markerClustererOptions );
function attachInfoBoxToMarker( map, marker, infoBox , i ){
google.maps.event.addListener( marker, 'click', function(){
if( $( '[data-related="map"]' ).filter('[data-id="'+i+'"]').length > 0 ){
var $m = $( '[data-related="map"]' ).filter('[data-id="'+i+'"]');
$( '[data-related="map"]' ).removeClass( 'map-active' );
$m.addClass('map-active');
}
if( last != null ){
last.close();
}
var scale = Math.pow( 2, map.getZoom() );
var offsety = ( (100/scale) || 0 );
var projection = map.getProjection();
var markerPosition = marker.getPosition();
var markerScreenPosition = projection.fromLatLngToPoint( markerPosition );
var pointHalfScreenAbove = new google.maps.Point( markerScreenPosition.x, markerScreenPosition.y - offsety );
var aboveMarkerLatLng = projection.fromPointToLatLng( pointHalfScreenAbove );
map.setCenter( aboveMarkerLatLng );
infoBox.open( map, marker );
last = infoBox;
});
}
}
initializePropertiesMap( data );
}
/////
$(document).ready(function () {
function initialize_property_street_view( data , id ){
var propertyMarkerInfo = data;
var propertyLocation = new google.maps.LatLng( propertyMarkerInfo.latitude, propertyMarkerInfo.longitude );
/**
* Street View
*/
var panoramaOptions = {
position: propertyLocation,
pov: {
heading: 34,
pitch: 10
}
};
var panorama = new google.maps.StreetViewPanorama( document.getElementById( id ), panoramaOptions);
google.maps.event.trigger(panorama, 'resize');
}
$( ".property-preview-map").each( function(){
new GooglemapSingle( $(this).data() , $(this).attr('id') );
} );
$( ".tab-google-street-view-btn") .click( function(){
$( ".property-preview-street-map").hide();
$( ".property-preview-street-map").each( function(){
var d = $(this).data() ;
var i = $(this).attr('id') ;
initialize_property_street_view( d , i );
} );
$( ".property-preview-street-map").show( 100 );
} );
///
// auto set height for split google map
$( '.split-maps-container' ).each( function() {
$( "#opalestate-map-preview ").height( $(window).height() );
} );
})
$(document).ready(function () {
// search
// show google maps
// update google maps
var updatePreviewGoogleMap = function( url ) {
if( $('#opalestate-map-preview').length > 0 ) {
$.ajax({
type: 'GET',
dataType: 'json',
url: opalesateJS.ajaxurl,
data: url,
success: function(data) {
new GoogleMapSearch( data );
}
});
}
};
if( $('#opalestate-map-preview').length > 0 || $( '.opalesate-properties-results').length > 0 ) {
var currentLocation = location.search.substr(1)+"&action=opalestate_ajx_get_properties&paged="+$('#opalestate-map-preview').data('page');
updatePreviewGoogleMap( currentLocation );
}
// update results
function updatePropertiesResults( data ){
$( '.opalesate-properties-results').append( $('<div class="opalestate-loading"></div>') );
$.ajax({
type: "GET",
url: opalesateJS.ajaxurl,
data: data+"&action=opalestate_render_get_properties" ,
success: function( response ) {
if( response ){
$( '.opalesate-properties-results' ).html( response );
}
$( '.opalesate-properties-results .opalestate-loading').remove();
$('.opalestate-sortable select').select2( {
width: '100%',
minimumResultsForSearch: -1
} );
}
});
}
function updatePropertiesByParseringHtml( newurl ){
$( '.opalesate-properties-results .opalesate-archive-bottom').append( $('<div class="opalestate-loading"></div>') );
$.ajax({
type: "GET",
url: newurl,
dataType : 'html',
cache: false,
success: function( data ) {
if( data ){
$( '.opalesate-properties-results' ).html( $(data).find('.opalesate-properties-results').html() );
$('.opalestate-sortable select').select2( {
width: '100%',
minimumResultsForSearch: -1
} );
}
// $( '.opalesate-properties-results .opalestate-loading').remove();
}
});
}
$('form.opalestate-search-form').submit( function ( ){
if( $('#opalestate-map-preview').length > 0 ) {
if( $(".opalesate-properties-results") && $(".opalesate-properties-results").data('mode') == 'html' ) {
var $form = $(this);
if (history.pushState) {
var ps = $form.serialize();
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?'+ ps;
window.history.pushState({path:newurl},'',newurl);
updatePropertiesByParseringHtml( newurl );
}
} else {
updatePropertiesResults( $(this).serialize() );
}
return false;
}
return true;
} );
$( '.ajax-search-form form.opalestate-search-form' ).each( function(){
var $form = $(this);
$( '.ajax-change select', this ).change( function(){
if (history.pushState) {
var ps = $form.serialize();
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?'+ ps;
window.history.pushState({path:newurl},'',newurl);
}
$form.submit();
return false;
} );
} );
// // Sortable Change // //
$("body").delegate( '#opalestate-sortable-form select', 'change', function(){
var ps = '';
if( $('form.opalestate-search-form').length > 0 ) {
var $form =$('form.opalestate-search-form');
var ps = $form.serialize()+"&opalsortable="+$(this).val()+"&display="+$(".display-mode a.active").data('mode');
}
if( $(".opalesate-properties-results") && ps ) {
if (history.pushState) {
var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?'+ ps;
window.history.pushState({path:newurl},'',newurl);
updatePropertiesByParseringHtml( newurl );
}
} else {
$("#opalestate-sortable-form").submit();
}
} );
// display mode
$( "body" ).delegate( ".display-mode a", 'click', function() {
if( $(".opalesate-properties-results").length > 0 ){
var newurl = $(this).attr('href');
window.history.pushState({path:newurl},'',newurl);
updatePropertiesByParseringHtml( newurl );
return false;
}
} );
// check any estate search form is enabled /////////////////
if( $('#opalestate-map-preview').length > 0 ) {
$( "body" ).delegate( "form.opalestate-search-form select", "change", function () {
var params = $( "form.opalestate-search-form" ).serialize();
var url = "action=opalestate_ajx_get_properties&"+params;
updatePreviewGoogleMap( url );
$('form.opalestate-search-form').submit();
return true;
} );
$( "body" ).delegate( "form.opalestate-search-form input", "change", function () {
if( $(this).hasClass("ranger-geo_radius") ){
return false;
}
var params = $( "form.opalestate-search-form" ).serialize();
var url = "action=opalestate_ajx_get_properties&"+params;
updatePreviewGoogleMap( url );
$('form.opalestate-search-form').submit();
} );
}
/////////// ///////
} );
})(jQuery);
//// //////
(function( $ ) {
'use strict';
$(document).ready(function () {
$( '.opalestate-search-opal-map' ).each( function() {
initializeMapAdressSearch( $(this) );
});
} );
function initializeMapAdressSearch( mapInstance ) {
var searchInput = mapInstance.find( '.opal-map-search' );
// Search
var autocomplete = new google.maps.places.Autocomplete( searchInput[0] );
// autocomplete.bindTo( 'bounds', map );
var latitude = mapInstance.find( '.opal-map-latitude' );
var longitude = mapInstance.find( '.opal-map-longitude' );
google.maps.event.addListener( autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
if ( ! place.geometry ) {
return;
}
if( place.geometry.location.lat() ){
$(mapInstance).addClass("active");
} else {
$(mapInstance).removeClass("active");
}
latitude.val( place.geometry.location.lat() );
longitude.val( place.geometry.location.lng() );
});
$( ".map-remove", mapInstance ).click( function() {
latitude.val( "" );
longitude.val( "" );
searchInput.val("");
latitude.change();
} );
$( searchInput ).keypress( function( event ) {
if ( 13 === event.keyCode ) {
event.preventDefault();
}
});
}
})( jQuery );

263
assets/js/frontend/property.js Executable file
View File

@@ -0,0 +1,263 @@
/* global tinymce, wpCookies, autosaveL10n, switchEditors */
// Back-compat
window.opalestate_messages = function() {
return true;
};
/**
* @summary Adds autosave to the window object on dom ready.
*
* @since 3.9.0
*
* @param {jQuery} $ jQuery object.
* @param {window} The window object.
*
*/
( function( $, window ) {
/**
* @summary Auto saves the post.
*
* @since 3.9.0
*
* @returns {Object}
* {{
* getPostData: getPostData,
* getCompareString: getCompareString,
* disableButtons: disableButtons,
* enableButtons: enableButtons,
* local: ({hasStorage, getSavedPostData, save, suspend, resume}|*),
* server: ({tempBlockSave, triggerSave, postChanged, suspend, resume}|*)}
* }
* The object with all functions for autosave.
*/
function opalestate_messages() {
var $document = $( document );
var $page = $( '#page-importer' );
/**
*
*/
function trigger_send_messages(){
$( ".opalestate-message-form" ).on('submit', function(){
make_ajax( $( this ).serialize(), this );
return false;
} );
}
function toggle_submit_button ( submit ){
var _this = $('button[type="submit"]', submit );
if( $( _this ).attr('disabled') == "disabled" ){
$( _this ).removeAttr( 'disabled' );
$(_this).find('i').remove( );
} else {
$( _this ).attr('disabled','disabled');
$(_this).append( '<i class="fa fa-spinner fa-spin"></i>' );
}
};
function trigger_send_reply(){
$( ".opalestate-form-reply" ).on( "submit" , function(){
var message = $( 'textarea', this).val();
if( message ) {
make_ajax_reply( $( this ).serialize(), this );
}
return false;
} );
}
function make_ajax_reply( data, _this ){
$( '.opalestate-message-notify', _this ).remove();
$.ajax({
type : 'POST',
dataType : 'json',
url : opalesateJS.ajaxurl,
data : 'action=send_email_contact_reply&' + data,
success: function( response ) {
if( response ) {
var _class = response.status ? 'success' : 'danger';
// $( _this ).append('<p class="opalestate-message-notify msg-status-'+ _class +'"><span>'+ response.msg +'</span></p>');
if( response.status ){
$( 'textarea', _this ).val( "" );
var myToast = $.toast({
heading: response.heading,
text: response.msg,
icon: 'success',
position: 'bottom-right',
hideAfter: 3500,
showHideTransition: 'fade'
});
if ( response.data ){
var html = '<div class="message-body">';
html += '<div class="message-body"><div class="message-avatar">';
html += '<img src="'+response.data.avatar+'">';
html += '</div><div class="message-content">';
html += '<div>'+response.data.created+'</div>' + response.data.message;
html += '</div></div>';
html += '</div>';
$(".opalestate-read-message").append( html );
}
} else {
}
}
}
});
}
function load_message_reply(){
}
function make_ajax ( data, _this ) {
$( '.opalestate-message-notify', _this ).remove();
var action = $( _this ).data('action')? $( _this ).data('action') : 'send_email_contact';
toggle_submit_button( _this );
$.ajax({
type : 'POST',
dataType : 'json',
url : opalesateJS.ajaxurl,
data : 'action='+action+'&' + data,
success: function( response ) {
if( response ) {
var _class = response.status ? 'success' : 'danger';
$( _this ).append('<p class="opalestate-message-notify msg-status-'+ _class +'"><span>'+ response.msg +'</span></p>');
if( response.status ){
$( 'textarea', _this ).val( "" );
}
toggle_submit_button( _this );
}
}
});
}
function trigger_print_property() {
$( '.js-print-property' ).on( 'click', function ( e ) {
e.preventDefault();
var id = $( this ).data( 'id' );
var newWindown = window.open( '', 'Print!', 'width=800 ,height=850' );
$.ajax( {
type: 'POST',
url: opalesateJS.ajaxurl,
data: {
'action': 'opalestate_ajax_create_property_print',
'id': id,
},
success: function ( data ) {
newWindown.document.write( data );
newWindown.document.close();
newWindown.focus();
setTimeout( function () {
newWindown.print();
}, 1000 );
}
} );
} );
}
function trigger_toggle_featured() {
/// ajax set featured
$( 'body' ).delegate( '.btn-toggle-featured', 'click', function () {
var $this = $( this );
$.ajax( {
type: 'POST',
url: opalesateJS.ajaxurl,
data: 'property_id=' + $( this ).data( 'property-id' ) + '&action=opalestate_toggle_featured_property', // elements.
dataType: 'json',
success: function ( data ) {
if ( data.status ) {
$( '[data-id="property-toggle-featured-' + $this.data( 'property-id' ) + '"]' )
.removeClass( 'hide' );
$this.remove();
} else {
alert( data.msg );
}
}
} );
return false;
} );
}
function trigger_view_gallery(){
$( 'body' ).delegate( '.opalestate-ajax-gallery', 'click', function () {
var parent = $(this).parent();
var open_gallery = function ( parent ){
$(parent ).magnificPopup({
type: 'image',
delegate: 'a.gallery-item',
gallery:{
enabled:true
}
});
$( 'a.gallery-item', parent ).trigger('click');
}
if( $(".gallery-item", parent ).length <= 0 ){
var items = [];
$.ajax( {
type: 'POST',
url: opalesateJS.ajaxurl,
data: 'property_id=' + $( this ).data( 'id' ) + '&action=opalestate_gallery_property', // elements.
dataType: 'json',
success: function ( data ) {
if( data.gallery ){
for( var image in data.gallery ){
parent.append( '<a href="'+data.gallery[image]+'" class="gallery-item hide"></a>' );
}
}
open_gallery( parent );
}
} );
} else {
open_gallery( parent );
}
return false;
} );
}
/**
* @summary Sets the autosave time out.
*
* Wait for TinyMCE to initialize plus 1 second. for any external css to finish loading,
* then save to the textarea before setting initialCompareString.
* This avoids any insignificant differences between the initial textarea content and the content
* extracted from the editor.
*
* @since 3.9.0
*
* @returns {void}
*/
$document.on( '.opalestate-message-form', function( event, editor ) {
}).ready( function() {
trigger_send_messages();
trigger_send_reply();
trigger_print_property();
trigger_toggle_featured();
trigger_view_gallery();
});
return {
};
}
/** @namespace wp */
window.wp = window.wp || {};
window.wp.opalestate_messages = opalestate_messages();
}( jQuery, window ));

245
assets/js/frontend/submission.js Executable file
View File

@@ -0,0 +1,245 @@
jQuery( document ).ready( function ( $ ) {
'use strict';
var toggleSubmit = function ( _this ){
if( $( _this ).attr('disabled') == "disabled" ){
$( _this ).removeAttr( 'disabled' );
$(_this).find('i').remove( );
} else {
$( _this ).attr('disabled','disabled');
$(_this).append( '<i class="fa fa-spinner fa-spin"></i>' );
}
};
$( '.opalestate-submission-tab' ).each( function () {
var $submission_tab = $( this );
var $submit_btn = $submission_tab.find( '[name=submit-cmb]' );
var $next_btn = $( '.submission-next-btn' );
var $back_btn = $( '.submission-back-btn' );
var $tab_content = $submission_tab.find( '.opalestate-tab-content' );
$submission_tab.find( '.tab-item' ).first().addClass( 'active' );
$tab_content.first().addClass( 'active' );
if ( $tab_content.length != 1 ) {
$submit_btn.hide();
} else {
$next_btn.hide();
}
$submit_btn.on( 'click', function ( e ) {
e.preventDefault();
var empty_required_inputs = opalestate_get_empty_required_inputs( $submission_tab );
if ( empty_required_inputs.length === 0 ) {
$submit_btn.parents( 'form' ).submit();
}
} );
/*
$next_btn.click( function(){
// $submit_btn.click();
return false;
});
*/
var submitFormFiles = function ( name, files ) {
var formData = new FormData();
formData.append('section', 'general');
// formData.append('action', 'opalestate_submitted_property');
$(".cmb2-uploader-files").each( function(){
var file_btn = $( 'input.select-file', this );
var files = $(".uploader-item-preview", this );
var name = $(this).data( 'name' );
var issingle = $( this ).data('single');
$(files).each( function( i , element ){
var file = $(this).prop( 'file');
if( file ) {
if( issingle ){
formData.append( name, file );
} else {
formData.append( name+"["+i+"]", file );
}
}
} );
});
// console.log( formData );
var dataSubmit = $submit_btn.parents( 'form' ).serializeArray();
$.each( dataSubmit, function ( key, input ) {
formData.append( input.name, input.value );
});
formData.append('action', 'opalestate_save_agency_data');
toggleSubmit( $submit_btn );
$.ajax({
url : opalesateJS.ajaxurl,
data : formData,
type : 'POST',
processData: false,
contentType: false,
dataType: "json",
success : function( response ){
if( response.status == true ){
if( response.redirect ){
window.location.href = response.redirect;
}
var myToast = $.toast({
heading: response.heading,
text: response.message,
icon: 'success',
position: 'bottom-right',
hideAfter: 5000,
showHideTransition: 'fade',
});
} else {
toggleSubmit( $submit_btn );
var myToast = $.toast({
heading: response.heading,
text: response.message,
icon: 'error',
position: 'bottom-right',
hideAfter: 5000,
showHideTransition: 'fade'
});
}
}
});
}
$submit_btn.parents( 'form' ).on('submit', function() {
submitFormFiles();
return false;
} );
// Clicking Next button
$next_btn.on( 'click', function ( e ) {
e.preventDefault();
var $tab_content = $( this ).parents( '.opalestate-tab-content' );
var empty_required_inputs = opalestate_get_empty_required_inputs( $tab_content );
if ( empty_required_inputs.length === 0 ) {
var $next_tab_content = $tab_content.next();
if ( $next_tab_content.length != 0 ) {
$submission_tab.find( '.opalestate-tab-content' ).removeClass( 'active' );
$submission_tab.find( '.tab-item.active' )
.removeClass( 'active' )
.addClass( 'validated' )
.addClass( 'passed' )
.next()
.addClass( 'active' );
$tab_content.addClass( 'validated' ).addClass( 'passed' );
$next_tab_content.addClass( 'active' );
$( 'html, body' ).animate( {
scrollTop: $next_tab_content.offset().top - 100
}, 500 );
// Show Save button if is last tab.
if ( $next_tab_content.is( ':last-child' ) ) {
$next_btn.hide();
$submit_btn.show();
}
}
}
} );
// Clicking Back button
$back_btn.on( 'click', function ( e ) {
e.preventDefault();
var $tab_content = $( this ).parents( '.opalestate-tab-content' );
$submission_tab.find( '.opalestate-tab-content' ).removeClass( 'active' );
$submission_tab.find( '.tab-item.active' )
.removeClass( 'active' )
.removeClass( 'passed' )
.prev()
.addClass( 'active' );
$tab_content.removeClass( 'active' );
var $prev_tab_content = $tab_content.prev();
if ( $prev_tab_content.length != 0 ) {
$prev_tab_content.addClass( 'active' ).removeClass( 'passed' );
$( 'html, body' ).animate( {
scrollTop: $prev_tab_content.offset().top - 100
}, 500 );
}
$submit_btn.hide();
$next_btn.show();
} );
$( '.tab-item' ).on( 'click', function ( e ) {
e.preventDefault();
var $el = $( this );
var $prev_tab_item = $el.prev();
if ( $el.hasClass( 'validated' ) || ($prev_tab_item.length != 0 && $prev_tab_item.hasClass( 'validated' ) &&
$prev_tab_item.hasClass( 'passed' )) ) {
$submission_tab.find( '.opalestate-tab-content' ).removeClass( 'active' );
$submission_tab.find( '.tab-item.active' ).removeClass( 'active' );
var $tab_id = $el.attr( 'href' );
var $prev_tab_content = $( $tab_id ).prev();
var $next_tab_content = $( $tab_id ).next();
if ( $prev_tab_content.length != 0 ) {
$back_btn.show();
} else {
$back_btn.hide();
}
if ( $next_tab_content.length != 0 ) {
$next_btn.show();
$submit_btn.hide();
} else {
$next_btn.hide();
$submit_btn.show();
}
$el.addClass( 'active' );
$( $tab_id ).addClass( 'active' );
}
} );
} );
function opalestate_get_empty_required_inputs( el_wrapper ) {
var empty_required_inputs = [];
el_wrapper.find( 'input' ).each( function () {
$( this ).removeClass( 'required' );
$( this ).blur();
if ( $( this ).prop( 'required' ) ) {
if ( $( this ).val() == '' ) {
$( this ).addClass( 'required' );
$( this ).focus();
empty_required_inputs.push( $( this ) );
}
}
} );
return empty_required_inputs;
}
$( '.opalestate-tab-content input' ).each( function ( e ) {
if ( $( this ).prop( 'required' ) ) {
$( this ).on( 'input', function () {
if ( $( this ).val() == '' ) {
$( this ).addClass( 'required' );
$( this ).focus();
} else {
$( this ).removeClass( 'required' );
}
} );
}
} );
} );

193
assets/js/frontend/uploader.js Executable file
View File

@@ -0,0 +1,193 @@
/* global tinymce, wpCookies, autosaveL10n, switchEditors */
// Back-compat
window.opalestate_uploader = function() {
return true;
};
/**
* @summary Adds autosave to the window object on dom ready.
*
* @since 3.9.0
*
* @param {jQuery} $ jQuery object.
* @param {window} The window object.
*
*/
( function( $, window ) {
/**
* @summary Auto saves the post.
*
* @since 3.9.0
*
* The object with all functions for autosave.
*/
function opalestate_uploader() {
$document = $( document );
function is_image_file( file ) {
const acceptedImageTypes = ['image/gif', 'image/jpeg', 'image/png'];
return file && acceptedImageTypes.includes(file['type'])
}
function check_number_files( file , i ) {
if( is_image_file(file) ) {
if( i+1 > opalesateJS.mfile_image ){
return false;
}
} else {
if( i+1 > opalesateJS.mfile_other ){
return false;
}
}
return true;
}
function check_filesize ( file , i ) {
if( is_image_file(file) ) {
if( file.size > opalesateJS.size_image ){
var myToast = $.toast({
heading: file.name,
text: opalesateJS.error_upload_size,
icon: 'error',
position: 'bottom-right',
hideAfter: 3500,
showHideTransition: 'fade'
});
return false;
} else {
return true;
}
} else {
return true;
}
}
/**
*
*/
function trigger_button_upload(){
var handleUpload = function ( _container ){
var file_btn = $( 'input.select-file', _container );
var allow_files = [];
// var all_selected = [];
var name = $(this).data( 'name' );
var issingle = $(_container).data('single');
var show_icon = $(_container).data( 'show-icon' );
var on_select_files = function ( files, _container ) {
if ( window.File && window.FileList && window.FileReader ) {
$(files).each( function( i, file ){
if( check_number_files( file, i+$(".uploader-item-preview",_container).length ) == false ){
return ;
}
if( check_filesize( file, i ) ) {
var picReader = new FileReader();
picReader.addEventListener("load", function ( event ) {
var input = '<div class="uploader-item-preview">';
var picFile = event.target;
if ( picFile.result ) {
if( show_icon == 1 ) {
input += '<div class="inner preview-icon"><span class="btn-close"></span><i class="fas fa-paperclip"></i> '+ file.name +' </div>';
} else {
input += '<div class="inner preview-image"><span class="btn-close"></span><img src="'+picFile.result+'"></div>';
}
}
input += '</div>';
var a = $(input) ;
if( issingle ){
$( ".uploader-item-preview", _container ).remove();
all_selected = [];
}
$( _container ).prepend( a );
a.prop( 'file', file );
} );
picReader.readAsDataURL( file );
}
} );
}
};
file_btn.on("change", function( event ){
on_select_files( event.target.files, _container, allow_files );
} );
$( _container ).on( "click", ".btn-close", function(){
if( confirm(opalesateJS.confirmed ) ){
if( $("input", $(this).parent().parent()).length ){
var rinput = $("<input type=\"hidden\" name=\"remove_image_id[]\" value=\""+ $("input", $(this).parent().parent()).val() +"\">");
$(_container).append( rinput );
}
$(this).parent().parent().remove();
}
} );
$( ".button-placehold", _container ).click( function(){
file_btn.trigger("click");
} );
}
$(".cmb2-uploader-files").each( function(){
handleUpload( this )
} );
// fix for submittion form
window.CMB2 = window.CMB2 || {};
window.CMB2.metabox().find('.cmb-repeatable-group').on( 'cmb2_add_row', function(i, row ) {
var _container = $( row );
if( $(".cmb2-uploader-files", _container ).length ) {
$( ".uploader-item-preview", _container ).remove();
$(".cmb2-uploader-files", _container ).each( function(){
var name = $( 'input', this ).attr('name');
$( this ).attr('data-name', name );
$(this).data( 'name', name );
handleUpload( this );
});
}
} );
}
function upload_attachments( name, files ) {
alert( name );
}
/**
* @summary Sets the autosave time out.
*
* Wait for TinyMCE to initialize plus 1 second. for any external css to finish loading,
* then save to the textarea before setting initialCompareString.
* This avoids any insignificant differences between the initial textarea content and the content
* extracted from the editor.
*
* @since 3.9.0
*
* @returns {void}
*/
$document.on( 'body', function( event, editor ) {
}).ready( function() {
trigger_button_upload();
});
return {
};
}
/** @namespace wp */
window.wp = window.wp || {};
window.wp.opalestate_uploader = opalestate_uploader();
}( jQuery, window ));