File: /home/salhiscp/salhab360photos.com/wp-content/plugins/fwdsisc/js/shortcode.js
/**
* SHortcode.
*
* @package fwdsisc
* @since fwdsisc 1.0
*/
jQuery(document).ready(function($) {
'use strict';
var presetId;
var playlistId;
var sisc_item_id;
var oppener;
var autoopen;
// Get data array.
fwdsicPresets_ar = unescapeHtml(fwdsicPresets_ar);
if(fwdsicPresets_ar == 'null'){
fwdsicPresets_ar = []
}else{
fwdsicPresets_ar = JSON.parse(fwdsicPresets_ar);
}
if(!fwdsicPresets_ar) fwdsicPresets_ar = [];
fwdsicPlaylists_ar = unescapeHtml(fwdsicPlaylists_ar);
if(fwdsicPlaylists_ar == 'null'){
fwdsicPlaylists_ar = []
}else{
fwdsicPlaylists_ar = JSON.parse(fwdsicPlaylists_ar);
}
if(!fwdsicPlaylists_ar) fwdsicPlaylists_ar = [];
$("#sisc_item_auto_open").val("no");
setTimeout(function(){
$("#fwdsisc_shortcode").val(getShortcode());
}, 600)
$.each(fwdsicPresets_ar, function(i, el){
$("#fwdsisc_presets_list").append("<option value='" + el.name + "'>" + el.name + "</option>");
});
$("#fwdsisc_presets_list").change(function(){
presetId = $("#fwdsisc_presets_list option:selected").val();
$("#fwdsisc_shortcode").val(getShortcode());
});
$('.fwdSISCInputFleds').each(function() {
var elem = $(this);
// Save current value of element
elem.data('oldVal', elem.val());
// Look for changes in the value
elem.bind("propertychange change click keyup input paste", function(event){
// If value has changed...
if (elem.data('oldVal') != elem.val()) {
// Updated stored value
elem.data('oldVal', elem.val());
$("#fwdsisc_shortcode").val(getShortcode());
}
});
});
function setShortodeIntext(){
if(fwdsicPlaylists_ar.length > 0){
$("#fwduvp_shortocde").val(getShortcode());
$("#fwduvp_shortocde").show();
}else{
$("#fwduvp_shortocde").hide();
}
}
$("#fwdsisc_div").hide();
if (fwdsicPlaylists_ar.length > 0){
$.each(fwdsicPlaylists_ar, function(i, el){
$("#fwdsisc_main_playlists_list").append("<option value='" + el.name + "'>" + el.name + "</option>");
});
$("#fwdsisc_main_playlists_list").change(function(){
playlistId = $("#fwdsisc_main_playlists_list option:selected").val();
$("#fwdsisc_shortcode").val(getShortcode());
});
}else{
var td = $("#fwdsisc_main_playlists_list").parent();
$("#fwdsisc_main_playlists_list").remove();
td.append("<em>No galleries are available.</em>");
$("#fwdsisc_presets_list").prop("disabled", true);
$("#fwdsisc_presets_list").css("cursor", "default");
$("#fwdsisc_shortcode").css({"opacity":".4", "pointer-events":"none"});
$("#id_or_class_input").prop("disabled", true);
$("#id_or_class_input").css("cursor", "default");
$("#sisc_item_id_input").prop("disabled", true);
$("#sisc_item_id_input").css("cursor", "default");
}
$("#fwdsisc_shortcode_btn").click(function(){
addShortcodeFinal();
return false;
});
function getShortcode(){
presetId = $("#fwdsisc_presets_list option:selected").val();
playlistId = $("#fwdsisc_main_playlists_list option:selected").val();
if(isNaN(sisc_item_id)) sisc_item_id = 0;
var shortcode = '[fwdsisc preset_id="' + presetId + '" playlist_id="' + playlistId + '"]';
return shortcode;
}
function addShortcodeFinal(){
var shortcode = getShortcode();
if (typeof tinymce != "undefined"){
var editor = tinymce.get("content");
if (editor && (editor instanceof tinymce.Editor) && ($("textarea#content:hidden").length != 0)) {
editor.selection.setContent(shortcode);
editor.save({no_events: true});
}else{
var text = $("textarea#content").val();
var select_pos1 = $("textarea#content").prop("selectionStart");
var select_pos2 = $("textarea#content").prop("selectionEnd");
var new_text = text.slice(0, select_pos1) + shortcode + text.slice(select_pos2);
$("textarea#content").val(new_text);
}
}else{
var text = $("textarea#content").val();
var select_pos1 = $("textarea#content").prop("selectionStart");
var select_pos2 = $("textarea#content").prop("selectionEnd");
var new_text = text.slice(0, select_pos1) + shortcode + text.slice(select_pos2);
$("textarea#content").val(new_text);
}
$("#fwdsisc_div").hide();
$("#fwdsisc_div").fadeIn(600);
$("#fwdsisc_msg").html("The shortcode has been added!");
return false;
}
// Utils.
function escapeHtml(str) {
var map = {
"&": "&",
"<": "<",
">": ">",
"\"": """,
"'": "'"
};
str = str.replace(/'/g, "\"");
return str.replace(/[&<>"']/g, function(m) { return map[m]; });
}
function unescapeHtml(str) {
var map = {
"&": "&",
"<": "<",
">": ">",
""": "\"",
"'": "'"
};
return str.replace(/(&|<|>|"|')/g, function(m) { return map[m]; });
}
function removeFirstAndLastChar(str){
str = str.substring(1);
str = str.slice(0, -1);
return str;
}
});