Search Results

Search found 1295 results on 52 pages for 'hook'.

Page 11/52 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • What is a easiest way to implement Mail Server in ubuntu and hook in webmail through XAMPP?

    - by Parris
    Hi Everyone, I currently have xampp running on my ubuntu server. I tried a variety of things including installing, postfix+dovecot+roundcube+postfixadmin (postfix+dovecot work I think, postfix admin also works, roundcube works and connects to dovecot but i cant create user accounts, or figure out how that works), citadel (it installed, but I have no idea how to make it work with xampp for webmail) and i tried messing with exim and vexim a bit also. In short I feel like this should be a lot easier, and I can't figure it out haha. XAMPP works fine. I got my server running with everything. I was thinking about mercury mail, but I need a webmail solution also. I was thinking about google apps, but 50 bucks a year per user is a steep change from free. Thanks for the help!

    Read the article

  • Error while Trying to Hook "TerminateProcess" Function. Target Process crashes. Can anyone help me

    - by desaiparth
    Debugging with visual studio 2005 The following Error Displayed :Unhandled exception at 0x00000000 in procexp.exe: 0xC0000005: Access violation reading location 0x00000000. And Thread Information: 2704 Win32 Thread 00000000 Normal 0 extern "C" VDLL2_API BOOL WINAPI MyTerminateProcess(HANDLE hProcess,UINT uExitCode) { SetLastError(5); return FALSE; } FARPROC HookFunction(char *UserDll,FARPROC pfn,FARPROC HookFunc) { DWORD dwSizeofExportTable=0; DWORD dwRelativeVirtualAddress=0; HMODULE hm=GetModuleHandle(NULL); FARPROC pfnOriginalAddressToReturn; PIMAGE_DOS_HEADER pim=(PIMAGE_DOS_HEADER)hm; PIMAGE_NT_HEADERS pimnt=(PIMAGE_NT_HEADERS)((DWORD)pim + (DWORD)pim-e_lfanew); PIMAGE_DATA_DIRECTORY pimdata=(PIMAGE_DATA_DIRECTORY)&(pimnt-OptionalHeader.DataDirectory); PIMAGE_OPTIONAL_HEADER pot=&(pimnt-OptionalHeader); PIMAGE_DATA_DIRECTORY pim2=(PIMAGE_DATA_DIRECTORY)((DWORD)pot+(DWORD)104); dwSizeofExportTable=pim2-Size; dwRelativeVirtualAddress=pim2-VirtualAddress; char *ascstr; PIMAGE_IMPORT_DESCRIPTOR pimexp=(PIMAGE_IMPORT_DESCRIPTOR)(pim2-VirtualAddress + (DWORD)pim); while(pimexp-Name) { ascstr=(char *)((DWORD)pim + (DWORD)pimexp-Name); if(strcmpi(ascstr,UserDll) == 0) { break; } pimexp++; } PIMAGE_THUNK_DATA pname=(PIMAGE_THUNK_DATA)((DWORD)pim+(DWORD)pimexp-FirstThunk); LPDWORD lpdw=&(pname-u1.Function); DWORD dwError=0; DWORD OldProtect=0; while(pname-u1.Function) { if((DWORD)pname-u1.Function == (DWORD)pfn) { lpdw=&(pname-u1.Function); VirtualProtect((LPVOID)lpdw,sizeof(DWORD),PAGE_READWRITE,&OldProtect); pname-u1.Function=(DWORD)HookFunc; VirtualProtect((LPVOID)lpdw,sizeof(DWORD),PAGE_READONLY,&OldProtect); return pfn; } pname++; } return (FARPROC)0; } FARPROC CallHook(void) { HMODULE hm=GetModuleHandle(TEXT("Kernel32.dll")); FARPROC fp=GetProcAddress(hm,"TerminateProcess"); HMODULE hm2=GetModuleHandle(TEXT("vdll2.dll")); FARPROC fpHook=GetProcAddress(hm2,"MyTerminateProcess"); dwAddOfTerminateProcess=HookFunction("Kernel32.dll",fp,fpHook); if(dwAddOfTerminateProcess == 0) { MessageBox(NULL,TEXT("Unable TO Hook Function."),TEXT("Parth"),MB_OK); } else { MessageBox(NULL,TEXT("Success Hooked."),TEXT("Parth"),MB_OK); } return 0; } Thanks in advance for any help.

    Read the article

  • Silverlight for Windows Embedded tutorial (step 6)

    - by Valter Minute
    In this tutorial step we will develop a very simple clock application that may be used as a screensaver on our devices and will allow us to discover a new feature of Silverlight for Windows Embedded (transforms) and how to use an “old” feature of Windows CE (timers) inside a Silverlight for Windows Embedded application. Let’s start with some XAML, as usual: <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="640" Height="480" FontSize="18" x:Name="Clock">   <Canvas x:Name="LayoutRoot" Background="#FF000000"> <Grid Height="24" Width="150" Canvas.Left="320" Canvas.Top="234" x:Name="SecondsHand" Background="#FFFF0000"> <TextBlock Text="Seconds" TextWrapping="Wrap" Width="50" HorizontalAlignment="Right" VerticalAlignment="Center" x:Name="SecondsText" Foreground="#FFFFFFFF" TextAlignment="Right" Margin="2,2,2,2"/> </Grid> <Grid Height="24" x:Name="MinutesHand" Width="100" Background="#FF00FF00" Canvas.Left="320" Canvas.Top="234"> <TextBlock HorizontalAlignment="Right" x:Name="MinutesText" VerticalAlignment="Center" Width="50" Text="Minutes" TextWrapping="Wrap" Foreground="#FFFFFFFF" TextAlignment="Right" Margin="2,2,2,2"/> </Grid> <Grid Height="24" x:Name="HoursHand" Width="50" Background="#FF0000FF" Canvas.Left="320" Canvas.Top="234"> <TextBlock HorizontalAlignment="Right" x:Name="HoursText" VerticalAlignment="Center" Width="50" Text="Hours" TextWrapping="Wrap" Foreground="#FFFFFFFF" TextAlignment="Right" Margin="2,2,2,2"/> </Grid> </Canvas> </UserControl> This XAML file defines three grid panels, one for each hand of our clock (we are implementing an analog clock using one of the most advanced technologies of the digital world… how cool is that?). Inside each hand we put a TextBlock that will be used to display the current hour, minute, second inside the dial (you can’t do that on plain old analog clocks, but it looks nice). As usual we use XAML2CPP to generate the boring part of our code. We declare a class named “Clock” and derives from the TClock template that XAML2CPP has declared for us. class Clock : public TClock<Clock> { ... }; Our WinMain function is more or less the same we used in all the previous samples. It initializes the XAML runtime, create an instance of our class, initialize it and shows it as a dialog: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { if (!XamlRuntimeInitialize()) return -1;   HRESULT retcode;   IXRApplicationPtr app; if (FAILED(retcode=GetXRApplicationInstance(&app))) return -1; Clock clock;   if (FAILED(clock.Init(hInstance,app))) return -1;     UINT exitcode;   if (FAILED(clock.GetVisualHost()->StartDialog(&exitcode))) return -1;   return exitcode; } Silverlight for Windows Embedded provides a lot of features to implement our UI, but it does not provide timers. How we can update our clock if we don’t have a timer feature? We just use plain old Windows timers, as we do in “regular” Windows CE applications! To use a timer in WinCE we should declare an id for it: #define IDT_CLOCKUPDATE 0x12341234 We also need an HWND that will be used to receive WM_TIMER messages. Our Silverlight for Windows Embedded page is “hosted” inside a GWES Window and we can retrieve its handle using the GetContainerHWND function of our VisualHost object. Let’s see how this is implemented inside our Clock class’ Init method: HRESULT Init(HINSTANCE hInstance,IXRApplication* app) { HRESULT retcode;   if (FAILED(retcode=TClock<Clock>::Init(hInstance,app))) return retcode;   // create the timer user to update the clock HWND clockhwnd;   if (FAILED(GetVisualHost()->GetContainerHWND(&clockhwnd))) return -1;   timer=SetTimer(clockhwnd,IDT_CLOCKUPDATE,1000,NULL); return 0; } We use SetTimer to create a new timer and GWES will send a WM_TIMER to our window every second, giving us a chance to update our clock. That sounds great… but how could we handle the WM_TIMER message if we didn’t implement a window procedure for our window? We have to move a step back and look how a visual host is created. This code is generated by XAML2CPP and is inside xaml2cppbase.h: virtual HRESULT CreateHost(HINSTANCE hInstance,IXRApplication* app) { HRESULT retcode; XRWindowCreateParams wp;   ZeroMemory(&wp, sizeof(XRWindowCreateParams)); InitWindowParms(&wp);   XRXamlSource xamlsrc;   SetXAMLSource(hInstance,&xamlsrc); if (FAILED(retcode=app->CreateHostFromXaml(&xamlsrc, &wp, &vhost))) return retcode;   if (FAILED(retcode=vhost->GetRootElement(&root))) return retcode; return S_OK; } As you can see the CreateHostFromXaml function of IXRApplication accepts a structure named XRWindowCreateParams that control how the “plain old” GWES Window is created by the runtime. This structure is initialized inside the InitWindowParm method: // Initializes Windows parameters, can be overridden in the user class to change its appearance virtual void InitWindowParms(XRWindowCreateParams* wp) { wp->Style = WS_OVERLAPPED; wp->pTitle = windowtitle; wp->Left = 0; wp->Top = 0; } This method set up the window style, title and position. But the XRWindowCreateParams contains also other fields and, since the function is declared as virtual, we could initialize them inside our version of InitWindowParms: // add hook procedure to the standard windows creation parms virtual void InitWindowParms(XRWindowCreateParams* wp) { TClock<Clock>::InitWindowParms(wp);   wp->pHookProc=StaticHostHookProc; wp->pvUserParam=this; } This method calls the base class implementation (useful to not having to re-write some code, did I told you that I’m quite lazy?) and then initializes the pHookProc and pvUserParam members of the XRWindowsCreateParams structure. Those members will allow us to install a “hook” procedure that will be called each time the GWES window “hosting” our Silverlight for Windows Embedded UI receives a message. We can declare a hook procedure inside our Clock class: // static hook procedure static BOOL CALLBACK StaticHostHookProc(VOID* pv,HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam,LRESULT* pRetVal) { ... } You should notice two things here. First that the function is declared as static. This is required because a non-static function has a “hidden” parameters, that is the “this” pointer of our object. Having an extra parameter is not allowed for the type defined for the pHookProc member of the XRWindowsCreateParams struct and so we should implement our hook procedure as static. But in a static procedure we will not have a this pointer. How could we access the data member of our class? Here’s the second thing to notice. We initialized also the pvUserParam of the XRWindowsCreateParams struct. We set it to our this pointer. This value will be passed as the first parameter of the hook procedure. In this way we can retrieve our this pointer and use it to call a non-static version of our hook procedure: // static hook procedure static BOOL CALLBACK StaticHostHookProc(VOID* pv,HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam,LRESULT* pRetVal) { return ((Clock*)pv)->HostHookProc(hwnd,Msg,wParam,lParam,pRetVal); } Inside our non-static hook procedure we will have access to our this pointer and we will be able to update our clock: // hook procedure (handles timers) BOOL HostHookProc(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam,LRESULT* pRetVal) { switch (Msg) { case WM_TIMER: if (wParam==IDT_CLOCKUPDATE) UpdateClock(); *pRetVal=0; return TRUE; } return FALSE; } The UpdateClock member function will update the text inside our TextBlocks and rotate the hands to reflect current time: // udates Hands positions and labels HRESULT UpdateClock() { SYSTEMTIME time; HRESULT retcode;   GetLocalTime(&time);   //updates the text fields TCHAR timebuffer[32];   _itow(time.wSecond,timebuffer,10);   SecondsText->SetText(timebuffer);   _itow(time.wMinute,timebuffer,10);   MinutesText->SetText(timebuffer);   _itow(time.wHour,timebuffer,10);   HoursText->SetText(timebuffer);   if (FAILED(retcode=RotateHand(((float)time.wSecond)*6-90,SecondsHand))) return retcode;   if (FAILED(retcode=RotateHand(((float)time.wMinute)*6-90,MinutesHand))) return retcode;   if (FAILED(retcode=RotateHand(((float)(time.wHour%12))*30-90,HoursHand))) return retcode;   return S_OK; } The function retrieves current time, convert hours, minutes and seconds to strings and display those strings inside the three TextBlocks that we put inside our clock hands. Then it rotates the hands to position them at the right angle (angles are in degrees and we have to subtract 90 degrees because 0 degrees means horizontal on Silverlight for Windows Embedded and usually a clock 0 is in the top position of the dial. The code of the RotateHand function uses transforms to rotate our clock hands on the screen: // rotates a Hand HRESULT RotateHand(float angle,IXRFrameworkElement* Hand) { HRESULT retcode; IXRRotateTransformPtr rotatetransform; IXRApplicationPtr app;   if (FAILED(retcode=GetXRApplicationInstance(&app))) return retcode;   if (FAILED(retcode=app->CreateObject(IID_IXRRotateTransform,&rotatetransform))) return retcode;     if (FAILED(retcode=rotatetransform->SetAngle(angle))) return retcode;   if (FAILED(retcode=rotatetransform->SetCenterX(0.0))) return retcode;   float height;   if (FAILED(retcode==Hand->GetActualHeight(&height))) return retcode;   if (FAILED(retcode=rotatetransform->SetCenterY(height/2))) return retcode; if (FAILED(retcode=Hand->SetRenderTransform(rotatetransform))) return retcode;   return S_OK; } It creates a IXRotateTransform object, set its rotation angle and origin (the default origin is at the top-left corner of our Grid panel, we move it in the vertical center to keep the hand rotating around a single point in a more “clock like” way. Then we can apply the transform to our UI object using SetRenderTransform. Every UI element (derived from IXRFrameworkElement) can be rotated! And using different subclasses of IXRTransform also moved, scaled, skewed and distorted in many ways. You can also concatenate multiple transforms and apply them at once suing a IXRTransformGroup object. The XAML engine uses vector graphics and object will not look “pixelated” when they are rotated or scaled. As usual you can download the code here: http://cid-9b7b0aefe3514dc5.skydrive.live.com/self.aspx/.Public/Clock.zip If you read up to (down to?) this point you seem to be interested in Silverlight for Windows Embedded. If you want me to discuss some specific topic, please feel free to point it out in the comments! Technorati Tags: Silverlight for Windows Embedded,Windows CE

    Read the article

  • UppercuT &ndash; Custom Extensions Now With PowerShell and Ruby

    Arguably, one of the most powerful features of UppercuT (UC) is the ability to extend any step of the build process with a pre, post, or replace hook. This customization is done in a separate location from the build so you can upgrade without wondering if you broke the build. There is a hook before each step of the build has run. There is a hook after. And back to power again, there is a replacement hook. If you dont like what the step is doing and/or you want to replace its entire functionality,...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • UppercuT &ndash; Custom Extensions Now With PowerShell and Ruby

    Arguably, one of the most powerful features of UppercuT (UC) is the ability to extend any step of the build process with a pre, post, or replace hook. This customization is done in a separate location from the build so you can upgrade without wondering if you broke the build. There is a hook before each step of the build has run. There is a hook after. And back to power again, there is a replacement hook. If you dont like what the step is doing and/or you want to replace its entire functionality,...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • svn post-commit not performing

    - by davin
    ive been sitting on this for about 7 hours, and ive aged close to 7 years... ahhh, server admin does that to me. i have svn wired through apache2 with webdav in the usual manner (basically like http://www.howtoforge.com/setting-up-subversion-with-webdav-post-commit-hook-and-multiple-sites-on-jaunty-jackalope-ubuntu-9.04). ive had endless problems with this (i didnt on my previous ubuntu server install, although this is ubuntu 10.10): this happened, and was fixed like in the post: http://stackoverflow.com/questions/2547400/how-do-you-fix-an-svn-409-conflict-error this looks like my issue, although its not my solution: http://serverfault.com/questions/135494/apache-svn-on-ubuntu-post-commit-hook-fails-silently-pre-commit-hook-permis my commit to svn works (finally). although the post-commit hook which is supposed to svn update the working copy of the repo on the server, doesn't work. the post-commit hook itself executes, and has sudo permissions (as in the setup url above. testing with whoami somelogfile.log or sudo whoami somelogfile.log shows www-data and root, respectively), although it wont perform the svn update (sudo svn update /var/www/gameServer /var/svn/gameServer.log). similar to the serverfault url above, when i perform the exact command it does update the working copy to the latest revision, just not through the post-commit hook. an age old question that is 90% of the time a permissions issue. but in pure frustration i chmod 777 lots of stuff not to mention the fact that www-data is in /etc/sudoer so it shouldnt even need that. im collapsing in front of the screen partly out of frustration and partly out of sleepiness. any direction would be appreciated.

    Read the article

  • Upgrade Ubuntu 12.04 to 12.10 failed

    - by pre-commit-hook
    I've a problem. Upgrade failed after "Setting new software channels", when Calculating changes. I tried error: Not all updates can be installed An unresolvable problem occurred while calculating the upgrade: E:Unable to correct problems, you have held broken packages. This can be caused by: * Upgrading to a pre-release version of Ubuntu * Running the current pre-release version of Ubuntu * Unofficial software packages not provided by Ubuntu If none of this applies, then please report this bug using the command 'ubuntu-bug ubuntu-release-upgrader-core' in a terminal. Now i have 1580 packages to update and do not update. Partial system upgrade also fails in the first step. What next? Alternatively, to undo the changes? Thank's to help.

    Read the article

  • how to hook up default beforeunload event on an aspx page ?

    - by Nikhil Vaghela
    I have a custom web part placed on one of the application page in SharePoint. This page it seems already have a function which gets executed on windows beforeunload javascript event. My problem is that i too need to execute some client side code (to prompt user for any unsaved changes in my web part) on windows beforeunload event. How can i achieve this ? I mean let the default event be fired as well as call my function also ? Appreciate any help. Nikhil.

    Read the article

  • Is it possible to have a global exception hook?

    - by Heinrich Ulbricht
    Hi, my code is fairly well covered with exception handling (try..except). Some exceptions are not expected to happen and some exceptions happen fairly often, which is expected and ok. Now I want to add some automated tests for this code. It would be good to know how many exceptions happened during execution, so I can later see if the expected number was raised or anything unexpected happened. I don't want to clutter every exception handling block with debug code, so my question is: Is there a way to install some kind of global exception handler which sits right before all other exception handling blocks? I am searching for a central place to log these exceptions. Thanks for any suggestions! (And if this matters: it is Delphi 2009)

    Read the article

  • How do I hook up a custom tab bar build in IB to a UINavigationController Object instanced in XCODE?

    - by David Hsu
    What I did to create the custom NAV BAR: 1. Created an empty XIB and added a view with class UINavigationController. 2. Under the view I added the navigation bar and a left and right button onto the nav bar. 3. Control drag from "File Owner" to "View" Inside my class where I call the modal view navigation controller: SignupViewController *addController = [[SignupViewController alloc] initWithNibName:@"SignupViewController" bundle:nil]; // Create the navigation controller and present it modally. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController]; navigationController.navigationBar = ///WHAT SHOULD GO HERE? [self presentModalViewController:navigationController animated:YES]; Thank in advance!

    Read the article

  • C#: Hook up all events from object in single statement.

    - by David
    In my domain layer all domain objects emit events (of type InvalidDomainObjectEventHandler) to indicate invalid state when the IsValid property is called. On an aspx codebehind, I have to manually wire up the events for the domain object like this: _purchaseOrder.AmountIsNull += new DomainObject.InvalidDomainObjectEventHandler(HandleDomainObjectEvent); _purchaseOrder.NoReason += new DomainObject.InvalidDomainObjectEventHandler(HandleDomainObjectEvent); _purchaseOrder.NoSupplier += new DomainObject.InvalidDomainObjectEventHandler(HandleDomainObjectEvent); _purchaseOrder.BothNewAndExistingSupplier += new DomainObject.InvalidDomainObjectEventHandler(HandleDomainObjectEvent); Note that the same method is called in each case since the InvalidDomainobjectEventArgs class contains the message to display. Is there any way I can write a single statement to wire up all events of type InvalidDomainObjectEventHandler in one go? Thanks David

    Read the article

  • How and Where do I learn about how to hook up my uncreated Database to a 3rd party API

    - by raln
    I want to create a database with information that I can send to a third party... they give their api on their website but they don't break it down for new / newbs like myself... I'm confused and was thinking of getting a developer to do this all for me but I DON'T want to get ripped off... and overpay All it is is a webapplication backed by a database onto their platform where they support different API's but I also need a function in my web app that can send various messages via XML, or SMPP to their webservice.. . hmm -Ken

    Read the article

  • In Spring MVC (2.0) how can you easily hook multiple pages/urls to use 1 controller?

    - by danny
    <!--dispatcher file--> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/foo/bar/baz/boz_a.html">bozController</prop> </props> </property> </bean> <!--mappings file--> <bean id="bozController" class="com.mycompany.foo.bar.baz.BozController"> <property name="viewPathA" value="foo/bar/baz/boz_a" /> <property name="viewPathB" value="foo/bar/baz/boz_b" /> ... <property name="viewPathZ" value="foo/bar/baz/boz_z" /> </bean> how do I set it up so that when the user loads page boz_w.html it uses the bozController, and sets the viewPath to use boz_w.jsp?

    Read the article

  • How to filter Wordpress posts using a hook in a plugin?

    - by Davide
    I'm creating a Wordpress plugin and, being a newbie in the development on this platform, I'm stuck on this problem. I'd like to have posts in the loop filtered by categories, defined by the user through an admin page. I would actually like to be able to modify query_post() parameters in the plugin, but the only trick I found is to re-run the query_post() with my user-defined criteria, thing that I would like to avoid. I'm sure the solution is evident, but can't find it!

    Read the article

  • How do I hook into a game and write a script to manipulate it?

    - by Ethan
    Hey SO, I know this is a pretty open question but I was wondering how people go about writing scripts that will "play" a game, or manipulate it in some way. I had been thinking that I'd try to get a working AI to play a game for fun, but don't even really know where to start. Are there any good resources to learn this? What are good languages to use? Once I have the language, how do I get my script hooked into the game? I was thinking of just trying simple flash games, if that helps. Thanks a bunch!

    Read the article

  • How to hook to a keystroke under Windows Vista?

    - by Dave
    Hi. I'm working on a program idea which needs to respond when a particular Function key is pressed on the keyboard(like F10). (A) is that possible? (B) what language should i use (i'll be getting the development outsourced, so its not a problem) (c) any sample code which shows how it works?

    Read the article

  • How to hook onclick event for each cell in a table in Javascript?

    - by MartyIX
    I was thinking if there's a better solution for adding onclick handler to each cell in a table than this approach: http://stackoverflow.com/questions/1207939/adding-an-onclick-event-to-a-table-row Better in the way that I wouldn't need to set "cell.onclick = function" for each cell. I just need to get the coordinations of a cell where user clicked. Thanks!

    Read the article

  • Non-Dom Element Event Binding with jQuery

    - by Rick Strahl
    Yesterday I had a short discussion with Dave Reed on Twitter regarding setting up fake ‘events’ on objects that are hookable. jQuery makes it real easy to bind events on DOM elements and with a little bit of extra work (that I didn’t know about) you can also set up binding to non-DOM element ‘event’ bindings. Assume for a second that you have a simple JavaScript object like this: var item = { sku: "wwhelp" , foo: function() { alert('orginal foo function'); } }; and you want to be notified when the foo function is called. You can use jQuery to bind the handler like this: $(item).bind("foo", function () { alert('foo Hook called'); } ); Binding alone won’t actually cause the handler to be triggered so when you call: item.foo(); you only get the ‘original’ message. In order to fire both the original handler and the bound event hook you have to use the .trigger() function: $(item).trigger("foo"); Now if you do the following complete sequence: var item = { sku: "wwhelp" , foo: function() { alert('orginal foo function'); } }; $(item).bind("foo", function () { alert('foo hook called'); } ); $(item).trigger("foo"); You’ll see the ‘hook’ message first followed by the ‘original’ message fired in succession. In other words, using this mechanism you can hook standard object functions and chain events to them in a way similar to the way you can do with DOM elements. The main difference is that the ‘event’ has to be explicitly triggered in order for this to happen rather than just calling the method directly. .trigger() relies on some internal logic that checks for event bindings on the object (attached via an expando property) which .trigger() searches for in its bound event list. Once the ‘event’ is found it’s called prior to execution of the original function. This is pretty useful as it allows you to create standard JavaScript objects that can act as event handlers and are effectively hookable without having to explicitly override event definitions with JavaScript function handlers. You get all the benefits of jQuery’s event methods including the ability to hook up multiple events to the same handler function and the ability to uniquely identify each specific event instance with post fix string names (ie. .bind("MyEvent.MyName") and .unbind("MyEvent.MyName") to bind MyEvent). Watch out for an .unbind() Bug Note that there appears to be a bug with .unbind() in jQuery that doesn’t reliably unbind an event and results in a elem.removeEventListener is not a function error. The following code demonstrates: var item = { sku: "wwhelp", foo: function () { alert('orginal foo function'); } }; $(item).bind("foo.first", function () { alert('foo hook called'); }); $(item).bind("foo.second", function () { alert('foo hook2 called'); }); $(item).trigger("foo"); setTimeout(function () { $(item).unbind("foo"); // $(item).unbind("foo.first"); // $(item).unbind("foo.second"); $(item).trigger("foo"); }, 3000); The setTimeout call delays the unbinding and is supposed to remove the event binding on the foo function. It fails both with the foo only value (both if assigned only as “foo” or “foo.first/second” as well as when removing both of the postfixed event handlers explicitly. Oddly the following that removes only one of the two handlers works: setTimeout(function () { //$(item).unbind("foo"); $(item).unbind("foo.first"); // $(item).unbind("foo.second"); $(item).trigger("foo"); }, 3000); this actually works which is weird as the code in unbind tries to unbind using a DOM method that doesn’t exist. <shrug> A partial workaround for unbinding all ‘foo’ events is the following: setTimeout(function () { $.event.special.foo = { teardown: function () { alert('teardown'); return true; } }; $(item).unbind("foo"); $(item).trigger("foo"); }, 3000); which is a bit cryptic to say the least but it seems to work more reliably. I can’t take credit for any of this – thanks to Dave Reed and Damien Edwards who pointed out some of these behaviors. I didn’t find any good descriptions of the process so thought it’d be good to write it down here. Hope some of you find this helpful.© Rick Strahl, West Wind Technologies, 2005-2010Posted in jQuery  

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >