- Screen name: jQuerydan
- About Me: I be wanderin' abit into Flash, javascript, and lately jQuery. Now tinkerin' with video-audio based web apps implying Youtube API and streaming audio (i need an iPad lol!).
jQuerydan's Profile
20 Posts
40 Responses
0
Followers
Show:
- Expanded view
- List view
Private Message
- 11-Feb-2016 09:51 PM
- Forum: Using jQuery
I'm trying to rebind a button that was previously unbound with the one() method, like this:- $(document).one('keypress', 'button', function(e){
- // do something once here ...
- }).on('keyup', 'button', function(){
- // How to rebind keypress to button ?
- });
Because the keypress event triggers non-stop while a key is continuously pressed, I use the one() method to trigger function only once, and because I need keypress in order to use String.fromCharCode(e.which), how can I rebind button to keypress using the keyup event?UPDATEHere is a fiddle to demonstrate https://jsfiddle.net/8jbt58t5/1/ I- 10-Aug-2014 09:44 AM
- Forum: Using jQuery
I need to delete all substrings ending with a $ symbol within a semi-colon delimited string. Sample string may look like this (spaces between semi-colon delimiters only for code clarity). Substrings are of variable lengths:
- dgtrs534u$hi874hbf45 ; kk4746hghf ; 86dgdhdt65jdbsgdb254sf $277dhcbh74 ; re6hdgf554
Final string should look like this: hi874hbf45 ; kk4746hghf ; 277dhcbh74 ; re6hdgf554 (these values are always same length each)
I'll use code below. It's the "replace" method I can't figure out. If I split the string and use something like:
var split = splittedString.slice(-10).join(' ; '); I get "join is not a function". Is there a way to simply delete substrings left of all $ (including $ ) down to preceding delimiters without splitting?
- var string = $ ("#string" ).text();
- var finalString = string.replace( substrings left of all $ (including $) down to preceding delimiters ,"");
- $("#string").text(finalString);
Thx for pointers. dan- 08-Mar-2014 07:30 PM
- Forum: Using jQuery
Migrating from Youtube API v2 to v3 is a genuine pain in the ass! In v3 there is more code to write in order to filter what you need to get. The worst of the bunch is attempting to access all videos that exist in a Youtube channel. Youtube API v3 recycles the code term "Playlist" to mean Playlist content AND Channel content, that itself is needlessly confusing, unlike v2 where everything coded was clearcut and intelligent. Anyhow,
I couldn't find practical sample on how to get the data needed to access uploaded Youtube channel content. I am trying this based on very broad application but hitting a wall somehow.
First yor're supposed to get the "playlist" ID of the channel ID...- function GetPlaylistID() {
- gapi.client.setApiKey('Your-API-Key');
- gapi.client.load('youtube', 'v3', function(){
- var SelMenuOption = $("#Select-menu option:selected").val();
- var requestOptions = {
- mine: false, // False for public access?, no authorization needed.
- id: SelMenuOption,
- part: 'contentDetails'
- };
- request.execute(function(response) {
- var playlistId = response.result.channels[0].contentDetails.uploads;
$('#SavedID').val(playlistId); - });
- GetUploadedVideos();
- });
- }
..then you get the channel video uploads from the saved "playlist" ID mentioned above...- function GetUploadedVideos() {
- gapi.client.setApiKey('Your-API-key');
- gapi.client.load('youtube', 'v3', function(){
- var savedID = $('#SavedID').val();
- var request = gapi.client.youtube.playlistItems.list({
- playlistId: savedID,
- part: 'snippet'
- });
- request.execute(function(response) {
- // Go through result.playlistItems to view list of uploaded videos?
- for(var i=0;i<response.items.length;i++) {
- var rvideoID = response.playlistItems[i].id.videoId; // or snippet.videoId
- var rchannelID = response.playlistItems[i].snippet.channelId;
- var rchannelTitle = response.playlistItems[i].snippet.channelTitle
- var rTitle = response.playlistItems[i].snippet.title;
- var rDescription = response.playlistItemss[i].snippet.description;
- var rthumbnail = response.playlistItems[i].snippet.thumbnails.medium.url;
-
- var ytresults = 'HTML ..."
- $('#printResult').append(ytresults);
- });
- )
These are the errors I get:
TypeError: response.result.channels is undefined (line 11 of GetPlaylistID)
TypeError: response.items is undefined (line 13 of GetUploadedVideos())
Any better solutions? Why so darn complicated??
dan- 09-Jan-2014 10:51 AM
- Forum: Using jQuery
Hidden #main-input contains a string of comma-separated values. I need to find all same class divs that each contain same unique text and replace that text with the relevant comma-delimited substrings stored in #main-input, like so:
1- Find the first .container div that only contains the text "findme";
2- Replace "findme" with the first comma-delimited substring of hidden #main-input;
3- Find the second .container div that only contains the text "findme";
4- Replace "findme" with the second comma-delimited substring of hidden #main-input;
... continue to last .container div.
The code snippet below demonstrates how thing would work. Those .container divs are dynamically appended with their parent li to parentUL via ajax call which terminates like so:...- . . .
- $.when.apply(null,defArray).done(function(){
- $('#parentUL').append('<li><div class="container">findme</div></li>');
- });
- <#parentUL>
- <li><div class="container">hiThere</div></li>
- <li><div class="container">63AB</div></li> // First findme replaced by 63AB
- <li><div class="container">Whatever</div></li>
- <li><div class="container">Ha72</div></li> // Second findme replaced by Ha72
- <li><div class="container">7kK3</div></li> // Third findme replaced by 7kK3
- <li><div class="container">NevaMind</div></li>
- . . .</ul>
- <input type="hidden" id="main-input" /> // C.S.V.= 63AB,Ha72,7kK3
Doesn't matter whether the code would interact during each append or after all append is done, I just don't know what efficient code would do the job in a jiffy. Any help is greatly appreciated. ~ dan
- 23-Dec-2013 08:07 PM
- Forum: Using jQuery
Using the Youtube API 2 for embedded iframe, and after dynamically building a list of videos from a playlist feed which is rid of private or deleted videos, I aim to retrieve the duration of each fetched video through jsonc, kinda like so:- // Code to first display playlist feed and remove private or deleted videos (if any) not included here.
- . . .
- var vid = Array();
- $(".list:visible").find('.videoID').each(function(data){
- vid[data] = $(this).text();
- var video = '//gdata.youtube.com/feeds/api/videos/' + vid + '?v=2&alt=jsonc';
- $.getJSON(video, function(data,status,xhr) {
- console.log(data.data.duration);
- // Here would be code to append transformed duration (hours:mins:secs) of each video (thumbnail) into their span containers.
- });
- });
Is the above legit? I guess I have to do it this way since beforehand in some feeds there are private and deleted videos that must be deleted from the list, so I fetch all videos in the playlist feed, then immediately remove all videos components whose title equals Private video or Deleted Video, then iterate the code above throughout remaining video IDs. I do it this way because the code breaks if it encounters a private or deleted video element thats exists within the list (no data.data.duration to return?).
Problem is, the above code doesn't loop through all dynamically set .videoID. Console.log only prints the duration of first .videoID displayed. I also tried setTimeout in order to wait a few to make sure the playlist feed had completely displayed and that didn't help either.
Is there a better and more efficient way to do the above? Am kinda newbie to all this ajax jsonc thingy, any pointers leading to an efficient solution would be mighty helpful! ~ dan
- 14-Nov-2013 12:11 PM
- Forum: Using jQuery
I need each fixed childTEXTBOX to display the index number of their parent li once a button is clicked. I currently only get the first child count which displays in all child text boxes of li belonging to parentUL :- $("#Button").on('click', function() {
- var index = $('.parentUL > li').index() +1;
- $('.parentUL [id^=childTEXTBOX]').val('Group ' +index);
- });
Any pointers will help. ~ dan
- 09-Sep-2013 09:58 AM
- Forum: Using jQuery
Dave resolved for me on an earlier posting (jQuery 1.10 | Match counter div class with element id to get length of element id children) a counter solution for one parent group which needed independant counting of div children lengths. I would need the same counting solution (if possible) for ten parent groups. Those ten parent groups will contain the same parent-children div classes and id, but only one group will be visible at any given time, so the hidden groups shouldn't affect the visible group div count, right?
It appears in my current modified setup, there is a counter conflict, meaning whatever children divs have been counted in the first visible parent group, whenever I hide that parent group and make visible another parent group, the counter keeps in memory what has previously been counted and displays the previous count in the new visible parent group at the same children counter divs location of the first parent group.
I tried counter empty(), html(''), even made certain that no id or no class be the same in all div children counters, but to no avail. It's like jQuery or the browser keeps in memory what has been counted first and displays that count in any other counter when a count is requested. I even tried emptying the DOM cache for the counter but no go. Below is sample code on what is going on:- <div id ="GROUP-A" class="AllGroups"> // First* visible parent group counted, but now hidden.
- <div class="VCLA"> 3 </div> // Counter results are accurate.
- <ol id="VCLA" class="list">
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- </ol>
- <div class="VCLB"> 2 </div> // Counter results are accurate.
- <ol id="VCLB" class="list">
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- </ol>
- </div>
- <div id ="GROUP-B" class="AllGroups"> // Visible Parent group counted, with errors.
- <div class="VCLA"> 3 </div> // ERROR: Counter results should be 6, not 3 as in previous.
- <ol id="VCLA" class="list">
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- </ol>
- <div class="VCLB"> 2 </div> // ERROR: Counter results should be 4, not 2 as in previous.
- <ol id="VCLB" class="list">
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- <li>SOME STUFF</li> // dynamically appended
- </ol>
- </div>
*First means the first group made visible after dom ready, not first as in index position of group.
Any working adaptation to the following code recently updated by Dave would be awesome:- $("div[class^=VCL]").each(function(){
- var theList = $("#" + $(this).attr("class"));
- $(this).html(theList.children().length);
- });
- 06-Sep-2013 01:46 PM
- Forum: Using jQuery
Can I use indexOf to match my counter div with a list id in order to display li length?
Do I have to match them in order to do so? The counter should count dynamically appended li. Is there a better way to do this? I use each method because there are twelve div counters that must only count their related ordered lists, so there are twelve ordered lists that have their own id and each related counter has a class that matches those id.
I use this so far, but nothing happens yet, could be incorrect too ;-(- $("div[class^=VCL]").each(function(){
- var lvcnt = $(this);
- var lists = $('.list');
- if (lvcnt.attr('class').indexOf(lists.attr('id')) !== -1) {
- lvcnt.text(lists.children().length);
- }
- });
Any help to achieve a working result would make my day! ~ dan
UPDATE: Count works but display is only on first counter, whenever I add li to count on other counters, the sum count displays in first counter only ;-(
- 16-Aug-2013 11:07 AM
- Forum: Using jQuery
I need to append elements to a visible child div. There are other hidden children within the parent div that have different classes starting with same prefixes. Code doesn't seem to work:- $('.parent > [class^="ABC"]').append('some-elements'); // Obviously appends to all same prefix classes
- $('.parent > [class^="ABC"]:visible').append('some-elements'); // Appends to parent only
- $('.parent > div:visible').append('some-elements'); // Appends to parent only
Child divs have layout. Only one child div is visible at any given time. How to target the visible child div in order to append elements into it?- 04-May-2013 05:28 PM
- Forum: Using jQuery
Here's the scenario: I have a string of comma-delimited Youtube video IDs handled by a function which displays results as clickable video image thumbnails. Problem is, if that string contains an ID that does not exist anymore (or is inaccessible), the function breaks instead of skipping (or importing) the missing video image thumbnail. Is there a jQuery/Javascript solution that, upon button click, a function imports thumbnails of all existing and deleted videos requested by the ID string ? I don't mind displaying the thumbnails of the deleted videos, where possible, in fact, that would be best as the thumbnail count would be the same as original request. I'm using Ajax/get/jsonp and I dunno if error handling can tackle this issue. This is the last major hurdle of my project which I must overcome before my hair gets all pulled out LOL! Help anybody?- 04-May-2013 04:54 PM
- Forum: Using jQuery
Is it a current fact that using the Youtube iframe embedded player means having to reload the player when dynamically swapping video content? Should I understand that I can only use the swf object embed in order to dynamically change the video src with the javascript API? I use the Youtube iframe API for iPad users (for HTML5 video) and everytime I dynamically load a video by it's ID the whole player has to reload before loading the video. That's alot of wasted time between video loads. Is there a way to keep the dynamically set player from reloading when dynamically swapping videos through ajax jsonp function callback? Also, I can't seem to find a sample function thats uses queued videos for dynamic loading... . ;-(- 03-Apr-2013 05:11 PM
- Forum: Using jQuery
Is there a way to combine both HTML5 native Drag & Drop and image file append (local) for FileReader / Canvas manipulation? Basically I want to either:- Drag (native drag & drop) an image thumbnail (PNG Base64) located in a source div and drop it in a destination div where upon the dropevent FileReader and Canvas do their stuff, or:
- Append the same image thumbnail located in the same source div into the same destination div where upon an append or load event FileReader and Canvas do the same stuff.
I have the following code I use for the drag and drop part which works, but I would need a button that once clicked would trigger an append method (or load?) as explained above at #2:- function drop(e) {
- $('#DestinationDiv').css("background-color","#222222");
- var dt = e.dataTransfer;
- var files = dt.files;
- if(files.length>0) {
- handleFiles(files);
- }}
- function handleFiles(f) {
- var o=[];
- for(var i=0; i<f.length;i++) {
- var reader = new FileReader();
- reader.onload = (function(theFile) {
- return function(e) {
- gCtx.clearRect(0, 0, gCanvas.width, gCanvas.height);
- .....
- }; })(f[i]);
- reader.readAsDataURL(f[i]); }}
It would appear that a drag and drop event doesn't quite result like in a load or append event, like the data involved in dropping isn't the same data involved in loading (or appending) in a div. The file I drag and drop is of the type data:image/png;base64,iVBORw0... which works, but with the above code, when I append the same image in the div, an error occurs at line 21:- TypeError: f is undefined
- for(var i=0; i<f.length;i++)
Perhaps I need an eventListener for the "load" or "append" event of the destination div? Obviously the above code is missing something. Any hinters would permit me to sleep ealier tonight LOL! Thx for guiding me towards the right method-event! ;-) - dan
- 29-Mar-2013 10:35 AM
- Forum: Using jQuery
But not so easy as I thought in my scenario, I have a variable which is basically the video ID of a Youtube link that I extract from a url once clicked, which, if matching a substring (video ID) of a comma-delimited string of video IDs found in a input text box, should trigger an event., like so:- var videoID =$("#videoIDholder").val(); // <-- the stored link video ID
- var str = $("input[name=StringOfVideoIDs]").val().split(',');
- if ($.inArray(videoID, str) !== -1) {
- alert('match!');
- } else {
- alert('no match!');
- };
Problem is, with the above code, the console (Firebug) reflects what's in videoID or str but alerts don't show if there's a genuine match or not, i.e., the above code triggers the match alert when the text box contains any video ID, and when the text box is empty the "no match!" alert gets triggered. I don't have to know the location of the matching comma-delimited ID located in the text box, just if there's a comma-delimited ID that is a duplicate (or not a duplicate) of the ID extracted from the video link. I don't mind using indexOf.
The closest I got was with this which works with one hard-coded ID:- var str = $("input[name=StringOfVideoIDs]").val();
- var n=str.match(/GHFDr254gs7/g);
- alert(n);
However, the above video ID in bold must be replaced by a variable, like this:- var videoID =$("#videoIDholder").val();
- var str = $("input[name=StringOfVideoIDs]").val();
- var n=str.match(/videoID/g); // <--- Is this possible?
- alert(n);
I read that in this scenario, you would have to use .match(new RegExp( ... , but this is new for me.
Matching a variable in a dynamic environment is what I need, any hints??- 08-Dec-2012 06:40 PM
- Forum: Using jQuery
The following code works for user-click event on dynamically inserted class-based checkboxes:- $('.aenable, .benable').live('change', function() {
- var chkbxchkd = $('.aenable:checkbox:checked, .benable:checkbox:checked').length;
- $('.counter').html('( ' + chkbxchkd + ' selected )');
- });
The problem is when I click on a button that toggles on and off the checked states of the class-based dynamically inserted checkboxes, the counter doesn't reflect the actual number of checked checkboxes. Basically, I need a live counter that constantly detects (and counts) user-clicked and dynamically checked or unchecked dynamically inserted class-based checkboxes. Any hint? - dan- 20-Nov-2012 08:45 PM
- Forum: Using jQuery
A file input element selects a base64 png from desktop and a decoded text string appears in an adjacent text input element for further jQuery processing. However, when I drag and drop the same base64 png onto the file input element, the decoded text string appears in the adjacent text input element but is not subsequently processed by jQuery. It's like everything stops after line 2 of code:- $('#file_input').on('change', function() {
- handleFiles(this.files); // Base64 decoder which inserts text string in #result
- var array = $("#result").val().split(",");
- $.each(array,function(i){
- ... function processing ...
- 11-Oct-2012 09:25 AM
- Forum: Using jQuery
My multimedia app allows appending in a div the ol listing of clickable thumbnails, titles and durations of youtube videos for future replay. I was wondering how to save the ol element (with all the contents of li child elements) for future retrieval on a click of a button? Would the following cookie function work? https://github.com/carhartl/jquery-cookie/blob/master/README.md . I've read that cookies are not the way to go for this type of data, is that accurate? Basically, in my app, a button would export the div contents to the client's computer (perhaps as a playlist?) and another button would import that playlist back into my app.
Maybe a jQuery form or plugin would be in order here, any pointers? Thx for guiding me. - dan- 07-Oct-2012 10:43 PM
- Forum: Using jQuery
My app retrieves thumbnail, title and duration from searched videos or via preset links, but how do I go about in fetching the same info after import of a video provided in the related youtube videos that appear after a youtube video has ended? Basically, when a clicked related youtube video appears in Tubeplayer (which I use as player), how to get thumbnail, title, duration and vid ID of that video? Thx for pointers or sample code. - dan
Edited: Added ID in title and question.- 05-Oct-2012 10:04 AM
- Forum: Using jQuery
Is there a way to get the li number and title (after clicking on the li) of an ordered list that is set dynamically via ajax or jason? I use this as example for displaying the li in the hard-coded ol:- $("#List ol").append('<li><p>' + '<img src="'+thumbnail+'"'/><br />' + '<span class="title">'+imageTitle+'</span></p></li>');
A function dynamically fetches (after selecting an option from a pulldown menu) the thumbnails (fixed amount of 25 thumbs) and displays them (with their titles) in the ol div. The ordered list starts with the numbered li followed by the thumbnail image and the title below it. I managed to trim, splice, and join the title part but that's based on a variable which fetches the Youtube video title, like so:- var videoTitle = data.feed.entry[x].title.$t;
- var trimTitle = $.trim(videoTitle).substring(0, 70).split(" ").slice(0, 12).join(" ");
How can I get the selected li number (without the thumbnail) and corresponding title (trim-spliced like above) so they can display in a div? - dan- 09-Aug-2012 02:35 PM
- Forum: Using jQuery
Stuck here with sorta dilemma, I use this code to allow display of images in div via mouseover of select menu option:- $("#selectMenu").on("mouseover change", function() {
- oScroll2.tinyscrollbar_update($(this).val());
- return false;
- });
There are currently 11 anchors for 11 images, but this will grow. Anchor 1 is option value="1" (for first image); anchor 2 is option value="612" (for second image); anchor 3 is option value="1224" (for third image), etc. Those values are the pixel traveling distances (right to left) between left margin of div container and left margin of selected image (for scrolling - images are 612px wide).
EDIT: My prob is the following: When I mouseover any option in the select menu, it is the previous item (image) in the list that appears, regardless of direction. When I click on the option, however, everything works as it should. the correct image appears. Looks like something silly I dunno of... . What gives? - dan
UPDATE - Ok, here's the scoop, I tried "hover", "mouseover", "mouseenter, "select", and all of them trigger option item once you lose focus of option item with mouse (move onto the next item). Has this always been an issue with select menus? "Thud" !! Guess I need a function that supercedes this? Note: ".change() - event is deferred until the element loses focus."- jQuery API. Yup, I do need a function!- 08-Aug-2012 01:26 PM
- Forum: Using jQuery
I am trying to trigger a link that has same rel or name value of selected option value of a pulldown menu, is the following code capable of doing thist?- var s = $("this option:selected").val();
- $("a.track[rel='s']").trigger("click");
Basically you select an item from the pulldown menu and a matching link gets clicked. Scratching my head on this one (still learning). If above code is flawed, can you suggest some code that achieves what I need?
Thanks in advance. - danUPDATE: I got this function but it's not triggering the matching link. I gather I may have to find each link before any of them can be targeted?
Maybe reversing the order of this jsFiddle would do?- $("option").change(function(event){ //when option is selected
- event.preventDefault();
- $("a.track").attr(name='$(this).val()').trigger("click");
- «Prev
- Next »
Moderate user : jQuerydan
© 2013 jQuery Foundation
Sponsored by
and others.