shuffle slider display - php

i have a problem on the slider of my site, though the slider works fine and good but i need it to be random or shuffle instead of displaying an ordered content..
i already have the code and it need some modification.
this is the line on the main file.php
<script type="text/javascript">
$(document).ready(function() {
$('#slider1').s3Slider({
timeOut: 8000
});
});
<div id="slider1">
<ul id="slider1Content">
<li class="slider1Image">
<img src="products/1.png" alt="1" />
<span class="left">
caption1
</span>
</li>
<li class="slider1Image">
<img src="products/2.png" alt="2" />
<span class="right">caption2
</span>
</li>
<li class="slider1Image">
<img src="products/3.png" alt="3" />
<span class="right">caption3.
</span>
</li></div>
this is the java script file
(function($){
$.fn.s3Slider = function(vars) {
var element = this;
var timeOut = (vars.timeOut != undefined) ? vars.timeOut : 4000;
var current = null;
var timeOutFn = null;
var faderStat = true;
var mOver = false;
var items = $("#" + element[0].id + "Content ." + element[0].id + "Image");
var itemsSpan = $("#" + element[0].id + "Content ." + element[0].id + "Image span");
items.each(function(i) {
$(items[i]).mouseover(function() {
mOver = true;
});
$(items[i]).mouseout(function() {
mOver = false;
fadeElement(true);
});
});
var fadeElement = function(isMouseOut) {
var thisTimeOut = (isMouseOut) ? (timeOut/2) : timeOut;
thisTimeOut = (faderStat) ? 10 : thisTimeOut;
if(items.length > 0) {
timeOutFn = setTimeout(makeSlider, thisTimeOut);
} else {
console.log("Poof..");
}
}
var makeSlider = function() {
current = (current != null) ? current : items[(items.length-1)];
var currNo = jQuery.inArray(current, items) + 1
currNo = (currNo == items.length) ? 0 : (currNo - 1);
var newMargin = $(element).width() * currNo;
if(faderStat == true)
{
if(!mOver) {
$(items[currNo]).fadeIn((timeOut/6), function() {
if($(itemsSpan[currNo]).css('bottom') == 0) {
$(itemsSpan[currNo]).slideUp((timeOut/6), function() {
faderStat = false;
current = items[currNo];
if(!mOver) {
fadeElement(false);
}
});
} else {
$(itemsSpan[currNo]).slideDown((timeOut/6), function() {
faderStat = false;
current = items[currNo];
if(!mOver) {
fadeElement(false);
}
});
}
});
}
} else {
if(!mOver) {
if($(itemsSpan[currNo]).css('bottom') == 0) {
$(itemsSpan[currNo]).slideDown((timeOut/6), function() {
$(items[currNo]).fadeOut((timeOut/6), function() {
faderStat = true;
current = items[(currNo+1)];
if(!mOver) {
fadeElement(false);
}
});
});
} else {
$(itemsSpan[currNo]).slideUp((timeOut/6), function() {
$(items[currNo]).fadeOut((timeOut/6), function() {
faderStat = true;
current = items[(currNo+1)];
if(!mOver) {
fadeElement(false);
}
});
});
}
}
}
}
makeSlider();
};})(jQuery);
i am struggling modifying this script for almost a week ... please help

