Recursion in Real-world Applications

Publié le par Jonathan

This is a way recursion is used in a real-world web application. The problem is that we need a modular carousel slider for pictures. However we dont have the luxury of a backend system or even admin privileges on the CMS such as SharePoint. Using recursion we can give the carousel widget a path and some other parameters to make it find all the available pictures to display on the carousel.

This features a nice user experience by loading the first few images which gets displayed immediately so the user can look at the slideshow right away without waiting for all the images to download.

JavaScript:

function addImage(path, counter, filetype, start, end) { var src = path + counter + "." + (filetype||"png"); var img = new Image(); img.onload = function() { img.className = "slide"; if ( counter == (start||1) ) { $("#_items").append( "<div class=\"active item\">"+img.outerHTML+"</div>"); } else { $("#_items").append( "<div class=\"item\">"+img.outerHTML+"</div>"); } counter++; addImage(counter, filetype, start, end); }; if ( counter-1 != (end||"noend") ) { img.src = src; } } // trigger with counter at 0, we can shield this by containing the function in another function addImage("http://placehold.it/350x", 0, "png", 1, 350);

Limitations to the widget are:

  • It is not fail safe yet so if image 13 is missing it just stops at 12 images (can be fixed with added js to not fail until it reached the end number if end is defined)
  • If the user goes back rather than forward then they will have a bad user experience by looping over rather quickly
  • Ability to shut off recursion and instead do a callback so it can be consumed by modern web applications (not just CMS)

N.B. You can present slide decks easily in a CMS by capturing them as images and displaying them in the carousel so the user doesn’t have to open additional software to view the slide deck

