javascript Textarea selection
Textarea selection - získání pozice karety kurzoru.
// FOR Gecko Browser selectionStart / selectionEnd selection length
function getPos(){
if (typeof document.getElementById('idTextarea').selectionStart != 'undefined') {
var nPosCursor = document.getElementById('idTextarea').selectionStart;
var nEndPos = document.getElementById('idTextarea').selectionEnd;
return nPosCursor;
}
return 0; // or -1
}
// source by javascript-array.com/guides/javascript_faq/
//Internet Explorer 4+, Mozilla/Gecko/Firefox
function getCaretPos(obj)
{
obj.focus();
if(obj.selectionStart) return obj.selectionStart; //Gecko
else if (document.selection) //Internet Explorer
{
var sel = document.selection.createRange();
var clone = sel.duplicate();
sel.collapse(true);
clone.moveToElementText(obj);
clone.setEndPoint('EndToEnd', sel);
return clone.text.length;
}
return 0;
}
77LW NO topic_id
AD
Další témata ....(Topics)
Funkce JavaScript pro práci s datumem a časem.
function msToTime(duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}
// console.log(msToTime(300000))
// output: 00:05:00.0
// get time difference between two dates in seconds
var startDate = new Date();
// Do your operations
var endDate = new Date();
var seconds = (endDate.getTime() - startDate.getTime()) / 1000;
var milliseconds = (endDate.getTime() - startDate.getTime());
[, OPTIONAL second param [, OPTIONAL ... param]]
static Date.now() // returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
parse(dateVal) // Date.parse('05 Dec 1998 00:12:00 GMT'); // return 912816720000
toDateString() // sunday 19.7.2020
toTimeString() // 20:15:37
getDate() // 1-31
getDay() // 0-6, 0 == Sunday
var now = new Date();
var dayOfWeekSundayIs7 = now.getDay() == 0)?7:now.getDay();
getFullYear() // 2020
getHours() // 0-23
getMilliseconds() // eg. 956
getMinutes() // 0-59
getMonth() // 0 january
getSeconds() // 0-59
getTime() // https://en.wikipedia.org/wiki/Unix_time
getTimezoneOffset() //returns the time zone difference, in minutes, from current locale
getYear() //does not return full years ("year 2000 problem"), it is no longer used and has been replaced by the getFullYear() method.
setDate(numDate) // 1-31 day of month
setHours(numHours[, numMin[, numSec[, numMilli]]]) // now.setHours(20, 21, 22); 20:21:22
setMilliseconds(numMilli) // 0-999
setMinutes(numMinutes[, numSeconds[, numMilli]]) // 0-59, 0-59, 0-999
setMonth(numMonth[, dateVal]) // 0-11
setSeconds(numSeconds[, numMilli]) 0-59 [, 0-999]
setYear(numYear) // not set full years ("year 2000 problem"), it is no longer used and has been replaced by the setFullYear() method.
setUTCDate() //
setUTCFullYear(2020) // 2020 sets the full year for a specified date according to universal time GMT
setUTCHours()
setUTCMilliseconds()
setUTCMinutes()
setUTCMonth()
setUTCSeconds()
toLocaleTimeString()
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
now.toLocaleDateString(undefined, options); //neděle 19. července 2020
// PDT Pacific Daylight Time (UTC -7)
// GMT ... SET GMT TIME +- ZONE ... new Date('December 31, 1974 23:59:30 GMT-3:00');
toGMTString() // DEPRECATED!!!! use toUTCString()
// Using UTC instead GMT!!!
var d = new Date("2020-07-15T00:00:00.000+07:00"); // UTC + 7
console.log(d.toISOString()); // "2020-07-14T17:00:00.000Z"
console.log(d.valueOf()); // 1594746000000
toISOString() // "2020-07-14T17:00:00.000Z"
toJSON() // "2020-07-14T17:00:00.000Z"
toSource() //This feature is obsolete!!!! Dont use!!!!
toString() // "Tue Jul 14 2020 19:00:00 GMT+0200 (Středoevropský letní čas)"
toUTCString() // "Tue, 14 Jul 2020 17:00:00 GMT"
valueOf() // 1594746000000
How to sort array in javascript.
sort diacritical diakritika
function sortCZ(a, b) {
var token = {'á': 'a', 'č': 'c', 'ď': 'd', 'é': 'e', 'ě': 'e', 'í': 'i', 'ň': 'n', 'ř': 'r', 'š': 's', 'ť': 't', 'ú': 'u', 'ů': 'u', 'ý': 'y', 'ž': 'z'};
var code_a = (token[a]) ? token[a].charCodeAt(0) + 0.5 : a.charCodeAt(0);
var code_b = (token[b]) ? token[b].charCodeAt(0) + 0.5 : b.charCodeAt(0);
// example s=115 š will 115.5 in array immediately after s OK :)
if(token[a]){
some = token[a].charCodeAt(0) + 0.5; // 115.5
some = token[a].charCodeAt(0); // 115
}
return code_a - code_b;
}
var ar = new Array("x","č","a","c","h","z","a","ř","e","ž","ě","ň","í","d","š");
ar.sort(sortCZ);
Editace contextového menu a přidání položek do kontextového menu Notepad++
Konkrétně je to vyvolání nabídky pro změnu syntaxe v otevřeném souboru.
Postup:
- vybrat z horního menu
- Settings
- Edtit Context Menu
- Upravit soubor
- Zavřít a otevřít Notepad++
- Vyzkoušet funkci
Konkrétně je to vyvolání nabídky pro změnu syntaxe v otevřeném souboru.
Postup:
- vybrat z horního menu
- Settings
- Edtit Context Menu
- Upravit soubor
- Zavřít a otevřít Notepad++
- Vyzkoušet funkci
Před < Item odstraňte mezeru!!!!! Zde je to jen kvůli zobrazeni. Prolížeče mají tendenci kód převést na HTML.
< Item id="0"/><!-- moje -->
< Item FolderName="Language Syntax" MenuEntryName="Language" MenuItemName="CSS" ItemNameAs="Language CSS"/>
< Item FolderName="Language Syntax" MenuEntryName="Language" MenuItemName="HTML" ItemNameAs="Language HTML"/>
< Item FolderName="Language Syntax" MenuEntryName="Language" MenuItemName="JAVASCRIPT" ItemNameAs="Language JAVASCRIPT"/>
< Item FolderName="Language Syntax" MenuEntryName="Language" MenuItemName="PHP" ItemNameAs="Language PHP"/>
Styly se nacházejí v příslušné složce temáta, které používáme. Například:
Jednotlivé soubory můžeme upravovat, ale je nutné provádět refresh stylu z Admin centra ACP, záložka Styles -> Style components
Další soubory stylů přidáváme do jako import:
myforum/styles/prosilver/theme/stylesheet.css
Styly můžeme též editovat z ACP tabulka Styles -> Themes a zvolti Edit příslušné šablony
a po uložení provedeme refresh témata.
Nebo Styly - Skiny - Upravit konkrétní šablonu (prosilver atd.)
Někdy musíme vymazat i soubory ze složky cache a ponechat tam jen index.html a .htaccess
mojeforum/styles/prosilver/theme/
Jednotlivé soubory můžeme upravovat, ale je nutné provádět refresh stylu z Admin centra ACP, záložka Styles -> Style components
Další soubory stylů přidáváme do jako import:
myforum/styles/prosilver/theme/stylesheet.css
@import url("prs.css");
Styly můžeme též editovat z ACP tabulka Styles -> Themes a zvolti Edit příslušné šablony
a po uložení provedeme refresh témata.
Nebo Styly - Skiny - Upravit konkrétní šablonu (prosilver atd.)
Někdy musíme vymazat i soubory ze složky cache a ponechat tam jen index.html a .htaccess
PHP function get first and latest character from string
// for earlier version PHP can use mb_strlen, mb_substr if use
// diacritical accent $str = 'ěščřžýáíé';
function startsWith($haystack, $needle)
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
Date: 11.06.2020 - 20:10Editace: 18 10 2016
Počet článků v kategorii: 77
Url:javascript-textarea-selection