文献翻译JQuery标签的使用.docx
- 文档编号:28114346
- 上传时间:2023-07-08
- 格式:DOCX
- 页数:22
- 大小:360.52KB
文献翻译JQuery标签的使用.docx
《文献翻译JQuery标签的使用.docx》由会员分享,可在线阅读,更多相关《文献翻译JQuery标签的使用.docx(22页珍藏版)》请在冰豆网上搜索。
文献翻译JQuery标签的使用
本科毕业设计
外文文献及译文
文献、资料题目:
JqueryInAction—UsingthejQuery
flags
文献、资料来源:
著作
文献、资料发表(出版)日期:
2008.7.15院(部):
专
班
姓
学
业:
级:
名:
号:
指导教师:
翻译日期:
1
外文文献:
DOMwithjQueryutilityfunctions—UsingthejQueryflags6.1UsingthejQueryflags
SomeoftheinformationjQuerymakesavailabletousaspageauthors,andevenpluginauthors,isavailablenotviamethodsorfunctionsbutaspropertiesdefinedon$.Manyoftheseflagsarefocusedonhelpingusdivinethecapabilitiesofthecurrentbrowser,butothershelpuscontrolthebehaviorofjQueryatapage-globallevel.
ThejQueryflagsintendedforpublicuseareasfollows:
$.fx.off—Enablesordisabledeffects
$.support—Detailssupportedfeatures
$.browser—Exposesbrowserdetails(officiallydeprecated)
Let’sstartbylookingathowjQueryletsusdisableanimations.
6.1.1Disablinganimations
Theremaybetimeswhenwemightwanttoconditionallydisableanimationsinapagethatincludesvariousanimatedeffects.Wemightdosobecausewe’vedetectedthattheplatformordeviceisunlikelytodealwiththemwell,orperhapsforaccessibilityreasons.
Inanycase,wedon’tneedtoresorttowritingtwopages,onewithandonewithoutanimations.Whenwedetectwe’reinananimation-adverseenvironment,wecansimplysetthevalueof$.fx.offtotrue.
Thiswillnotsuppressanyeffectswe’veusedonthepage;itwillsimplydisabletheanimationofthoseeffects.Forexample,thefadeeffectswillshowandhidetheelementsimmediately,withouttheinterveninganimations.
Similarly,callstotheanimate()methodwillsettheCSSpropertiestothespecified
finalvalueswithoutanimatingthem.UsingthejQueryflags
Onepossibleuse-caseforthisflagmightbeforcertainmobiledevicesorbrowsersthatdon’tcorrectlysupportanimations.Inthatcase,youmightwanttoturnoffanimations
1
sothatthecorefunctionalitystillworks.The$.fx.offflagisaread/writeflag.Theremainingpredefinedflagsaremeanttoberead-only.Let’stakealookattheflagthatgivesusinformationontheenvironmentprovidedbytheuseragent(browser).
6.1.2Detectinguseragentsupport
Thankfully,almostblissfully,thejQuerymethodsthatwe’veexaminedsofarshieldusfromhavingtodealwithbrowserdifferences,evenintraditionallyproblematicareaslikeeventhandling.Butwhenwe’retheoneswritingthesemethods(orotherextensions),wemayneedtoaccountforthedifferencesinthewaysbrowsersoperatesothattheusersofourextensionsdon’thaveto.
BeforewediveintoseeinghowjQueryhelpsusinthisregard,let’stalkaboutthewholeconceptofbrowserdetection.
WHYBROWSERDETECTIONISHEINOUSOK,maybethewordheinousistoostrong,butunlessit’sabsolutelynecessary,thebrowserdetectiontechniqueshouldbeavoided.
Browserdetectionmightseem,atfirst,likealogicalwaytodealwithbrowserdifferences.
Afterall,it’seasytosay,“IknowwhatthesetofcapabilitiesofbrowserXare,sotestingforthebrowsermakesperfectsense,right?
”Butbrowserdetectionisfullofpitfallsandproblems.
Oneofthemajorargumentsagainstthistechniqueisthattheproliferationofbrowsers,aswellasvaryinglevelsofsupportwithinversionsofthesamebrowser,makesthistechniqueanunscalableapproachtotheproblem.
Youcouldbethinking,“Well,allIneedtotestforisInternetExplorerandFire-fox.”ButwhywouldyouexcludethegrowingnumberofSafariusers?
WhataboutOperaandGoogle’sChrome?
Moreover,therearesomeniche,butnotinsignificant,browsersthatsharecapabilityprofileswiththemorepopularbrowsers.Camino,forexample,usesthesametechnologyasFirefoxbehinditsMac-friendlyUI.AndOmniWebusesthesamerenderingengineasSafariandChrome.
There’snoneedtoexcludesupportforthesebrowsers,butitisaroyalpaintohave
2
totestforthem.Andthat’swithoutevenconsideringdifferencesbetweenversions—IE6,IE7,andIE8,forexample.
Yetanotherreasonisthatifwetestforaspecificbrowser,andafuturereleasefixesthatbug,ourcodemayactuallystopworking.jQuery’salternativeapproachtothisissue(whichwe’lldiscussinthenextsection)givesbrowservendorsanincentivetofixthebugsthatjQueryhasworkedaround.
Afinalargumentagainstbrowserdetection(orsniffing,asit’ssometimescalled)isthatit’sgettingharderandhardertoknowwho’swho.
Arowsersidentifythemselvesbysettingarequestheaderknownastheuseragentstring.Parsingthisstringisn’tforthefaint-hearted.Inaddition,manybrowsersnowallowtheiruserstospoofthisstring,sowecan’tevenbelievewhatittellsusafterwedogothoughallthetroubleofparsingit!
AJavaScriptobjectnamednavigatorgivesusapartialglimpseintotheuseragentinformation,butevenithasbrowserdifferences.Wealmostneedtodobrowserdetectioninordertodobrowserdetection!
Stopthemadness!
BrowserdetectionisImprecise,accidentallyblockingbrowserswithinwhichourcodewouldactuallyworkUnscalable,leadingtoenormousnestedifandif-elsestatementstosortthingsoutInaccurate,duetousersspoofinguseragentinformationObviously,we’dliketoavoidusingitwheneverpossible.Butwhatcanwedoinstead?
WHAT’STHEALTERNATIVETOBROWSERDETECTION?
Ifwethinkaboutit,we’renotreallyinterestedinwhichbrowseranyoneisusing,arewe?
Theonlyreasonwe’reeventhinkingaboutbrowserdetectionissothatwecanknowwhichcapabilitiesandfeatureswecanuse.It’sthecapabilitiesandfeaturesofabrowserthatwe’rereallyafter;usingbrowserdetectionisjustaham-handedwayoftryingtodeterminewhatthosefeaturesandcapabilitiesare.
Sowhydon’twejustfigureoutwhatthosefeaturesareratherthantryingtoinferthemfromthebrowseridentification?
Thetechniqueknownbroadlyasfeaturedetectionallowscodetobranchbasedonwhethercertainobjects,properties,orevenmethodsexist.
3
Let’sthinkbacktochapter4oneventhandlingasanexample.Rememberthattherearetwoadvancedevent-handlingmodels:
theW3CstandardDOMLevel2EventModelandtheproprietaryInternetExplorerEventModel.BothmodelsdefinemethodsontheDOMelementsthatallowlistenerstobeestablished,buteachusesdifferentmethodnames.ThestandardmodeldefinesthemethodaddEventListener(),whereastheIEmodeldefinesattachEvent().
Usingbrowserdetection,andassumingthatwe’vegonethroughthepainandaggravationofdeterminingwhichbrowserisbeingused(maybeevencorrectly),wecouldwritecomplexcodetosetflags:
isIE,isFirefox,andisSafari
if(isIE){
element.attachEvent('onclick',someHandler);
}
elseif(isFirefox||isSafari){
element.addEventListener('click',someHandler);
}
else{
thrownewError('eventhandlingnotsupported');
}
Asidefromthefactthatthisexampleglossesoverwhatevernecessarilycomplexcodewe’reusingtosettheflagsisIE,isFirefox,andisSafari,wecan’tbesureiftheseflagsaccuratelyrepresentthebrowserbeingused.Moreover,thiscodewillthrowanerrorifusedinOpera,Chrome,Camino,OmniWeb,orahostofotherlesser-knownbrowsersthatmightperfectlysupportthestandardmodel.Considerthefollowingvariationofthiscode:
if(element.attachEvent){
element.attachEvent('onclick',someHandler);
}
elseif(element.addEventListener){
element.addEventListener('click',someHandler);
}
else{
thrownewError('eventhandlingnotsupported');
}
Thiscodedoesn’tperformalotofcomplex,andultimatelyunreliable,browserdetection,anditautomaticallysupportsallbrowsersthatsupporteitherofthetwocompetingeventmodels.Muchbetter!
4
Featuredetectionisvastlysuperiortobrowserdetection.It’smorereliable,anditdoesn’taccidentallyblockbrowsersthatsupportthecapabilitywe’retestingforsimplybecausewedon’tknowaboutthefeaturesofthatbrowser,orevenofthebrowseritself.DidyouaccountforGoogleChromeinyourmostrecentwebapplication?
iCab?
Epiphany?
Konqueror?
NOTEEvenfeaturedetectionisbestavoidedunlessabsolutelyrequired.Ifwecancomeupwithacross-browsersolution,itshouldbepreferredoverany
typeofbranching.
Butassuperiortobrowserdetectionasfeaturedetectionmaybe,itcanstillbenowalkinthepark.Branchinganddetectionofanytypecanstillbetediousandpainfulinourpages,andsomefeaturedifferencescanbedecidedlydifficulttodetect,requiringnontrivialordownrightcomplexchecks.jQuerycomestoouraidbyperformingthosechecksforusandsupplyingtheresultsinasetofflagsthatdetectthemostcommonuseragentfeaturesthatwemightcareabout.
THEJQUERYBROWSERCAPABILITYFLAGS
ThebrowsercapabilityflagsareexposedtousaspropertiesofjQuery’s$.supportobject.
Table6.1summarizestheflagsthatareavailableinthisobject.
Table6.1The$.supportbrowsercapabilityflags
FlagpropertyDescriptionboxModelcssFloatSettotrueiftheuseragentrendersaccordingtothestandards-compliantboxmodel.Thisflagisn’tsetuntilthedocument
5
isready.Moreinformationregardingthebox-modelissueisavailableathttp:
//www.quirksmode.org/css/box.htmlandathttp:
//www.w3.org/TR/RECCSS2/box.html.
SettotrueifthestandardcssFloatpropertyoftheelement’sstyle
propertyisused.Table6.1The$.supportbrowsercapabilityflags(continued)
FlagpropertyDescriptionhrefNormalizedSettotrueifobtainingthehrefelementattributesreturnsthevalueexactlyasspecified.htmlSerializeSettotrueifthebrowserevaluatesstylesheetreferencesbyelementswheninjectedintotheDOMviainnerHTML.leadingWhitespaceSettotrueifthebrowserhonorsleadingwhitespacewhentextisinsertedviainnerHTML.noC
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 文献 翻译 JQuery 标签 使用