Not sure if your still looking for a solution... I've just done this, but thought it would have been a better method to write the li tags out server side by calling them from a random array. That's if your using server side scriptiing - Below is what I did in php.
$arr = array("
Some text", "
Some text", "
Some text", );
$arrCnt = count($arr);
for ($i=0; $i<=$arrCnt; $i++)
{
$random = array_rand($arr);
echo "<li class='sliderImage'>";
echo $arr[$random];
echo "</li>\n";
if($i<$arrCnt-1)
unset($arr[$random]);
}
?>
Hope that helps.

Related

Joomla Interesting search module error!(SJ Filter for VirtueMart )

I would like to ask for help with the following topic!
We use SJ Filter for VirtueMart on our website! However the price filter uses price without tax. It's not good this way.I think the system uses the "base price" (without tax).I would like the filter use "end user price" with tax.(27.tax).I didn't find anything in the setting. I attached files from filter.I checked the code but I couldn't find anything that I could change.
Please someone help !
enter image description here
enter image description here
<?php
/**
* #package SJ Filter for VirtueMart
* #version 2.0.0
* #license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* #copyright (c) 2014 YouTech Company. All Rights Reserved.
* #author YouTech Company http://www.smartaddons.com
*/
defined ('_JEXEC') or die;
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function ($) {
;
(function (element) {
var $element = $(element),
$_ft_form = $('.ft-form', $element),
$_group_ft = $('.ft-group', $element),
$_filtering = $('.ft-filtering', $element)
$_ajax_url = '<?php echo (string)JURI::getInstance(); ?>';
var $_gr_prices = $('.ft-group-prices', $element),
$_slide_prices = $(".ft-slider-price", $_gr_prices),
_min_price = <?php echo (int)$params->get('price_min',0); ?>,
_max_price = <?php echo (int)$params->get('price_max',1300000); ?>;
var $timer = 0;
$_slide_prices.each(function (index, element) {
$(this)[index].slide = null;
});
$_slide_prices.slider({
range: true,
min: _min_price,
max: _max_price,
values: [_min_price, _max_price],
slide: function (event, ui) {
$(".ft-price-min", $_gr_prices).val(ui.values[0]);
$(".ft-price-max", $_gr_prices).val(ui.values[1]);
if ($timer) {
clearTimeout($timer);
}
$timer = setTimeout(
function () {
processAjax()
}, 1000);
}
});
$('.ft-price-input', $_gr_prices).on('keyup', function () {
var $that = $(this);
if ($timer) {
clearTimeout($timer);
}
var _price_tmp = parseInt($that.val());
$timer = setTimeout(function () {
if (!isNaN(_price_tmp) && _price_tmp >= 1) {
_price_tmp = _price_tmp >= _max_price ? _max_price : _price_tmp;
if ($that.hasClass('ft-price-min')) {
var _maxp = $(".ft-price-max", $_gr_prices).val();
_maxp = (_maxp != '' ) ? _maxp : _max_price;
_price_tmp = _price_tmp >= _maxp ? _maxp : _price_tmp;
$that.val(_price_tmp);
$_slide_prices.slider("values", 0, _price_tmp);
} else {
var _minp = $(".ft-price-min", $_gr_prices).val();
_minp = (_minp != '' ) ? _minp : _min_price;
_price_tmp = (_price_tmp >= _minp && _price_tmp <= _max_price ) ? _price_tmp : _minp;
$that.val(_price_tmp);
$_slide_prices.slider("values", 1, _price_tmp);
}
} else {
if ($that.hasClass('ft-price-min')) {
$that.val('');
$_slide_prices.slider("values", 0, _min_price);
} else {
$that.val('');
$_slide_prices.slider("values", 1, _max_price);
}
}
processAjax();
}, 1000);
});
// var $_open_close = $('.ft-open-close ', $_group_ft);
// $_open_close.on('click ', function () {
// var $_parent = $(this).parents('.ft-heading');
// $_parent.siblings('.ft-content').stop(true, false).slideToggle(400, function () {
// if ($_parent.parent().hasClass('ft-open')) {
// $_parent.parent().removeClass('ft-open').addClass('ft-close');
// }
// else {
// $_parent.parent().removeClass('ft-close').addClass('ft-open');
// }
// });
//
// });
var $_ft_heading = $('.ft-heading', $_group_ft);
$_ft_heading.on('click', function () {
$(this).siblings('.ft-content').stop(true, false).slideToggle(400, function () {
if ($(this).parent().hasClass('ft-open')) {
$(this).parent().removeClass('ft-open').addClass('ft-close');
} else {
$(this).parent().removeClass('ft-close').addClass('ft-open');
}
});
});
if ($('.ft-group', $element).width() <= 200) {
$('.sj-vm-filter .ft-content-prices .ft-price-value input[type="text"]').css('width', '38px');
}
//.ft-opt-count
var $_label_opt = $('.ft-opt-name, .ft-color-value', $_group_ft);
$_label_opt.on('click ', function () {
var _input_check = $(this).siblings('input[type="checkbox"]'),
_checked = _input_check.prop('checked'),
_color_value = $(this).is('.ft-color-value');
if (_checked) {
if (_color_value) {
$(this).removeClass('ft-checked');
}
_input_check.removeAttr('checked');
} else {
if (_color_value) {
$(this).addClass('ft-checked');
}
_input_check.attr('checked', 'checked');
}
processAjax();
});
function showClearAll() {
var $ft_content = $('.ft-content', $_group_ft);
$ft_content.each(function () {
var $that = $(this);
var $i = 0;
$(':input', $that).each(function () {
if ($(this).prop('checked')) {
$i++;
}
});
if ($i > 0) {
$('.ft-opt-clearall', $that).fadeIn(500);
} else {
$('.ft-opt-clearall', $that).fadeOut(500);
}
});
}
$('input[type="hidden"]', $element).val('');
$('input[type="hidden"]', $_group_ft).val('');
$(':checkbox ', $_group_ft).removeAttr('checked');
$(':checkbox ', $_group_ft).on('click', function () {
processAjax();
});
$('.ft-opt-clearall', $_group_ft).unbind('click.clearall').on('click.clearall', function () {
var _ft_select = $(this).siblings('.ft-select');
$('input[type="checkbox"]', _ft_select).removeAttr('checked');
$('.ft-color-value', _ft_select).removeClass('ft-checked');
processAjax();
});
var _config_global = '';
function processAjax() {
var fields = $(":input", $element).serialize();
_config_global = fields;
showClearAll();
var _loading = $('<div class="sj-loading" ><div class="ft-image-loading"></div></div>');
$("body").append(_loading);
$.ajax({
type: 'POST',
url: $_ajax_url,
data: {
is_ajax_ft: 1,
ft_module_id: <?php echo $module->id ?>,
_config_data: _config_global
},
success: function (data) {
_loading.remove();
if (data.items_markup != '') {
$('.ft-filtering', $_ft_form).replaceWith(data.items_markup);
updateAfterLoadAjax();
}
if (data.filter_product != '') {
if ($('<?php echo $params->get('area_results'); ?>').length) {
$('<?php echo $params->get('area_results'); ?>').html(data.filter_product);
updateAfterLoadAjax();
}
}
if (data == 'noresults') {
window.location.href = $_ajax_url;
}
},
error: function () {
_loading.remove();
},
dataType: 'json'
});
}
var parseQueryString = function (queryString) {
var params = {}, queries, temp, i, l;
queries = queryString.split("&");
for (i = 0, l = queries.length; i < l; i++) {
temp = queries[i].split('=');
params[temp[0]] = temp[1];
}
return params;
};
function updateAfterLoadAjax() {
if(typeof Virtuemart !== 'undefined'){
var $_form = $("form.product");
Virtuemart.product($_form);
}
var $_ft_result = $('#ft_results_<?php echo $module->id; ?>');
$('.orderlistcontainer', $_ft_result).hover(
function () {
$(this).find('.orderlist').stop().show()
},
function () {
$(this).find('.orderlist').stop().hide()
}
)
var $_orderList = $('.orderlist', $_ft_result);
if ($_orderList.length > 0) {
$_orderList.children().on('click', function () {
var _href = $('a ', $(this)).attr('href');
_href = _href.replace(/\?/g, '&').replace('by,', 'orderby=');
_href = _href.replace(/\//g, '&');
var _orderby = parseQueryString(_href);
$('.config-orderby', $element).attr('value', _orderby.orderby);
processAjax();
return false;
});
}
var $_selectbox = $('select.inputbox', $_ft_result);
var _limit = $('option:selected', $_selectbox).text();
$('option:selected', $_selectbox).each(function(){
var _limit = $(this).text();
$('.config-limit', $element).attr('value', _limit);
$_selectbox.removeAttr('onchange');
$_selectbox.on('change', function () {
var _value = $('option:selected', $(this)).text();
$('.config-limit', $element).attr('value', _value);
processAjax();
return false;
});
});
//add product_load_limit last run processAjax() in select box
var pro_load = "<?php echo $params->get('limit_results',5)?>";
var url_option = "<?php echo JURI::base(true).'/?limit=';?>";
var _option = '<option value="' + url_option + pro_load + '">' + pro_load + '</option>';
var $_selectbox_2 = $('select.inputbox option:first', $_ft_result);
if ($_selectbox_2.text() != pro_load) {
$_selectbox_2.before(_option);
}
var $vm_pagination = $('.vm-pagination ul', $_ft_result);
if ($vm_pagination.length > 0) {
$vm_pagination.children().on('click', function () {
var $this = $(this);
if ($this.is('.disabled') || $this.is('.active')) {
return false;
} else {
var _href = $('a ', $(this)).attr('href');
_href = _href.replace(/\?/g, '&').replace('results,', 'limit_start=');
_href = _href.replace(/\//g, '&');
var _lmstart = parseQueryString(_href);
var _start = 0;
if (typeof _lmstart.limit_start != 'undefined') {
_start = _lmstart.limit_start
_start = _start.split("-");
_start = _start[1];
} else if (typeof _lmstart.start != 'undefined') {
_start = _lmstart.start;
}
$('.config-limitstart', $element).attr('value', _start);
processAjax();
}
return false;
});
}
// Click Button
function display(view) {
jQuery('.browse-view .row').removeClass('vm-list vm-grid').addClass(view);
jQuery('.icon-list-grid .vm-view').removeClass('active');
if(view == 'vm-list') {
jQuery('.browse-view .product').addClass('col-lg-12 product-full');
jQuery('.browse-view .product .product-left').addClass('col-md-4');
jQuery('.browse-view .product .product-right').addClass('col-md-8');
jQuery('.icon-list-grid .' + view).addClass('active');
}else{
jQuery('.browse-view .product').removeClass('col-lg-12 product-full');
jQuery('.browse-view .product .product-left').removeClass('col-md-4');
jQuery('.browse-view .product .product-right').removeClass('col-md-8');
jQuery('.icon-list-grid .' + view).addClass('active');
}
}
jQuery('.vm-view-list .vm-view').each(function() {
var ua = navigator.userAgent,
event = (ua.match(/iPad/i)) ? 'touchstart' : 'click';
jQuery('.vm-view-list .vm-view').bind(event, function() {
jQuery(this).addClass(function() {
if(jQuery(this).hasClass('active')) return '';
return 'active';
});
jQuery(this).siblings('.vm-view').removeClass('active');
catalog_mode = jQuery(this).data('view');
display(catalog_mode);
});
});
var $_filtering = $('.ft-filtering', $element), _ft_opt_close = $('.ft-opt-close', $_filtering),
_filtering_clearall = $('.ft-filtering-clearall', $_filtering);
_ft_opt_close.on('click', function () {
var _data_value = $(this).parent().attr('data-filter'),
_cls_ft = $('.' + _data_value);
if (_cls_ft.length > 0) {
$(':checkbox', _cls_ft).removeAttr('checked');
$(_cls_ft).attr('value', '');
$('.ft-color-value', _cls_ft).removeClass('ft-checked');
processAjax();
}
});
_filtering_clearall.on('click', function () {
var _opt_inner = $('.ft-opt-inner', $_filtering);
if (_opt_inner.length > 0) {
_opt_inner.each(function () {
var _data_value = $(this).attr('data-filter'),
_cls_ft = $('.' + _data_value);
$(':checkbox', _cls_ft).removeAttr('checked');
$(_cls_ft).attr('value', '');
$('.ft-color-value', _cls_ft).removeClass('ft-checked');
});
processAjax();
}
});
}
})('#<?php echo $tag_id; ?>');
});
//]]>
</script>

Event not triggering until 3rd click

I have a filter by alphabet within a WordPress website that I would like to filter when the letter is selected without the user having to select the letter and then the search button. However it only seems to work after the 3rd click and that is if you click quickly. The filter itself is a customisation for an existing WordPress directory theme, here is a link to the directory: https://staging.pata.org.uk/item/. How can I get the click to trigger on the first click of a letter rather than the third?
This is the jquery:
<script type="text/javascript">
jQuery(document).ready(function(){
// filter type actions
// checkbox
jQuery('.advanced-filters-wrap-letter ul li.filter-checkbox-letter').on('click', function(e){
jQuery(this).toggleClass('filter-enabled');
var $input = jQuery(this).find('input');
if($input.is(':checked')){
$input.removeAttr('checked');
} else {
$input.attr('checked', true);
}
// filter submit actions
jQuery('.filter-container').on('click', function(e){
e.preventDefault();
// build new query
var addToFilter = "";
var filterString = "";
var filterCheck = 0;
// &filters=id;id;id
jQuery('.advanced-filters-wrap ul li').each(function(){
var $inputOne = jQuery(this).find('input');
if($inputOne.is(':checked')){
addToFilter = $inputOne.val() + " ";
filterCheck += 1;
}
});
jQuery('.advanced-filters-wrap-letter ul li').each(function(){
var $input = jQuery(this).find('input');
if($input.is(':checked')){
filterString = filterString + $input.val() + " " + addToFilter;
filterCheck += 1;
}
});
filterString = filterString.trim().replace(new RegExp(' ', 'g'), ";");
var pathName = window.location.pathname;
/* remove page parameter from url */
pathName = pathName.replace(new RegExp("page\/[0-9]*\/", 'g'), "");
/* remove page parameter from url */
var baseUrl = window.location.protocol+"//"+window.location.host+pathName;
var eParams = window.location.search.replace("?", "").split('&');
var nParams = {};
jQuery.each(eParams, function(index, value){
var val = value.split("=");
if(typeof val[1] == "undefined"){
nParams[val[0]] = "";
} else {
nParams[val[0]] = decodeURIComponent(val[1]);
}
});
var query = jQuery.extend({}, nParams, { filters: filterString });
if(filterCheck == 0){
delete query.filters;
}
delete query.paged;
delete query.count;
// remove empty keys
jQuery.each(query, function(k, v){
if(!k){
delete query[k];
}
});
var queryString = jQuery.param(query);
window.location.href = baseUrl + "?" + queryString;
});
});
});
</script>
and this is the rest of the code
<?php
// &filters=id;id;id;id
$themeOptions = aitOptions()->getOptionsByType('theme');
$advancedFiltersOptions = (object)$themeOptions['itemAdvancedFilters'];
if($advancedFiltersOptions->enabled){
$filters_avalaible = get_terms('ait-items_filters', array('hide_empty' => false));
$filters_enabled = array();
if(isset($_REQUEST['filters']) && !empty($_REQUEST['filters'])){
$filters_enabled = explode(";",$_REQUEST['filters']);
}
if($query->max_num_pages != 1){
// check if there will be pagination
$item_query_args = $query->query_vars; // populate new variable ... dont modify original query
$item_query_args['nopaging'] = true;
$item_query = new WP_Query($item_query_args);
} else {
$item_query = $query;
}
$item_filters = array();
foreach($item_query->posts as $post){
$post_meta = get_post_meta( $post->ID, '_ait-item_filters-options');
if(!empty($post_meta)){
$post_filters = $post_meta[0]['filters'];
foreach ($post_filters as $id) {
$filter = get_term($id, 'ait-items_filters', "OBJECT");
if(!empty($filter)){
array_push($item_filters, $filter);
}
}
}
}
$unique_filters = array_map("unserialize", array_unique(array_map("serialize", $item_filters)));
$filters_avalaible = $unique_filters;
usort($filters_avalaible, function($a, $b){
return strcmp($a->slug, $b->slug);
});
?>
<?php
if(is_array($filters_avalaible) && count($filters_avalaible) > 0){
?>
<div class="advanced-filters-wrap-letter">
<div class="advanced-filters-container">
<div class="content">
<h3>Alphabetical</h3>
<ul class="advanced-filters columns-<?php echo $advancedFiltersOptions->filterColumns ?>">
<?php
$array=array("A", "B", "C", "D", "E", "F","G","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$letters = array();
foreach($filters_avalaible as $filter){
if(in_array($filter->name,$array)) {
array_push($letters, $filter);
}
}
?>
<?php
foreach($letters as $letter)
{
if(!empty($letter))
{
$filter_options = get_option( "ait-items_filters_category_".$letter->term_id );
$filter_type = isset($filter_options['type']) ? $filter_options['type'] : 'checkbox';
$is_enabled = in_array($letter->term_id, $filters_enabled);
$li_class = "";
$in_checked = "";
if($is_enabled){
$li_class = "filter-enabled";
$in_checked = "checked";
}
switch($filter_type){
case 'checkbox':
/*$imageClass = !empty($filter_options['icon']) ? 'has-image' : '';*/
$imageClass = 'has-image';
$image = !empty($filter_options['icon']) ? '<i class="fa '.$filter_options['icon'].'"></i>' : '<i class="fa fa-dot-circle-o"></i>';
echo '<li class="filter-container filter-checkbox-letter '.$li_class.' '.$imageClass.' "><input type="checkbox" name="'.$letter->slug.'" value="'.$letter->term_id.'" '.$in_checked.'> <span class="filter-name">'.$letter->name.'</span></li>';
break;
default:
echo '<li class="filter-container filter-unsupported">'.__('Unsupported filter', 'ait-advanced-filters').'</li>';
break;
}
}}}?>
</ul>
</div>
</div>
<div class="advanced-filters-actions">
<?php _e('Search', 'ait') ?>
Back
</div>
</div>
<?php
}

Webrtc working fine on lan & local But not working on internet

I have made an webrtc program which is working fine on intranet but not working on internet. I have made the firewall of router to off now don't know what is getting wrong.
Here is my code:
<?php
global $db;
if(isset($_REQUEST['room_id'])){
$room_id=$_REQUEST['room_id'];
require_once 'modules/Conferencingrooms/Conferencingroom.php';
$conferencingroom=new Conferencingroom();
$conferencingroom->retrieve($room_id);
$branch_id=$conferencingroom->branch_id;
}
else{
sugar_die('Error! Access is Denind');
}
?>
<script>
if (window.location.protocol != "https:")
window.location.href = "https:" + window.location.href.substring(window.location.protocol.length);
</script>
<video src="" id="localVideo" style="border:1px red dotted">Patient Video</video>
<video src="" id="remoteVideo" style="border:1px red dotted">Doctor Video</video>
<script>
var pc;
var callNo = '<?php echo $room_id;?>'; // 0 indicates callNo not initialised yet
var caller = <?php if($branch_id==$current_user->branch_id) echo 'true';else echo 'false'?>;
if (caller) {
$("#ajaxStatusDiv").show();
}
var video_constraints={
mandatory:{
maxWidth:320,
maxHeight:320,
maxAspectRatio:16/8,
maxFrameRate:500,
}
}
navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia.bind(navigator);;
navigator.getUserMedia({audio: true, video: true}, onUserMediaSuccess, onUserMediaError);
function onUserMediaSuccess(stream) {
document.getElementById('localVideo').src = webkitURL.createObjectURL(stream);
document.getElementById('localVideo').play();
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
pc = new PeerConnection({iceServers: [ {url:'stun:stun01.sipphone.com'},
{url:'stun:stun.ekiga.net'},
{url:'stun:stun.fwdnet.net'},
{url:'stun:stun.ideasip.com'},
{url:'stun:stun.iptel.org'},
{url:'stun:stun.rixtelecom.se'},
{url:'stun:stun.schlund.de'},
{url:'stun:stun.l.google.com:19302'},
{url:'stun:stun1.l.google.com:19302'},
{url:'stun:stun2.l.google.com:19302'},
{url:'stun:stun3.l.google.com:19302'},
{url:'stun:stun4.l.google.com:19302'},
{url:'stun:stunserver.org'},
{url:'stun:stun.softjoys.com'},
{url:'stun:stun.voiparound.com'},
{url:'stun:stun.voipbuster.com'},
{url:'stun:stun.voipstunt.com'},
{url:'stun:stun.voxgratia.org'},
{url:'stun:stun.xten.com'},
{
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: 'webrtc#live.com'
},
{
url: 'turn:192.158.29.39:3478?transport=udp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
},
{
url: 'turn:192.158.29.39:3478?transport=tcp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
}]});
pc.preventSSLAutoAllowed = false;
pc.autoReDialOnFailure = true;
pc.setDefaultEventsForMediaElement = false;
pc.addStream(stream);
pc.onicecandidate = function (evt) {
console.log('On Ice Candidate');
console.log(evt.candidate);
if (!evt.candidate) {
console.log('inner');
pc.onicecandidate = null;
if (pc.localDescription) postLocalData();
}
};
pc.onaddstream = function(evt) {
document.getElementById('remoteVideo').src = webkitURL.createObjectURL(evt.stream);
document.getElementById('remoteVideo').play();
};
if (caller){
console.log('Create Offer called');
pc.createOffer(onDescCreated, onCreateOfferError);
}
else {
getRemoteData();
}
window.onbeforeunload = function() {
/*
stream.stop();
if (caller && callNo > 0) navigator.sendBeacon('deleteCall.php', callNo);
*/
};
}
function onUserMediaError(err) {
if(err.name=='DevicesNotFoundError'){
alert('Media device is not connected');}
console.log('User media error: ' + err.name);
}
function onCreateOfferError(err) {
logError('Error creating offer: ' + err.name);
}
function onDescCreated(desc) {
pc.setLocalDescription(desc, onLocalDescSuccess, onLocalDescError);
}
function onLocalDescSuccess() {
if(caller)
console.log('offer create success');
if (pc.iceGatheringState == 'complete') {
if(caller)
{
console.log('Send for store sdp for caller');
}
else{
console.log('Send for store sdp for callee');
}
postLocalData();
}
}
function onLocalDescError(err) {
logError("Local description could not be created: " + err.name);
}
function postLocalData() {
console.log('Storing local sdp');
var xhr = new XMLHttpRequest();
var sdp=pc.localDescription.sdp;
xhr.open('POST', 'index.php?module=Conferencingrooms&action=AjaxCalls&storeSdp=true&caller='+caller);
xhr.onload = (caller ? getRemoteData : waitForConnection);
xhr.send(callNo + '~' + sdp);
}
function getRemoteData() {
console.log("Checking db for remote sdp");
var xhr = new XMLHttpRequest();
xhr.open('GET', 'index.php?module=Conferencingrooms&action=AjaxCalls&fetchSdp=true&caller='+caller+'&callNo=' + callNo);
xhr.onload = processRemoteData;
xhr.send();
}
function processRemoteData() {
if (this.response) {
var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
var sdp = new SessionDescription();
sdp.type = (caller ? 'answer' : 'offer');
sdp.sdp = this.response;
console.log('Processing remote sdp: ' + sdp);
pc.setRemoteDescription(sdp, onRemoteDescSuccess, onRemoteDescError);
}
else
setTimeout(getRemoteData, 1000);
}
function onRemoteDescSuccess() {
console.log("Remote sdp successfully set");
if (caller) {
waitForConnection();
}
else
pc.createAnswer(onDescCreated, onCreateAnswerError);
}
function onRemoteDescError(err) {
logError("Remote description could not be set: " + err.name);
}
function onCreateAnswerError(err) {
logError("Error creating answer: " + err.name);
}
function waitForConnection() {
console.log('Waiting');
if (pc.iceConnectionState == 'connected' || pc.iceConnectionState == 'completed') {
console.log('Waitingdsadsd');
logError('Connection complete');
caller = null;
document.getElementById('remoteVideo').ondblclick = function() {
this.requestFullscreen = this.mozRequestFullScreen || this.webkitRequestFullscreen;
this.requestFullscreen();
}
}
else
setTimeout(waitForConnection, 1000);
}
function logError(msg) {
console.log(msg);
if (caller && callNo > 0) navigator.sendBeacon('deleteCall.php', callNo);
}
</script>
This is an php signalling version in which room is created on passing room id in the url

flexiquote rotator custom tweak

I'm using flexiquoterotator for word press I tweaked it to show the next and previous button following is my code
function ($) {
var callquote;
quoteRotator = {
i: 1,
quotes: [";
$i=0;
foreach($results as $result){
echo "\"$openquote<span id='quote'>$result->quote</span>$closequote";
if($result->author != '')
echo " <span id='quoteauthor'>$result->author</span>";
echo "\",\n";
$i++;
}
],
numQuotes: ".$i.",
fadeDuration: ".$fade.",
fadeoutDuration: ".$fadeout.",
delay: ".$delay.",
quotesInit: function(){
if (this.numQuotes < 1){
document.getElementById('quoterotator').innerHTML=\"No Quotes Found\";
} else {
this.navQuote();
this.quoteRotate();
this.quotehover();
}
},
navQuote: function() {
$('<div id=\"quotenav\"></div>').insertAfter('#quotearea');
for (n=1; n <= this.numQuotes ; n++) {
}
$('#quotenav').append('<span onclick=\"quoteRotator.callQuote(this,'+n+')\">Next</span>');
for (k= -3; k <= this.numQuotes ; k++) {
}
$('#quotenav').append('<span id=\"test\" onclick=\"quoteRotator.callQuote(this,'+k+')\">Prev</span>');
// insert style
$('head').append('<style type=\"text/css\">#quotenav {display: block;text-align: center;font-size: 50px;color: #000;}#quotenav span {margin: 0 3px;cursor: pointer;}#quotenav span.active,#quotenav span:hover{color: red;}</style>');
},
quoteRotate: function(i){
if(!i) {
i = this.i;
}
$('#quotenav span').each(function () {
$(this).removeClass('active');
});
$('#quotenav span:nth-child('+i+')').addClass('active');
jQuery('#quoterotator').hide().html(this.quotes[i - 1]).fadeIn(this.fadeDuration * 1000).css('filter','');
this.i = i % (this.numQuotes) + 1;
callquote = setTimeout('quoteRotator.quoteRotate()', (this.delay + this.fadeDuration) * 1000);
},
callQuote: function(e,n) {
clearTimeout(callquote);
this.quoteRotate(n);
},
quotehover: function() {
jQuery('#quotearea').mouseenter(function () {
clearTimeout(callquote);
}).mouseleave(function(){
setTimeout('quoteRotator.quoteRotate()', 500);
});
}
}
})(jQuery);
The above code doesn't shows the next and prev buttons instead it works for dot base navigation.
I Changed the location for buttons and it worked.

How to submit an iframe sub-form within main form using jQuery/AJAX?

I am using a jQuery plugin called Stepy, which is based of the FormToWizard plugin, to allow users to complete a 10-step form.
Using the next/back attributes, I've added a function to post data between steps so the user can save their work and come back at a later day if they'd like.
One of my steps allows the user to add items to a form within an iframe (to post data to a separate table). I'd like it to function so that when the user moves between steps, the items in the iframe post to their separate table as well. Is there a way to submit the form within the iframe between steps (i.e. submit iframe sub-form when main form submits)?
I am using PHP and MySQL.
Any help you could provide would be amazing!
Javascript:
$(function() {
$('#custom').stepy({
backLabel: 'Back',
block: true,
errorImage: true,
nextLabel: 'Next',
titleClick: true,
validate: false,
legend: false,
back: function(index) {
$.post('../../process.php')
}
next: function(index) {
$.post('../../process.php')
}
});
});
HTML:
<html>
<body>
<form id="custom" name="custom">
<fieldset title="Thread 1">
<legend>description one</legend>
<label>Question A:</label>
<input type="text" id="question_a" name="question_a" class="required">
<label>Question B:</label>
<input type="text" id="question_b" name="question_b">
</fieldset>
<fieldset title="Thread 2">
<legend>description two</legend>
<iframe src="../../list_form.php" width="100%" height="300"></iframe>
</fieldset>
<fieldset title="Thread 3">
<legend>description three</legend>
<label>Question C:</label>
<input type="text" id="question_c" name="question_c" class="required">
</fieldset>
<input type="submit" class="finish" value="Finish!">
</form>
</body>
</html>
iframe
<html>
<body>
<form id="sub_form" name="sub_form">
<label>Question 1:</label>
<input type="text" id="question_1" name="question_1">
<label>Question 2:</label>
<input type="text" id="question_2" name="question_2">
</form>
</body>
</html>
stepy.js
;(function($) {
var methods = {
init: function(options) {
return this.each(function() {
var opt = $.extend({}, $.fn.stepy.defaults, options),
$this = $(this).data('options', opt),
id = $this.attr('id');
if (id === undefined) {
id = 'stepy-' + $this.index();
$this.attr('id', id);
}
var $titlesWrapper = $('<ul/>', { id: id + '-titles', 'class': 'stepy-titles' });
if (opt.titleTarget) {
$(opt.titleTarget).html($titlesWrapper);
} else {
$titlesWrapper.insertBefore($this);
}
if (opt.validate) {
$this.append('<div class="stepy-error"/>');
}
var $steps = $this.children('fieldset'),
$step = undefined,
$legend = undefined,
description = '',
title = '';
$steps.each(function(index) {
$step = $(this);
$step
.addClass('step')
.attr('id', id + '-step-' + index)
.append('<p id="' + id + '-buttons-' + index + '" class="' + id + '-buttons"/>');
$legend = $step.children('legend');
if (!opt.legend) {
$legend.hide();
}
description = '';
if (opt.description) {
if ($legend.length) {
description = '<span>' + $legend.html() + '</span>';
} else {
$.error(id + ': the legend element of the step ' + (index + 1) + ' is required to set the description!');
}
}
title = $step.attr('title');
title = (title != '') ? '<div>' + title + '</div>': '--';
$titlesWrapper.append('<li id="' + id + '-title-' + index + '">' + title + description + '</li>');
if (index == 0) {
if ($steps.length > 1) {
methods.createNextButton.call($this, index);
}
} else {
methods.createBackButton.call($this, index);
$step.hide();
if (index < $steps.length - 1) {
methods.createNextButton.call($this, index);
}
}
});
var $titles = $titlesWrapper.children();
$titles.first().addClass('current-step');
var $finish = $this.children('.finish');
if (opt.finishButton) {
if ($finish.length) {
var isForm = $this.is('form'),
onSubmit = undefined;
if (opt.finish && isForm) {
onSubmit = $this.attr('onsubmit');
$this.attr('onsubmit', 'return false;');
}
$finish.click(function(evt) {
if (opt.finish && !methods.execute.call($this, opt.finish, $steps.length - 1)) {
evt.preventDefault();
} else {
if (isForm) {
if (onSubmit) {
$this.attr('onsubmit', onSubmit);
} else {
$this.removeAttr('onsubmit');
}
var isSubmit = $finish.attr('type') == 'submit';
if (!isSubmit && (!opt.validate || methods.validate.call($this, $steps.length - 1))) {
$this.submit();
}
}
}
});
$finish.appendTo($this.find('p:last'));
} else {
$.error(id + ': element with class name "finish" missing!');
}
}
if (opt.titleClick) {
$titles.click(function() {
var array = $titles.filter('.current-step').attr('id').split('-'), // TODO: try keep the number in an attribute.
current = parseInt(array[array.length - 1], 10),
clicked = $(this).index();
if (clicked > current) {
if (opt.next && !methods.execute.call($this, opt.next, clicked)) {
return false;
}
} else if (clicked < current) {
if (opt.back && !methods.execute.call($this, opt.back, clicked)) {
return false;
}
}
if (clicked != current) {
methods.step.call($this, (clicked) + 1);
}
});
} else {
$titles.css('cursor', 'default');
}
$steps.delegate('input[type="text"], input[type="password"]', 'keypress', function(evt) {
var key = (evt.keyCode ? evt.keyCode : evt.which);
if (key == 13) {
evt.preventDefault();
var $buttons = $(this).parent().children('.' + id + '-buttons');
if ($buttons.length) {
var $next = $buttons.children('.button right-aligned');
if ($next.length) {
$next.click();
} else {
var $finish = $buttons.children('.finish');
if ($finish.length) {
$finish.click();
}
}
}
}
});
$steps.first().find(':input:visible:enabled').first().select().focus();
});
}, createBackButton: function(index) {
var $this = this,
id = this.attr('id'),
opt = this.data('options');
$('<a/>', { id: id + '-back-' + index, href: 'javascript:void(0);', 'class': 'button left-aligned', html: opt.backLabel }).click(function() {
if (!opt.back || methods.execute.call($this, opt.back, index - 1)) {
methods.step.call($this, (index - 1) + 1);
}
}).appendTo($('#' + id + '-buttons-' + index));
}, createNextButton: function(index) {
var $this = this,
id = this.attr('id'),
opt = this.data('options');
$('<a/>', { id: id + '-next-' + index, href: 'javascript:void(0);', 'class': 'button right-aligned', html: opt.nextLabel }).click(function() {
if (!opt.next || methods.execute.call($this, opt.next, index + 1)) {
methods.step.call($this, (index + 1) + 1);
}
}).appendTo($('#' + id + '-buttons-' + index));
}, execute: function(callback, index) {
var isValid = callback.call(this, index + 1);
return isValid || isValid === undefined;
}, step: function(index) {
index--;
var $steps = this.children('fieldset');
if (index > $steps.length - 1) {
index = $steps.length - 1;
}
var opt = this.data('options');
max = index;
if (opt.validate) {
var isValid = true;
for (var i = 0; i < index; i++) {
isValid &= methods.validate.call(this, i);
if (opt.block && !isValid) {
max = i;
break;
}
}
}
$steps.hide().eq(max).show();
var $titles = $('#' + this.attr('id') + '-titles').children();
$titles.removeClass('current-step').eq(max).addClass('current-step');
if (this.is('form')) {
var $fields = undefined;
if (max == index) {
$fields = $steps.eq(max).find(':input:enabled:visible');
} else {
$fields = $steps.eq(max).find('.error').select().focus();
}
$fields.first().select().focus();
}
if (opt.select) {
opt.select.call(this, max + 1);
}
return this;
}, validate: function(index) {
if (!this.is('form')) {
return true;
}
var $step = this.children('fieldset').eq(index),
isValid = true,
$title = $('#' + this.attr('id') + '-titles').children().eq(index),
opt = this.data('options'),
$this = this;
$($step.find(':input:enabled').get().reverse()).each(function() {
var fieldIsValid = $this.validate().element($(this));
if (fieldIsValid === undefined) {
fieldIsValid = true;
}
isValid &= fieldIsValid;
if (isValid) {
if (opt.errorImage) {
$title.removeClass('error-image');
}
} else {
if (opt.errorImage) {
$title.addClass('error-image');
}
$this.validate().focusInvalid();
}
});
return isValid;
}
};
$.fn.stepy = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist!');
}
};
$.fn.stepy.defaults = {
back: undefined,
backLabel: '< Back',
block: false,
description: true,
errorImage: false,
finish: undefined,
finishButton: true,
legend: true,
next: undefined,
nextLabel: 'Next >',
titleClick: false,
titleTarget: undefined,
validate: false,
select: undefined
};
})(jQuery);
If you want to append Text\HTML or any other data to your iframe (which calling to a page on the same domain!) you may use:
jQuery("#iframe_id").contents().find('body').append('<div>Hello World</div>');
Full Example:
Full Example
If your iframe is on another domain you will have to use window.postMessage, which you may read about on Mozilla's docs:
Mozilla's docs
OR to take a look about my blog post about this subject.
Hope I helped,

Categories