I have a code that fetches the categorized posts, but the code when adding 150 posts or above is slow to fetch posts. This is the code
if(-1 < e.indexOf("://")) return (-1 < e.indexOf("://www.") ? e.split("://www.") : e.split("://"))[1].split(".")[0]
}
$(document).ready(function() {
$.each($(".emped-tv .views"), function(e, t) {
var a = $(this),
i = new Firebase("https://episode-viewer.firebaseIO.com/pages/id/" + a.attr("data-id"));
i.once("value", function(e) {
var t = e.val(),
e = !1;
null == t && ((t = {
value: 0
}).url = window.location.href, t.id = a.attr("data-id"), e = !0), a.html('<i class="fa fa-eye" aria-hidden="true"></i> ' + t.value), t.value++, "/" != window.location.pathname && (e ? i.set(t) : i.child("value").set(t.value))
})
}), $(".episodes-get").each(function() {
for(var e = $(this).find(".server-get i"), t = "", a = "", i = 0; i < e.length; i++) {
var s, n, o = e[i].textContent,
r = o.split("*");
r[1] ? (s = r[1], n = r[0], 0) : (s = i + 1, n = o);
o = smart_domain(n);
null == o && (o = "سيرفر مشاهدة"), 0 == i ? (t += '<a class="server-link active waves-effect waves-light" href="' + n + '" target="abdoutech">' + o + '<span class="server-num">' + s + '<i class="fa fa-play"></i></span></a>', a += '<iframe allowfullscreen="" class="embed-item" frameborder="0" height="1080" marginheight="0" marginwidth="0" name="abdoutech" scrolling="no" src="about:blank" width="1920"></iframe>') : t += '<a class="server-link waves-effect waves-light" href="' + n + '" target="abdoutech">' + o + '<span class="server-num">' + s + '<i class="fa fa-play"></i></span></a>'
}
$(".embed-responsive").append(a), $("#servers-content").html(t), $(".embed-responsive .play").click(function() {
$(".embed-item").attr("src", $(".server-link.active").attr("href")), $(this).remove()
}), $(".server-link").click(function() {
$(".server-link").removeClass("active"), $(this).addClass("active")
}), $(".tabs-content button").click(function(e) {
e.preventDefault();
var t = $(this),
e = $(this).data("content");
$(".tabs-content button,.content-div").removeClass("active"), t.toggleClass("active"), $("#" + e).toggleClass("active")
});
for(var l = $(this).find(".download-get i"), c = "", i = 0; i < l.length; i++) {
var d, f, v = l[i].textContent,
p = v.split("*"),
h = "";
p[1] ? (f = d = p[1], h = smart_domain(m = p[0])) : (d = "", h = smart_domain(m = v), f = "fa fa-download");
var m = encode_be64(m, $(".home-anime").text(), $(this).attr("number-episode"));
c += l ? '<a class="waves-effect waves-light" href="' + m + '" target="_blank"><span class="icon-M ' + f + '">' + d + "</span> " + h + "</a>" : "لايوجد روابط تحميل"
}
$("#download-content").html('<div class="outer-download">' + c + "</div>");
var u = $(".home-anime").text(),
g = document.location.origin + u;
$.get(g, function(e) {
var t = $(e).find(".info-post .rating").text();
$(".emped-tv .details .info h3.rat").html(t + "/10");
t = $(e).find(".info-post .date").text();
$(".emped-tv .details .info h3.release").html(t);
t = $(e).find(".main-posts .post-outer .thumb img").attr("src"), e = $(e).find(".titlepost").text();
$(".emped-tv .info-container a.cover").attr("href", g).html('<img alt="' + e + '" class="cover" src="' + t + '">'), $(".emped-tv .details .info h1").html('<a title="' + e + '" href="' + g + '">' + e + "</a>")
}, "html"), $(".info-container").removeClass("hide")
}), $("[name-anime]").each(function() {
var m = $("#episodes-content"),
e = $(this).attr("name-anime");
$.ajax({
type: "GET",
url: "https://www.blogger.com/feeds/" + idblogger + "/posts/default/-/" + e + "?alt=json-in-script&max-results=" + numposts,
dataType: "jsonp",
success: function(e) {
var t = "",
a = "";
if(e.feed.entry) {
for(var i = 0; i < e.feed.entry.length; i++) {
for(var s = 0; s < e.feed.entry[i].link.length; s++)
if("alternate" == e.feed.entry[i].link[s].rel) {
var n = e.feed.entry[i].link[s].href;
break
} var o, r, l = e.feed.entry[i].title.$t,
c = e.feed.entry[i].content.$t,
d = $(c).find(".episodes-get").attr("number-episode"),
f = "";
d && (o = d.split("."), c = d.split("-"), o[1] || (c[1] ? (d = c[0], f = " - " + c[1]) : d = (d = d.match(/\d/g)).join(""))), r = d ? " الحلقة : " + d + f : (r = l, ""), t += n == $($("html").html()).filter('meta[property="og:url"]').attr("content") ? '<a data-position="' + d + '" class="active waves-effect" href="' + n + '" ><i class="fa fa-pause"></i> ' + r + "</a>" : '<a data-position="' + d + '" class="waves-effect" href="' + n + '" ><i class="fa fa-play-circle"></i> ' + r + "</a>", a += '<option data-position="' + d + '" value="' + n + '">' + r + "</option>"
}
m.html('<div class="episodes-list">' + t + "</div>"), m.append('<select class="ep-select" onchange="if (this.value) window.location.href=this.value">' + a + "</select>"), $(".episodes-list a").sort(function(e, t) {
return $(t).data("position") > $(e).data("position") ? 1 : -1
}).appendTo(".episodes-list"), $(".ep-select option").sort(function(e, t) {
return $(t).data("position") > $(e).data("position") ? 1 : -1
}).appendTo(".ep-select");
var v = $(".episodes-get").attr("number-episode");
$('option[data-position="' + v + '"]').attr("selected", "selected");
var p = $("option[value*='" + location.pathname + "']"),
h = (p.text(), p.next().attr("value")),
v = p.prev().attr("value"),
p = $(".episodesfastReach"),
v = (h ? '<li ><a class="waves-effect" href="' + h + '">الحلقة السابقة</a></li>' : "") + (v ? '<li ><a class="waves-effect" href="' + v + '">الحلقة التالية</a></li>' : "");
$(p).html(v)
} else m.html('<div class="box-error"><i class="fa fa-exclamation" aria-hidden="true"></i><div class="info-error"></div></div>')
}
})
})
});
But I saw a blogger site that brings the classified posts in another way, as it brings 150 posts, and when you go down to the last post, it downloads 150 others.
This is the code for that site that you saw
$.ajax({
url: url,
type: get,
dataType: jsonp,
success: function(responce) {
fn(responce, type);
}
});
}
function lazy(fn, done, err, modules) {
var document;
var _0xE6BD = err[2][3];
if(done.scrollTop() + done.innerHeight() >= done[0].scrollHeight && !modules && $(".ep").length < _0xE6BD) {
document = true; <
div class = 'lds-ring' > < div > < /div><div></div > < div > < /div><div></div > < /div>;
load($(".ae-title .loader"), document, < div class = 'lds-ring' > < div > < /div><div></div > < div > < /div><div></div > < /div>);
fn(err); modules = true; document = false;
}
}
function load(ast, document, name) {
if(document) {
ast.append(name);
} else {
ast.html("");
}
}
function np(session, lib, end) {
var THREAD_STARTED = [];
var cb = 0;
for(; cb < parseInt(end / 150) + 1; cb++) {
var id = si(cb);
ajax(/feeds/posts /
default / -/ + lib + ?alt=json-in-script&max-results=150&start-index= + id, json_to_np, [THREAD_STARTED]);
}
links_ready(THREAD_STARTED, end, append_np, [THREAD_STARTED, window.location.href, session]);
}
function links_ready(type, done, error, callback) {
if(type.length < done) {
setTimeout(links_ready, 1e3, type, done, error, callback);
} else {
error(callback);
}
}
function append_np(right) {
var [typeR, cardR, nameR] = right;
var s3 = typeR.indexOf(cardR);
var managementcommandsdns = 0 == s3 ? : < div class = 'next' > < span > الحلقة التالية < /span><a href=' + typeR[s3 - 1] + '><i class='fa fa-chevron-right'></i > < /a></div > ;
var siteName = s3 + 1 == typeR.length ? : < div class = 'previous' > < span > الحلقة السابقة < /span><a href=' + typeR[s3 + 1] + '><i class='fa fa-chevron-left'></i > < /a></div > ;
nameR.append(managementcommandsdns + siteName);
}
function json_to_np(globalComponentsContext, componentStack) {
var data;
var PL$13 = globalComponentsContext.feed.entry;
var command_codes = componentStack[0];
if(void 0 !== PL$13) {
var PL$17 = 0;
for(; PL$17 < PL$13.length; PL$17++) {
var signedTransactionsCounter = PL$13[PL$17].link.length - 1;
for(; 0 <= signedTransactionsCounter; signedTransactionsCounter--) {
if(alternate == PL$13[PL$17].link[signedTransactionsCounter].rel) {
data = PL$13[PL$17].link[signedTransactionsCounter].href;
break;
}
}
command_codes.push(data);
}
}
}
function json_to_episodes(enumValueDeclaration, parameters) {
var i;
var sprite;
var _0xE6A1;
var PL$13 = enumValueDeclaration.feed.entry;
var GET_AUTH_URL_TIMEOUT = ;
var [type, timestamp, totalSecondsToStayOpen, inhibitorObjectPaths, pkg] = parameters;
var document = true;
if(void 0 !== PL$13) {
var PL$17 = 0;
for(; PL$17 < PL$13.length; PL$17++) {
var signedTransactionsCounter = 0;
for(; signedTransactionsCounter < PL$13[PL$17].link.length; signedTransactionsCounter++) {
if(alternate == PL$13[PL$17].link[signedTransactionsCounter].rel) {
_0xE6A1 = PL$13[PL$17].link[signedTransactionsCounter].href;
break;
}
}
i = PL$13[PL$17].content.$t;
PL$13[PL$17].title.$t.match(/\u0627\u0644\u062d\u0644\u0642\u0629\s\d+(\.\d+)?/g);
GET_AUTH_URL_TIMEOUT = GET_AUTH_URL_TIMEOUT + ( < div class = 'ep' > < a href = ' + _0xE6A1 + ' > +( != (sprite = get_element(i, type)) ? sprite : الحلقة + (inhibitorObjectPaths - (PL$17 + totalSecondsToStayOpen) + 1)) + < /a></div > );
}
$(timestamp).find(".eps").append(GET_AUTH_URL_TIMEOUT);
document = false;
load(timestamp.find(".ae-title .loader"), document, pkg);
}
}
function get_element(i, name) {
var flags;
var regex = ;
i = < div > +i + < /div>;
var template = 0;
for(; template < name.length; template++) {
regex = regex + (flags = null != (flags = $(i).find(name[template]).html()) ? flags : );
}
return regex;
}
function get_episodes(layoutItems) {
var [inputElement, floatLabelOffsetLeft, success] = layoutItems;
ajax(/feeds/posts /
default / -/ + floatLabelOffsetLeft + ?alt=json-in-script&max-results=150&start-index= + inputElement, json_to_episodes, success);
}
function si(name) {
return start_ind = 150 * name + 1, start_ind;
}
function forward(name, res) {
var DLF = name.feed.openSearch$totalResults.$t;
var args = si(0);
var pkg = < div class = 'lds-ring' > < div > < /div><div></div > < div > < /div><div></div > < /div>;
var [chain_from, label, chain_memo_sender, chain_propose_account] = res;
if(load(container.find(".ae-title .loader"), true, pkg), get_episodes([args, chain_from, [chain_propose_account, label, args, DLF, pkg]]), np($("#select-chapter .np"), chain_from, DLF), DLF > 150) {
var cb = 1;
for(; cb < parseInt(DLF / 150) + 1; cb++) {
args = si(cb);
$(label).find(".eps").on(scroll, function() {
lazy(get_episodes, $(label).find(".eps"), [args, chain_from, [chain_propose_account, label, args, DLF, pkg]], executed = false);
});
executed = true;
}
}
}
var anime = $(".anname").attr("data-anime");
var episode = $(".post-title").text();
var container = $("#select-chapter");
var url = /feeds/posts /
default / -/ + anime + ?alt=json-in-script&max-results=0;
var go = ajax(url, forward, [anime, container, episode, [.nofe, .noff]]);
I want to convert my code to make it like its code
I wanted to comment this solution, but unfortunately could not.
Add a read more (jump link) in every post, then it will load as its supposed to.
I made a javascript code to create some html element in parent iframe based on user selection from an iframe in a popup.
My code is given below.
The each loop may contain 50 to 150 iteration. Sometimes when I call function AddProcedures the Mozilla crashes during iteration, Is there any way to fix this issue or to reduce the browser load. I tried to put setTimeout after some code blocks but it didn't help.
I have also changed the for loop to jquery each, just to try if that helps.
var tot_codes = 0;
function doAddProcedure(thisVal,resolve){
var enc_id = $("#cpt_encounter").val();
var rowId = window.parent.$("[data-encounterBilled='"+ enc_id +"']").closest('tr').attr('id'); // table row ID
var recalc = parseInt(rowId.substring(rowId.indexOf('id-')+3));
var countval = $("#last_id").val();
//Load issue Fix
//Old code
//for (i = 0; i < document.cpt.elements.length; i++) {
//if (document.cpt.elements[i].type == "checkbox") {
//if (document.cpt.elements[i].checked == true) {
$('#cpt input:checkbox:checked').each(function(){
setTimeout(function() { }, 100);
var currentCodeMod = $(this).attr("data-codemod");
var currentCodeTypid = $(this).attr("data-codeTypeid");
if (currentCodeMod == null)
return;
tot_codes++;
var nextcntval = parseInt(countval) + 1;
var code_no = $(this).attr("id").replace("cpt_chkbx", "");
var Code = $("#codeVal" + code_no).val();
var just = $("#codeType" + code_no).val();
var categoryId = $("#codeType" + code_no).data("categoryid"); //Added to get category //Bug Fix
var Name = $("#cpttext" + code_no).val();
var codedisp = Code + ':' + Name;
var Modifier = '';
//if($("#modifier_setngs").val() == 1){
var Modifier1 = $("#modcpt1"+code_no).val() != '' ? $("#modcpt1"+code_no).val() + ":" : '';
var Modifier2 = $("#modcpt2"+code_no).val() != '' ? $("#modcpt2"+code_no).val() + ":" : '';
var Modifier3 = $("#modcpt3"+code_no).val() != '' ? $("#modcpt3"+code_no).val() + ":" : '';
var Modifier4 = $("#modcpt4"+code_no).val() != '' ? $("#modcpt4"+code_no).val() + ":" : '';
Modifier = Modifier1 + Modifier2 + Modifier3 + Modifier4;
//}
var codetableid = $("#code_tab_id" + code_no).val();
var j = countval; /* lineitem wise uniqid */
//var encounter = window.parent.$('#codetype-' + j).closest('tr.charge-entry-row').find('.expand-actions').attr('data-encounterid');
var encounter = enc_id;
var codeforarr = encounter + ':' + just + ':' + Code + '::' + Modifier;
window.parent.pushToArray(codeforarr);
var f = 0;
$(window.parent.$("#codetype-" + countval).parents().find('.inner-table .charge-entry-row')).each(function() {
//console.log($(this).find('.inputStringHidden').val() + '/' + codeforarr);
if ($(this).find('.inputStringHidden').val() == codeforarr) {
var exis_row_id = $(this).find('.inputStringHidden').attr('id').split('inputStringHidden-');
j = exis_row_id[1].toString();
f = 1;
$(this).find('.front_pay_codes_display').trigger('click');
}
});
if (f == 0) {
if (window.parent.document.getElementById('inputStringHidden-' + countval).value != '') {
window.parent.$("#codetype-" + countval).children().parent().parent().parent().siblings().find('.addnew-row').attr('data-rowadd', 'fromdb').trigger("click");
countval = parseInt(countval) + 1;
j = countval.toString();
}
window.parent.$("#add-" + countval).trigger("click");
window.parent.$("#codetype-" + (countval)).val(currentCodeTypid);
window.parent.$("#codetype-" + countval).trigger("change");
}
window.parent.document.getElementById('inputString' + j).value = codedisp;
window.parent.document.getElementById('category-' + j).value = categoryId; //Added to set category //Bug Fix
window.parent.document.getElementById('string_id' + j).value = Code;
window.parent.document.getElementById('string_value' + j).value = Name;
window.parent.document.getElementById('inputStringHidden-' + j).value = codeforarr;
window.parent.document.getElementById('codetableid-' + j).value = codetableid;
window.parent.$("#inputString" + j).closest('tr.charge-entry-row').find('.val-change-bit').val(1);
setTimeout(function() {}, 100);
window.parent.$("#suggestions" + j).hide();
window.parent.$("#inputString" + j).focus();
var uniqidHidden = window.parent.$("#inputString" + j).closest('tr.charge-entry-row').find('.uniqid-hidden').val();
window.parent.$('#add-modifier' + j).parent().find('.displaymode-elem').text(Modifier);
//if($("#modifier_setngs").val() == 1){
if (f == 0) {
window.parent.$('#add-modifier' + j).parent().find('.displaymode-elem').addClass('area-hide');
}else{
window.parent.$('#add-modifier' + j).parent().find('.displaymode-elem').removeClass('area-hide');
}
window.parent.$('#modifiers' + uniqidHidden).val(Modifier);
arr = Modifier.split(':');
window.parent.$('#modifier-' + uniqidHidden + '-1').val(arr[0]);
window.parent.$('#modifier-' + uniqidHidden + '-2').val(arr[1]);
window.parent.$('#modifier-' + uniqidHidden + '-3').val(arr[2]);
window.parent.$('#modifier-' + uniqidHidden + '-4').val(arr[3]);
//}
var eclaimPlanActive = window.parent.$('#eclaimPlanActive').val();
var price = $("#cpt_price" + code_no).val();
var price_level = $("#pricelevelhidden" + code_no).val();
if (price == 0 || price == null)
price = 0;
window.parent.$('#price-' + j).val(price);
window.parent.$('#bill-pricelevel-' + j).val(price_level);
/** Charge Total **/
var chargeTotal = window.parent.$('#charge-total').text().replace(/[\s\,]/g, '').trim();
if (chargeTotal == '')
chargeTotal = parseFloat(0);
var tempChargeTotal = parseFloat(chargeTotal) + parseFloat(price);
window.parent.$('#charge-total span').html(tempChargeTotal);
/** End **/
var units = $("#cpt_units" + code_no).val(); //data[0]['units']
if (units == 0 || units == null)
units = 1;
window.parent.$('#qty-' + j).val(units);
var tax = 0;
var disc = 0;
setTimeout(function() { }, 100);
if (window.parent.$('#tax-' + j).length > 0)
tax = window.parent.$('#tax-' + j).val().replace(/[\s\,]/g, '');
if (window.parent.$('#discount-' + j).length > 0)
disc = window.parent.$('#discount-' + j).val().replace(/[\s\,]/g, '');
var amount = price * units;
amount = amount + ((amount * tax) / 100);
if (disc > 0) {
var p = price * units;
var dc = ((p * disc) / 100);
amount = amount - dc;
}
/** Discount Total **/
var disTotal = window.parent.$('#discount-total').text().replace(/[\s\,]/g, '').trim();
if (disTotal == '')
disTotal = parseFloat(0);
var tempDisTotal = parseFloat(disTotal) + parseFloat(dc);
if (isNaN(tempDisTotal) == true) {
tempDisTotal = '0.00';
}
window.parent.$('#discount-total').html(tempDisTotal);
/** End **/
if (!parseFloat(window.parent.$('#lineitempaid-' + j).val()))
window.parent.$('#lineitempaid-' + j).val('0.00');
window.parent.$('#total-' + j).val(amount);
window.parent.$('#remainder-' + j).val(amount);
window.parent.$('#hidremainder-' + j).val(amount);
//insurance and patient_share
if (eclaimPlanActive == '1') {
var codetableid = window.parent.$('#codetableid-' + j).val();
var parentRowVal = parseInt(window.parent.$('#codetableid-' + j).closest('tr').find('.row_value').attr('data-rowvalue')) - 1;
var insData1 = window.parent.$('tr#row-id-' + parentRowVal + ' .encounter').attr('data-insdata1');
window.parent.getBenefitCategoryOfCode(j, codetableid, insData1);
if (window.parent.$('#have-benefit').val() == '0') {
var insData2 = window.parent.$('tr#row-id-' + parentRowVal + ' .encounter').attr('data-insdata2');
window.parent.getBenefitCategoryOfCode(j, codetableid, insData2);
}
}
var passParams = '';
window.parent.calculate('qty-' + j, passParams);
//Updating the title
window.parent.$("#inputString" + j).closest('tr.charge-entry-row').find('.fi-searchitems').attr('data-original-title', codedisp);
if (f == 0) {
//Display DIv :: Relace with new values
var cloneLabel = window.parent.$("#inputString" + j).closest('tr.charge-entry-row').find('.show_label').clone();
//In Edit Mode
if (cloneLabel.find('.displaymode-elem').length > 0) {
var $max_length = 16;
var trucncateCode = Name;
if (trucncateCode.length > $max_length)
trucncateCode = trucncateCode.substring(0, $max_length) + '...';
cloneLabel.find('.front_pay_codetype').text(just + ":");
cloneLabel.find('.front_pay_code').text(trucncateCode);
cloneLabel.find('.displaymode-elem').removeClass('area-hide');
cloneLabel.removeClass('area-hide');
cloneLabel.find("input[name='code_type']").val(just).attr('id', 'code_type-' + j);
cloneLabel.find("input[name='string_id']").val(Code).attr('id', 'string_id-' + j);
cloneLabel.find("input[name='string_value']").val(Name);
var dataType = $("#inputString" + j).closest('tr.charge-entry-row').find('.data_type').val();
if (dataType == "lab") {
var lab = $("select[name='lab_type']").find('option:selected').val();
if (cloneLabel.find("input[name='lab_type']").length > 0) {
cloneLabel.find("input[name='lab_type']").val(lab);
} else {
cloneLabel.append('<input type="hidden" name="lab_type" class="lab_type" value="' + lab + '">');
}
} else {
cloneLabel.find("input[name='lab_type']").remove();
}
setTimeout(function() { }, 100);
//Making the view
cloneLabel.removeClass('area-hide');
window.parent.$("#inputString" + j).closest('tr.charge-entry-row').find('.front_pay_codes_editelem').removeClass('area-show').addClass('area-hide');
window.parent.$("#inputString" + j).closest('tr.charge-entry-row').find('.show_label').replaceWith(cloneLabel);
window.parent.$("#inputString" + j).closest('tr.charge-entry-row').find('.show_autosuggest').html('');
}
window.parent.$("#codetype-" + countval).children().parent().parent().parent().siblings().find('.addnew-row').attr('data-rowadd', 'fromdb').trigger("click");
countval = nextcntval.toString();
}
else {
window.parent.$("#suggestions" + j).hide();
countval = countval.toString();
}
setTimeout(function() { }, 150);
});
window.parent.reCalculatePlanEncounterWise(recalc);
resolve("Success!");
}
function doAddPromise(thisVal){
return new Promise(function(resolve){
doAddProcedure(thisVal,resolve);
});
}
function AddProcedures(thisval)
{
$('#procedureSaveButton').text('Processing....');
// $('.fa-spinner').removeClass('hide');
top.ShowAjaxLoader('Loading..');
setTimeout(function(){
}, 2000);
//top.ShowAjaxLoader('Loading..');
setTimeout(function(){
$.when(doAddPromise(thisval)).done(function(){
if (tot_codes > 0) {
window.parent.phFrntpayClosePopup();
top.notification('Successfully added the procedures.');
//top.HideAjaxLoader('Loading..');
top.HideAjaxLoader();
$('body').removeClass('modal-open');
} else {
top.notification('Please select atleast one procedure.');
$('#procedureSaveButton').text('Add Procedures');
//$('.fa-spinner').addClass('hide');
top.HideAjaxLoader();
}
});
}, 10);
}
I have function that display ASCII table in monospace font
function ascii_table(array, header) {
if (!array.length) {
return '';
}
for (var i = array.length - 1; i >= 0; i--) {
var row = array[i];
var stacks = [];
for (var j = 0; j < row.length; j++) {
var new_lines = row[j].toString().split("\n");
row[j] = new_lines.shift();
stacks.push(new_lines);
}
var new_rows_count = Math.max.apply(Math, stacks.map(function(column) {
return column.length;
}));
for (var k = new_rows_count - 1; k >= 0; k--) {
array.splice(i + 1, 0, stacks.map(function(column) {
return column[k] || "";
}));
}
}
var lengths = array[0].map(function(_, i) {
var col = array.map(function(row) {
if (row[i] != undefined) {
return row[i].length;
} else {
return 0;
}
});
return Math.max.apply(Math, col);
});
// column padding
array = array.map(function(row) {
return '| ' + row.map(function(item, i) {
var size = item.length;
if (size < lengths[i]) {
if (item.match(/\t/g)) {
// tab have 4 spaces
size += item.match(/\t/g).length*3;
}
item += new Array(lengths[i] - size + 1).join(' ');
}
return item;
}).join(' | ') + ' |';
});
var sep = '+' + lengths.map(function(length) {
return new Array(length + 3).join('-');
}).join('+') + '+';
if (header) {
return sep + '\n' + array[0] + '\n' + sep + '\n' +
array.slice(1).join('\n') + '\n' + sep;
} else {
return sep + '\n' + array.join('\n') + '\n' + sep;
}
}
but fail if table cell contain japanese letters like 中文 when one character have width of two ascii letters:
中文
rock
How can I deal with cases like this? How can I know if width of a character have size of two?
You'll need to check the characters width rather than length. Anything that is a (decent) port of wcwidth should do the trick.
Fiddle: https://jsfiddle.net/fLfg7yqn/
JQuery:
$(function () {
$('.dvContentSlide').not(':eq(0)').addClass("dispNone");
$('.dvContentSlide:eq(0)').addClass("slideIsActive");
var g = parseInt($('div.slideIsActive').index()) + 1;
var u = $(".dvContentSlide").length;
$("#spCur").text("Current Index: " + g);
$("#spDVLen").text("SLIDE div length: " + $(".dvContentSlide").length);
for (var i = 0; i < u; i++)
$(".ulContentSliderNav").append('<li><span></span></li>');
$(".ulContentSliderNav :first-child a").addClass("ulContentSliderNavSel");
$(".cSlider").mouseover(function () {
clearInterval(po);
}).mouseout(function () {
po = setInterval(AutoSlide, 4000);
});
$(".ulContentSliderNav a").click(function (e) {
e.preventDefault();
$(this).parent().parent().find(".ulContentSliderNavSel").removeClass("ulContentSliderNavSel");
$(this).addClass("ulContentSliderNavSel");
GoToTheSlide($(this).parent().index());
});
function GoToTheSlide(t) {
$('.dvContentSlide').addClass("dispNone");
$('.dvContentSlide').removeClass("slideIsActive");
$('.dvContentSlide:nth-child(' + ++t + ')').addClass("slideIsActive").removeClass("dispNone");
}
$("#aContentSliderNext").click(function () {
var k = $('div.slideIsActive').index() + 1;
if (k >= $(".dvContentSlide").length) {
k = 1;
$('.dvContentSlide').not(':eq(0)').addClass("dispNone").removeClass("slideIsActive");
$('.dvContentSlide:eq(0)').addClass("slideIsActive").removeClass("dispNone");
}
else {
$(".dvContentSlide:nth-child(" + k + ")").removeClass("slideIsActive").addClass("dispNone");
$(".dvContentSlide:nth-child(" + ++k + ")").removeClass("dispNone").addClass("slideIsActive");
}
$("#spCur").text("Current Index: " + k);
$(".ulContentSliderNavSel").removeClass("ulContentSliderNavSel");
$(".ulContentSliderNav li:nth-child(" + k + ") a").addClass("ulContentSliderNavSel");
});
$("#aContentSliderPrev").click(function () {
var k = $('div.slideIsActive').index() + 1;
if (k <= 1) {
k = $(".dvContentSlide").length;
$('.dvContentSlide').not(':eq(' + k + ')').addClass("dispNone").removeClass("slideIsActive");
$('.dvContentSlide:nth-child(' + k + ')').addClass("slideIsActive").removeClass("dispNone");
}
else {
$(".dvContentSlide:nth-child(" + k + ")").removeClass("slideIsActive").addClass("dispNone");
$(".dvContentSlide:nth-child(" + --k + ")").removeClass("dispNone").addClass("slideIsActive");
}
$("#spCur").text("Current Index: " + k);
$(".ulContentSliderNavSel").removeClass("ulContentSliderNavSel");
$(".ulContentSliderNav li:nth-child(" + k + ") a").addClass("ulContentSliderNavSel");
});
function AutoSlide() {
var k = $('div.slideIsActive').index() + 1;
console.log(k);
if (k >= $(".dvContentSlide").length) {
k = 1;
$('.dvContentSlide').not(':eq(0)').addClass("dispNone").removeClass("slideIsActive");
$('.dvContentSlide:eq(0)').addClass("slideIsActive").removeClass("dispNone");
}
else {
$(".dvContentSlide:nth-child(" + k + ")").removeClass("slideIsActive").addClass("dispNone");
$(".dvContentSlide:nth-child(" + ++k + ")").removeClass("dispNone").addClass("slideIsActive");
}
$("#spCur").text("Current Index: " + k);
$(".ulContentSliderNavSel").removeClass("ulContentSliderNavSel");
$(".ulContentSliderNav li:nth-child(" + k + ") a").addClass("ulContentSliderNavSel");
}
var po = setInterval(AutoSlide, 4000);
});
Everything is working fine except how can I update the jquery/css so instead of showing the slide, it fades out the current slide and fades in the next slide with keeping the structure as is.
Have you tried fadeOut() fadeIn()? I didn't see it in your code, follow this link to see if it will meet your need.
This code is supposed to draw a grid (it's meant for a maze, so I need to only draw parts of it):
function drawMaze() {
for (var r = 0; r < Rows.length; r++) {
var row = Rows[r];
var sr = new createjs.Shape();
sr.x = 0;
sr.y = (r + 1) * offY;
var gr = sr.graphics.beginStroke("black");
gr.moveTo(0, (r + 1) * offY);
for (var i = 0; i < row.length; i++) {
if (row[i] === true) {
console.log("r=" + r + ",i=" + i + ",x=" + (i + 1) * offX + ",y=" + (r + 1) * offY);
gr.lineTo((i + 1) * offX, (r + 1) * offY);
} else {
gr.moveTo((i + 1) * offX, (r + 1) * offY);
}
}
stage.addChild(sr);
}
for (var c = 0; c < Cols.length; c++) {
var col = Cols[c];
var sc = new createjs.Shape();
sc.x = (c + 1) * offX;
sc.y = 0;
var gc = sc.graphics.beginStroke("black");
gc.moveTo((c + 1) * offX, 0);
for (var i = 0; i < col.length; i++) {
if (col[i] === true) {
console.log("c=" + c + ",i=" + i + ",x=" + (c + 1) * offX + ",y=" + (i + 1) * offY);
gc.lineTo((c + 1) * offX, (i + 1) * offY);
} else {
gc.moveTo((c + 1) * offX, (i + 1) * offY);
}
}
stage.addChild(sc);
}
var sd = new createjs.Shape();
sd.graphics.s("black").mt(0, 0).lt(offX * Cols.length, offY * Rows.length).f("red").r(175,175,175,175);
stage.addChild(sd);
stage.update();
}
The diagonal line/red square is only for visualization.
With this, the spacing between rows/columns is doubled and so only half of the lines form a grid. Here is the full code: http://jsfiddle.net/vyLRT/9/
I just found out what was wrong! I just simply moved the lines twice.
So instead of
sr.x = 0;
sr.y = (r + 1) * offY;
sc.x = (c + 1) * offX;
sc.y = 0;
all values just need to be set to 0.