[jQuery] Re: Creating a Plugin
It will actually be 2 instances of the plugin on 2 elements: $ ('#test').data('bbcode'), and $('#test2').data('bbcode') Thanks for those links, those will help me figure it out, although it doesn't look easy :) On Dec 6, 1:08 pm, "Richard D. Worth" <[EMAIL PROTECTED]> wrote: > On Sat, Dec 6, 2008 at 11:53 AM, Brian Ronk <[EMAIL PROTECTED]> wrote: > > > That might work. I'll tinker with that. How does it work with > > multiple instances of the same plugin through? Where I'm using it, I > > am going to be pulling data from 2 instances of the plugin. Maybe I > > could have two different names... I think that would work. > > Data has support for namespaces. So if your plugin is called foo, and > someone else has a bar plugin, each bbcode property can be separated be like > so: > > $("#test").data("bbcode.foo", fooBbcode); > $("#test").data("bbcode.bar", barBbcode); > > same for getting. So that's with two plugins with different names, but you > maybe figure out something based on that. It's tricky to do two instances of > the same plugin on the same element, because how does the user select one or > the other? Get's even more complex if you have a set of elements (more than > one element in the jQuery object on which you call your plugin method). > > > > > Although, I would like to know how to make my plugin accept a method > > call. > > You can do it by inspecting the type of the first parameter passed to the > plugin method. Usually that would be a hash containing init options. If it's > called again and is a string then you can treat that as a method name, and > do the appropriate thing (dispatch an internal function in your plugin, > probably). This is all abstracted quite nicely in the widget plugin created > by Scott González and Jörn Zaefferer. It's used as a base for all jQuery UI > widgets, and can be found here: > > http://jquery-ui.googlecode.com/svn/trunk/ui/ui.core.js > > You can look at most any jQuery UI widget for an example of use. Here's a > fairly simple one: > > http://jquery-ui.googlecode.com/svn/trunk/ui/ui.progressbar.js > > And here are some examples of use (including init, modifying options, > calling methods, destroying): > > http://jquery-ui.googlecode.com/svn/trunk/tests/visual/progressbar.html > > Notice you can declare an _init (near the beginning of the file) that gets > called at init (the first time the plugin method is called on an element), > with optional options that override any defaults (declared near the end of > the file). Any functions you declare without an underscore (_) at the > beginning are public. Also notice you can declare _getData and _setData. > These let you handle any get/set of your data keys in your plugin's > namespace. It's really quite a nice factory. If you end up making use of it > and have any further questions, you can get help on the jQuery UI list: > > http://groups.google.com/group/jquery-ui > > - Richard > > Richard D. Worthhttp://rdworth.org/
[jQuery] Re: Creating a Plugin
That might work. I'll tinker with that. How does it work with multiple instances of the same plugin through? Where I'm using it, I am going to be pulling data from 2 instances of the plugin. Maybe I could have two different names... I think that would work. Although, I would like to know how to make my plugin accept a method call. On Dec 6, 9:05 am, "Richard D. Worth" <[EMAIL PROTECTED]> wrote: > You could store the bbcode in the element's jQuery data store: > > $("#test").data("bbcode", "..."); > > and you can get it back out by > > var bbcode = $("#test").data("bbcode"); > > Seehttp://docs.jquery.com/Core/datafor more info. > > Please let me know if your question goes further into how to make your > plugin accept a method call that would then return this data. > > - Richard > > On Fri, Dec 5, 2008 at 2:27 AM, Brian Ronk <[EMAIL PROTECTED]> wrote: > > > I'm making an edit in place plugin, and am running into an issue, > > mainly because I'm not sure how to do it. The data I am working with > > is bbcode, so what is seen on screen (non editing) is not bbcode, but > > it decoded. I would like to be able to return the bbcode to work with > > it in another area. I'm just not sure how to do that. > > > What I'd like to be able to do is to initialize it: $('#test').bbcode > > (); and then be able to call it again (or something) to get the > > actual bbcode out. So, something like $('#test').bbcode('code'); or $ > > ('#test').showcode(); > > > It basically works right now, except for the returning data. I'm just > > not sure on how to procede to do that.
[jQuery] Re: Creating a Plugin
I don't think that will work for a few reasons. I have to be able to see the decoded text in a certain size, thus what I have is something where you click on the editable area, and it switches to editing. Plus, I have a few custom bbcodes that are being used, and I didn't see a way to add them. Granted, I could have missed. Thanks for that link though, it might come in handy somewhere else. On Dec 5, 2:41 am, Kevin Kietel <[EMAIL PROTECTED]> wrote: > How about this jQuery editor: > > http://markitup.jaysalvat.com/ > > it's called markItUp! and uses Html, Textile, Wiki Syntax, Markdown, > BBcode > > On 5 dec, 08:27, Brian Ronk <[EMAIL PROTECTED]> wrote: > > > I'm making an edit in place plugin, and am running into an issue, > > mainly because I'm not sure how to do it. The data I am working with > > is bbcode, so what is seen on screen (non editing) is not bbcode, but > > it decoded. I would like to be able to return the bbcode to work with > > it in another area. I'm just not sure how to do that. > > > What I'd like to be able to do is to initialize it: $('#test').bbcode > > (); and then be able to call it again (or something) to get the > > actual bbcode out. So, something like $('#test').bbcode('code'); or $ > > ('#test').showcode(); > > > It basically works right now, except for the returning data. I'm just > > not sure on how to procede to do that.
[jQuery] Creating a Plugin
I'm making an edit in place plugin, and am running into an issue, mainly because I'm not sure how to do it. The data I am working with is bbcode, so what is seen on screen (non editing) is not bbcode, but it decoded. I would like to be able to return the bbcode to work with it in another area. I'm just not sure how to do that. What I'd like to be able to do is to initialize it: $('#test').bbcode (); and then be able to call it again (or something) to get the actual bbcode out. So, something like $('#test').bbcode('code'); or $ ('#test').showcode(); It basically works right now, except for the returning data. I'm just not sure on how to procede to do that.
[jQuery] Selected/Highlighted by Mouse
I know that it's possible, but I'm wondering if there is something in jQuery that will return the data or index of what a user has selected with a mouse (or shift button). I'd like to have a way to create a note on a page about a certain selection that the user defines. So, maybe I'd like to add a note about my first paragraph. I would be able to highlight it, and click a button, and then write a note to tell myself "it's (not) possible". (which would be stored in the backend with the location of the note. Internally, I want to add a [note] type of BBCode to the text that is highlighted. Does this make sense? If so, anyone know how? Thanks.
[jQuery] Re: event question
Hmmm... That would work perfectly. I'll take a look at it. Thanks. On Apr 22, 4:55 pm, "Jake McGraw" <[EMAIL PROTECTED]> wrote: > The default behavior: > > $(".classname").click(function(){ > alert("Hello, world!"); > > }); > > $("body").append('Click Me!'); > > Clicking "Click Me!" would do nothing. > > Using the liveQuery plugin (http://brandonaaron.net/docs/livequery/): > > $(".classname").livequery("click", function(event) { > alert("Hello, world!"); > > }); > > $("body").append('Click Me!'); > > Clicking "Click Me!" should now produce an alert window. > > - jake > > On Tue, Apr 22, 2008 at 4:45 PM, Brian Ronk <[EMAIL PROTECTED]> wrote: > > > I have a click even that I add to a certain class when the page is > > created. There is the possibility of dynamically adding another > > element with that class, and I would like to have the same click even > > added. I'm just wondering what would happen if I registered the click > > event for that class, would that work? For instance: > > > At page creation, this is run: > > $('.classname').click(function() { > > ... > > }); > > > If I ran this after a new element with that class was created, would > > that screw anything up. I do have an id associated with the element, > > so I could just add the event that way. I just wasn't sure if there > > might be a better way, or if I could add that to a function, and just > > call it when needed.
[jQuery] event question
I have a click even that I add to a certain class when the page is created. There is the possibility of dynamically adding another element with that class, and I would like to have the same click even added. I'm just wondering what would happen if I registered the click event for that class, would that work? For instance: At page creation, this is run: $('.classname').click(function() { ... }); If I ran this after a new element with that class was created, would that screw anything up. I do have an id associated with the element, so I could just add the event that way. I just wasn't sure if there might be a better way, or if I could add that to a function, and just call it when needed.
[jQuery] Re: Issue inserting an img into a table
Actually, you solved it. I had a in the empty cells. I put a span around it so I could select it (to test with) and remove it, and that solved the problem. I also removed it, and since I have everything set to 20x20px, I don't really need those. Annoying whitespace. Thanks. On Apr 21, 4:13 pm, Hamish Campbell <[EMAIL PROTECTED]> wrote: > Want to post your code? > > Whitespace could cause issues. Also, what if you set overflow:hidden > for the tds? > > Thanks, > > Hamish > > On Apr 22, 8:04 am, Brian Ronk <[EMAIL PROTECTED]> wrote: > > > Well, the problem isn't actually putting the image into the table, > > that part is fine. I'm running into a problem the way it is > > displayed. My table is basically a map. It is 10x10, and I have it > > set specifically to 20px x 20px. Each has a background image > > that is actually 20px x 40px. These are sprites that, when hovered > > over, will change which part of the image it is looking at so I can > > tell where I am hovering. All this works fine. > > > Now, there is the possibility of each having an inserted > > into it at creation. These images are 20x20px .png images. These > > work correctly (with the help of vertical-align: bottom in the css). > > But, if I insert one after creation, or move one of the tags > > (with append or prepend) I get the image in the table, but that row > > that I insert it into is enlarged by 20px. I think it's related to > > the vertical-align somehow, but even setting the style inline with > > vertical-align: bottom doesn't make any difference. > > > Any ideas on how to fix this issue?
[jQuery] Issue inserting an img into a table
Well, the problem isn't actually putting the image into the table, that part is fine. I'm running into a problem the way it is displayed. My table is basically a map. It is 10x10, and I have it set specifically to 20px x 20px. Each has a background image that is actually 20px x 40px. These are sprites that, when hovered over, will change which part of the image it is looking at so I can tell where I am hovering. All this works fine. Now, there is the possibility of each having an inserted into it at creation. These images are 20x20px .png images. These work correctly (with the help of vertical-align: bottom in the css). But, if I insert one after creation, or move one of the tags (with append or prepend) I get the image in the table, but that row that I insert it into is enlarged by 20px. I think it's related to the vertical-align somehow, but even setting the style inline with vertical-align: bottom doesn't make any difference. Any ideas on how to fix this issue?
[jQuery] hovering over a table based map
I have a table based map (each square of the table is a different map area) and would like to use a hover as a sort of legend. So, when I hover over an area, I get a popup, or something, that says "this is a rock and a chicken". My map is based on an array of 10x10 numbers (for the base) and then (probably, haven't fully decided yet) names to indicate special areas on the map. So, 2 10x10 maps, one filled with numbers, the other has mostly null, with some names that will link to an image, specified by an id. (Sorry if that's a little confusing). Because of the way it is set up, and the fact that the map could change, I wanted the hover to be dynamic. The map is stored as a variable, so all I would (theoretically) have to do is get the description from legend[map.[y][x]].desc (where legend is an array 0 - whatever number) that has a description of each map tile). I wasn't sure how I would link a specific td in the page, so I thought a for loop with eq would work. So, I have a 10x10 map, 100 td elements in it. Go from 0 - 99, and on each one, create a hover event that (right now) shows the number in the div with id=test. I tried it with slice as well (the commented out part is my test with eq) to see if that made a difference. What happens is that everything displays 100. Obviously, I'm going about this the wrong way. Any ideas? for(var i = 0; i < 100; ++i) { //$('#map td:eq(' + i + ')').hover( $('#map td').slice(i, i + 1).hover( function() { var y = i / 10; var x = i % 10; $('#test').html(y + ', ' + x); }, function() { $('#test').html(""); }); }
[jQuery] children question
I'm working on a simple editor where I can see the changes as I type them. I got the idea figured out, but I'm selecting everything individually. Here's JS of the one that I have working right now: $(document).ready( function () { $('#newsEdit').focus( function() { editing = "news"; }); $('#newsEdit').blur( function() { editing = "none"; }); $('#newsEdit').keyup( function() { if(editing == 'news') { $('#news').html( $('#newsEdit').val() ); } }); }); var editing = "none"; What I would like to do though, is not have to add each one individually, so that I can maybe just select everything with a certain class, and the and tags would be set with these types of commands. So, if I add another and corresponding (or something) it will automatically be ready to go. I'm just not sure how to do that. I think it has something to do with .children, but the examples in the documentation don't help me with this right now. If someone can point me the direction I need to be going, that would be great. Thanks.
[jQuery] Re: JavaScript question (don't think it's jQuery related)
I'm positive that finishNote is running. I put in an alert before the parseNote, and even inside parseNote, and those run. I get the alert right before the return in parseNote even. I have tested in FireFox with Firebug, and I haven't seen any errors as of yet. Here is a copy of the data I got back in FF. (if it's not the same in IE, I have bigger issues...) {"notecount":1,"notes":[{"note":"this is a new note","dateadded":"2007-05-31 09:01:36"}]} On May 31, 4:36 am, "Rob Desbois" <[EMAIL PROTECTED]> wrote: > Can you / have you tested it with Firefox & Firebug? > Can you provide an example of the JSON data? > Are you certain that the finishNote function is being executed? > > I'm just thinking that it may be that the JSON data is malformed in some way > and that jQuery is failing before it gets called. One thing you could try is > setting up an AJAX error handler: > > $(document).ready(function() { > > >$.ajaxSetup({error: on_ajax_error}); > > }); > > > function on_ajax_error(xhr, error, exception) { > >alert('AJAX error'); > > } > > Bung that in if you haven't got one already and see what happens. > --rob > > On 5/30/07, Brian Ronk <[EMAIL PROTECTED]> wrote: > > > > > > > At first I thought it was a problem with the forms plugin, but I don't > > think so. In IE (6&7) I have an issue related to forms. The data > > that I'm getting back (JSON) isn't being displayed. Here is the > > success function that I have setup for adding a note in my system: > > > function finishNote(json, statusText) { > > notes = noteParse(json.notes); > > > try { > > $('#notes').append(notes); > > $('#notecount').val(json.notecount); > > } > > catch(err) { > > alert("error"); > > //alert(err); > > } > > } > > > I've been putting in alerts to see where it's going, and what's > > happening, and it looks like the noteParse function works correctly, > > but nothing happens after that. I use noteParse in another area, and > > it works correctly, so I would guess that it must be something in this > > one. I just added the try/catch today, and I don't get any alerts > > from that. Also, if I put in an alert right after noteParse, that one > > doesn't run either. > > I really wish that IE had something like FireBug to tell me what > > errors popped up... Does anyone see anything in that function that > > might cause problems? > > -- > Rob Desbois > Eml: [EMAIL PROTECTED] > Tel: 01452 760631 > Mob: 07946 705987 > "There's a whale there's a whale there's a whale fish" he cried, and the > whale was in full view. > ...Then ooh welcome. Ahhh. Ooh mug welcome.
[jQuery] JavaScript question (don't think it's jQuery related)
At first I thought it was a problem with the forms plugin, but I don't think so. In IE (6&7) I have an issue related to forms. The data that I'm getting back (JSON) isn't being displayed. Here is the success function that I have setup for adding a note in my system: function finishNote(json, statusText) { notes = noteParse(json.notes); try { $('#notes').append(notes); $('#notecount').val(json.notecount); } catch(err) { alert("error"); //alert(err); } } I've been putting in alerts to see where it's going, and what's happening, and it looks like the noteParse function works correctly, but nothing happens after that. I use noteParse in another area, and it works correctly, so I would guess that it must be something in this one. I just added the try/catch today, and I don't get any alerts from that. Also, if I put in an alert right after noteParse, that one doesn't run either. I really wish that IE had something like FireBug to tell me what errors popped up... Does anyone see anything in that function that might cause problems?
[jQuery] Re: getJSON() or post() parameter question
Depreciated? On the docs page it gives no indication for that, and it's updated for 1.1.2. Rob said that it was depreciated in 1.1.1 it looks like. Was this not noted somewhere, or maybe it's depreciated in 1.1.3? On May 17, 4:50 pm, Christopher Jordan <[EMAIL PROTECTED]> wrote: > Karl, > > Rob Gonda made the comment on his blog > <http://www.robgonda.com/blog/index.cfm/2007/5/15/AjaxCFC-fastSerializ...> > in responding to one of his readers. > > He said: > > "... BTW, the $.post() function was deprecated with jQuery 1.1 in favor > for .ajax()." > > That's where I read it. Who knows maybe Rob is wrong. Is there an > official list of deprecations for jQuery? > > Chris > > > > Karl Swedberg wrote: > > I could be wrong, but I don't think $.post() is deprecated. > > > --Karl > > _ > > Karl Swedberg > >www.englishrules.com > >www.learningjquery.com > > > On May 17, 2007, at 4:31 PM, Christopher Jordan wrote: > > >> Also, Brian, $.post() has been deprecated in favor of $.ajax(). where > >> you would write something like: > > >> $.ajax({ > >> type: 'POST', > >> url: 'page.php', > >> datatype: 'html', // or json, or xml or script depending on > >> what's getting returned > >> data: {'name':'Joe', 'age':'24',...},//also I think you could > >> pass 24 instead of '24' if you wanted. > >> success: function(data){ > >> // do something upon success > >> }, > >> error:function(data){ > >> // do something if the call fails > >> } > >> }); > > >> or you could create your parameter object like this > >> var params = {}; > >> params.name = 'Joe'; > >> params.age = '24'; > >> params.blah = 'something else'; > > >> then in the ajax call you would just say: > > >> ... > >> data: params, > >> success: function(){ > >> }, > >> ... > > >> Anyway I think that's the preferred method now, but I could be wrong. :o) > > >> Cheers, > >> Chris > > >> Jake McGraw wrote: > >>> $.post() accepts a collection of name/value pairs, I don't think > >>> multi-dimensional arrays/objects work, so what you've already suggested: > > >>> $post('page.php',{name:'Joe',age:'24'},...); > > >>> will work. > > >>> - jake > > >>> On 5/17/07, *Brian Ronk* <[EMAIL PROTECTED] > >>> <mailto:[EMAIL PROTECTED]>> wrote: > > >>> This is actually probably more relevant to post() since I can > >>> concatenate the parameters with the link for getJSON(), but here > >>> we go > >>> anyway. > > >>> I am pulling JSON information from the server for menu links, > >>> and then > >>> creating the menu off of that. Let's say that I have > > >>> {page: 'update.php', linkname: 'Update Joe', vars: [{name: 'name', > >>> value: 'Joe'}, {name: 'age', value: '24'}]} > > >>> as information that was returned for the link from the server (sorry > >>> if the JSON isn't quite right). If I were to put this directly in a > >>> link, it wouldn't be a problem, but since I am trying to put the > >>> info > >>> into a post() as parameters to pass to the server (the vars), I'm > >>> running into an issue of how to do it. > > >>> I was toying with the idea of storing the values in an outside > >>> variable, and just use that in the call: post(' update.php', > >>> varlist); > >>> I'm just not sure how that would work. > > >>> The API info for getJSON and post both have params (Map) and it > >>> looks > >>> like JSON. I guess the problem is that I'm not sure what Map > >>> is, and > >>> how I should be using it. Should I shorten my vars to just: vars: > >>> {name: 'Joe', age: '24'} and use something like: post('update.php', > >>> json.vars)? (Where json is the JSON object that is returned). > > >> -- > >>http://www.cjordan.us > > --http://www.cjordan.us
[jQuery] getJSON() or post() parameter question
This is actually probably more relevant to post() since I can concatenate the parameters with the link for getJSON(), but here we go anyway. I am pulling JSON information from the server for menu links, and then creating the menu off of that. Let's say that I have {page: 'update.php', linkname: 'Update Joe', vars: [{name: 'name', value: 'Joe'}, {name: 'age', value: '24'}]} as information that was returned for the link from the server (sorry if the JSON isn't quite right). If I were to put this directly in a link, it wouldn't be a problem, but since I am trying to put the info into a post() as parameters to pass to the server (the vars), I'm running into an issue of how to do it. I was toying with the idea of storing the values in an outside variable, and just use that in the call: post('update.php', varlist); I'm just not sure how that would work. The API info for getJSON and post both have params (Map) and it looks like JSON. I guess the problem is that I'm not sure what Map is, and how I should be using it. Should I shorten my vars to just: vars: {name: 'Joe', age: '24'} and use something like: post('update.php', json.vars)? (Where json is the JSON object that is returned).
[jQuery] $().click()?
I wanted to look something up, but since the site is moving hosts right now, that makes it a little hard :) is click() an available function? I wanted to add an event to a div that made an area visible to do some editing. I know I could just to an onclick method, but I wanted to try adding something dynamically to see what I could do, and if it was what I wanted. Thanks.