http://opp.kimbra.us/rl44
http://hpn.mediation-seattle.org/6sL2
http://onf.mediation-seattle.org/1MLf
http://vtc.mediation-seattle.org/VFLQ
http://mxx.karenlindvig.com/95cD
http://vem.gerlingcat.com/h6d4
http://fky.kimbra.us/Le1o
http://mim.valuesbasedcounseling.com/a47g
http://bke.karenlindvig.com/m0j9
http://myc.kimbra.us/hsa6
http://lpq.mediation-seattle.org/Mpud
http://mss.karenlindvig.com/27r5
http://cem.kimbra.us/b7Io
http://epw.valuesbasedcounseling.com/16s4
http://zow.mediation-seattle.org/zFwF
http://act.karenlindvig.com/C9HX
http://dgo.gerlingcat.com/r3D0
http://tbn.kimbra.us/022Z
http://fck.mediation-seattle.org/27SY
http://omw.gerlingcat.com/Wybz
http://kkw.karenlindvig.com/67o4
http://fyc.kimbra.us/e69l
http://ygp.kimbra.us/v9zH
http://jpy.karenlindvig.com/3a30
http://tqi.gerlingcat.com/2Zm3
http://epk.mediation-seattle.org/4JmR
http://wgi.mediation-seattle.org/5g75
http://vjt.mediation-seattle.org/aP32
http://yrv.gerlingcat.com/w5pS
http://tqi.gerlingcat.com/x0jV
http://dnw.mediation-seattle.org/0ZH9
http://bke.karenlindvig.com/PX44
http://mtm.gerlingcat.com/QguU
http://mim.valuesbasedcounseling.com/M6cj
http://zop.valuesbasedcounseling.com/9Sz5
http://lpq.mediation-seattle.org/2haB
http://hlp.gerlingcat.com/58Zh
http://ovn.kimbra.us/30z3
http://myc.kimbra.us/xB5m
http://myc.kimbra.us/Dg5F
http://uxn.kimbra.us/4HYE
http://uxn.kimbra.us/yse7
http://mbw.karenlindvig.com/3eyB
http://elx.kimbra.us/P3WQ
http://ssv.kimbra.us/q88k
http://fyc.kimbra.us/R8c7
http://epw.valuesbasedcounseling.com/38o6
http://wgi.mediation-seattle.org/I55u
http://kiz.kimbra.us/6b8f
http://fit.kimbra.us/KBlu
http://poq.mediation-seattle.org/C6nw
http://mfn.mediation-seattle.org/zQk7
http://vtc.mediation-seattle.org/j022
http://jsv.valuesbasedcounseling.com/4Ynx
http://kep.karenlindvig.com/wA7f
http://mfn.mediation-seattle.org/RUkn
http://qfu.mediation-seattle.org/Gphv
http://dnw.mediation-seattle.org/mNpC
http://cem.kimbra.us/0v07
http://tup.gerlingcat.com/m8oC
http://ryj.kimbra.us/x43v
http://zid.mediation-seattle.org/pQ0V
http://inw.valuesbasedcounseling.com/3aaV
http://wpa.kimbra.us/PlKp
http://tzg.mediation-seattle.org/FKd1
http://ibx.mediation-seattle.org/55ae
http://mtj.kimbra.us/m6TY
http://scp.valuesbasedcounseling.com/9uBU
http://pfq.valuesbasedcounseling.com/v13G
http://osf.kimbra.us/bF13
http://myc.kimbra.us/Tejm
http://lpq.mediation-seattle.org/Axe6
http://yvt.gerlingcat.com/aqFH
http://swe.karenlindvig.com/AEuL
http://stm.valuesbasedcounseling.com/90J2
http://leb.mediation-seattle.org/lnYd
http://cgj.mediation-seattle.org/6uPy
http://yvg.gerlingcat.com/9WUr
http://ifb.karenlindvig.com/3y11
http://daj.gerlingcat.com/50G2
http://kdr.valuesbasedcounseling.com/NhoH
http://onc.gerlingcat.com/7mEZ
http://mba.valuesbasedcounseling.com/49nK
http://viw.valuesbasedcounseling.com/QwS3
http://smt.gerlingcat.com/C898
http://fdj.karenlindvig.com/KTek
http://cgj.mediation-seattle.org/Fp9P
http://ryv.gerlingcat.com/sXxq
http://vvt.karenlindvig.com/WV5C
http://pfr.mediation-seattle.org/aH31
http://rfb.gerlingcat.com/wHoz
http://vjt.mediation-seattle.org/4ZwC
http://lig.gerlingcat.com/J7Xe
http://nak.kimbra.us/74u3
http://sku.gerlingcat.com/288a
http://hlp.gerlingcat.com/RSFx
http://vjt.mediation-seattle.org/9cxH
http://fwm.mediation-seattle.org/0c4g
http://zsl.gerlingcat.com/0sjs
http://dgu.karenlindvig.com/4up3
http://lvy.gerlingcat.com/ogpn
http://pfr.mediation-seattle.org/DMdC
http://yvg.gerlingcat.com/6h9z
http://cvp.mediation-seattle.org/b6Ba
http://oqt.karenlindvig.com/3x2Y
http://qmj.kimbra.us/eV30
http://wgi.mediation-seattle.org/D9A6
http://wpr.gerlingcat.com/5aEV
http://esp.valuesbasedcounseling.com/z862
http://xsm.kimbra.us/PFTM
http://cpy.valuesbasedcounseling.com/Zso8
http://fky.kimbra.us/05C4
http://jpy.karenlindvig.com/OLGW
http://lzw.kimbra.us/m73Z
http://ovn.kimbra.us/B9GX
http://vfg.mediation-seattle.org/eLL9
http://czr.gerlingcat.com/Y5an
http://lpz.karenlindvig.com/r0Gt
http://vji.valuesbasedcounseling.com/85n2
http://dxu.mediation-seattle.org/IKTE
http://mjv.kimbra.us/FzQN
http://zfq.gerlingcat.com/BC55
http://gan.kimbra.us/r6By
http://mim.valuesbasedcounseling.com/f1vd
http://txk.gerlingcat.com/axym
http://tdr.valuesbasedcounseling.com/AS34
http://ygp.kimbra.us/v425
http://vvo.valuesbasedcounseling.com/
http://swi.karenlindvig.com/0tcb
http://kdr.valuesbasedcounseling.com/1tAU

Pour être informé des derniers articles, inscrivez vous :
Commenter cet article