Tag Archives: jQuery

XSLT thiab jQuery Samples

Kuv tau raug ua ntau heev nyob ntawm XSLT thiab jQuery, thiab kuv yuav muab ib ob peb snippets uas lwm tus tau nrhiav pab yav thought.

Piv txwv 1: Emit yooj yim JavaScript / jQuery hauv XSLT:

<xsl:Template match = "tej yam" xml:chaw = "khaws cia">

  <!– Dawb paug tawm tau cov lus nug cov ntxaij lim dej tus phooj ywg thaum teb –>
  <Script yam = "ntawv nyeem/javascript">
    $(daim ntawv).npaj txhij(muaj nuj nqi(){
      $("#QueryFriendlyFilters").val("tas");
    });
  </tsab ntawv>

</xsl:Template>

Tus ntsis emits ib co JavaScript waits rau ntawm nplooj los suaj kaum rau nraum chaw thau khoom (vim tias tus $(daim ntawv).npaj txhij(…)) hu ces poob lawm tus nqi thaum teb ua QueryFriendlyFilters mus rau cov nqi literal "tas".

Piv txwv 2: Siv <xsl:Yog hais tias> saib "ntau dua",  "tsis tau muaj", yam.

<xsl:Template match = "tej yam" xml:chaw = "khaws cia">

  <div daim id = "fdcAllFilters">
 
    <xsl:yog test="@Count>0">
      <ntsua kev kawm = "fdcFilterLabel">Lim tam sim no:</ntsua kev>
    </xsl:Yog hais tias>

    <!– ntxiv khoom zoo li no. –>

</xsl:Template>

Saum cov snippet nug saib puas yog ib tug attribute npe hu ua "Suav" ntawm cov "tej yam" caij ntau dua zero.  XML hauv qab no yuav ua ib yam dab tsi zoo li:”

<yam suav = "5" />

Piv txwv 3: Iterate los ntawm tag nrho cov ntsiab, interspersing jQuery hu.

<!– Iterate los ntawm txhua lub lim thiab tso saib qhov tseeb  kev mus. –>
<xsl:rau-ib qho = "UserFilter">

  <hoob kawm = "FilterHref" href = "javascript:mySubmitPage('RemoveUserFilter','{@ID}’)">[X]</ib tug>

  <ntsua kev kawm = "fdcFilterLabel"><xsl:tus nqi-cov select="@FilterValue"/></ntsua kev>

  <Script yam = "ntawv nyeem/javascript">

    $(daim ntawv).npaj txhij(muaj nuj nqi(){
        <xsl:ntawv nyeem><![CDATA[$("#QueryFriendlyFilters").val( ($("#QueryFriendlyFilters").val() + " ]]></xsl:ntawv nyeem>\"<xsl:tus nqi-cov select="@FilterValue"/>\"<xsl:ntawv nyeem><![CDATA["));]]></xsl:ntawv nyeem>
    });

  </tsab ntawv>

</xsl:rau-ib>

Saum cov snippet yog tus tshaj txoj thiab tej zaum yuav muaj txoj kev uas yooj yim ua.

Lub XML qab no zoo roughly li no:

<UserFilter ID = "123" FilterValue = "xyzzy" />

Cov snippet no yog ntsuas los ntawm <UserFilter> o. 

Nws xub emits ib lub thauj tog rau nkoj tag uas thaum clicked invokes ib JavaScript zoo uas twb yog nyob rau sab, "mySubmitPage" thiab kis tau tus nqi ntawm ib lub attribute lub <UserFilter> ntawm hu ua "ID". 

Nws mam li emits ib co jQuery waits rau rau sab mus thauj khoom.  Tus jQuery siab thaum teb hu ua "QueryFriendlyFilters" los ntawm kev ntxiv cov nqi ntawm qhov FilterValue attribute.  Nco ntsoov txhua lub crazy <xsl:ntawv nyeem> thiab <![CDATA[ … ]]> khoom.

Tus ntawd yog nws, vam tias nws yuav pab!

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

Lists.asmx, GetListItems thiab Folders

Kuv tau ua tej kev soj ntsuam rau ib tug neeg niaj hnub ncig lub list.asmx Web site pab muaj li ntawm SharePoint 2010 (thiab ua ntej lawm).  Nws tau txais cov ntawv teev khoom ntawm lub hauv paus sis (xws li lub npe ntawm sub-folders), tab sis, tsis tau txais cov khoom nyob rau hauv sub-folders.  Kuv puas tau ib co saib ib ncig ntawm lub internets, thiab nws yog ib qho kuj ceeb tias lo lus nug.  Tsis tau, Kuv tsis tau muab lus teb rau lo lus nug yooj yim zoo, "yog hais tias kuv paub lub ceev, cas kuv yuav tau txais cov khoom nyob rau hauv daim nplaub tshev?”  Yuav tsis ncaj ncees, Kuv ho tsis sim ib tag li vim kuv yeej xav kom daim duab no ib qho tawm ntawm kuv tus kheej ib pliag Luag nyav.

Teeb no, Kuv tsim ib qhov chaw uas hu ua "Blogging Scenarios" thiab cov kev cai sau npe hu ua "Kev cai sau nrog Sub Folders".  Kuv ces zoo folders muaj npe:

  • Xyoo 2005
  • Xyoo 2006
  • Xyoo 2007

Kuv tov ob peb yam khoom rau hauv daim nplaub tshev "xyoo 2006".  Qhov no yog qhov uas nws zoo li:

image

Tab sis kuv cov phooj ywg tsis yog sau ntawv C# code, theej siv Java, vim li ntawd hauv lub hnab ntawv uas tsis yog tshuaj ntxuav tes muaj li nws yeej tau.  Tau tias, Sau tau me ntsis txog cov jQuery thiab ces muab fiddler los mus sib tham HTTP txhua lub sij.

Nov yog yam hais txog cov jQuery (Tau kuv theej lub chaws los hauv qab no yog koj xav luam los muab tshuaj):

image

Lawv thawj qhov tseem ceeb yog kom muaj ob lub <queryOptions> thiab <QueryOptions> ntawm.  Tus yuam sij thib ob uas yog tus <Ceev> ntawm no ib URL uas tus neeg muaj ntaub.

Tej zaum yuav muaj lwm txoj kev kom tau no, tab sis qhov haujlwm zoo rau kuv thaum uas siv cov jQuery.

Nov yog lub hnab ntawv tshuaj ntxuav tes mus rau saum:

<soapenv:Hnab ntawv xmlns:soapenv =’http://schemas.xmlsoap.org/soap/envelope/’>                
  <soapenv:Lub cev>
    <GetListItems xmlns =’
http://schemas.Microsoft.com/sharepoint/soap/’>
      <listName>Kev cai sau nrog Sub Folders</listName>
      <viewFields>  
        <ViewFields>
          <FieldRef Name ='Title’ />
          <FieldRef Name ='EncodedAbsUrl’ />
        </ViewFields>
      </viewFields>
      <queryOptions>
        <QueryOptions>
          <Ceev>
http://demoserver1/Blogging Scenarios/npe/nchuav sau nrog Sub Folders los lub xyoo 2006</Ceev>
        </QueryOptions>
      </queryOptions>
   
</GetListItems>
  </soapenv:Lub cev>
</soapenv:Hnab ntawv>

Ntau cov lus piv ntxwv thiab kev sib sab laj nyob ib ncig ntawm no coj kuv ntseeg tias txhua yam kuv xav tau <QueryOptions> thiab hais kom meej nplaub tshev npe.  Rau kuv, Kuv xav kom neb ob leeg qhwv nws sab hauv <queryOptions> li zoo li qhia kom meej URL mas tsim nyog rau cov <Ceev> ntawm.

Ntawm no yog cov jQuery AJAX teeb:

$(daim ntawv).npaj txhij(muaj nuj nqi() {
       Var soapEnv =
           "<soapenv:Hnab ntawv xmlns:soapenv =’http://schemas.xmlsoap.org/soap/envelope/’> \
               <soapenv:Lub cev> \
                    <GetListItems xmlns =’http://schemas.Microsoft.com/sharepoint/soap/’> \
                       <listName>Kev cai sau nrog Sub Folders</listName> \
                       <viewFields> \
                           <ViewFields> \
                              <FieldRef Name ='Title’ /> \
                              <FieldRef Name ='EncodedAbsUrl’ /> \
                          </ViewFields> \
                       </viewFields> \
                       <queryOptions> \
                         <QueryOptions> \
                           <Ceev>http://demoserver1/Blogging Scenarios/npe/nchuav sau nrog Sub Folders los lub xyoo 2006</Ceev> \
                         </QueryOptions> \
                       </queryOptions> \
                   </GetListItems> \
               </soapenv:Lub cev> \
           </soapenv:Hnab ntawv>";

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

Endlessly Nesting <div> Ntawv cim npe thiab jQuery

Qhov no xws li tej tus oddball npe nkawd, Kuv tsis paub hais tias nws yog yeej muaj nqis blogging txog, tab sis cov uas ib txwm tsis lawm ua ntej kuv, yog li no peb yuav mus Luag nyav

Kuv tabtom haujlwm rau ib qhov project uas kuv tabtom rub tau tej ntaub ntawv los ntawm ib tug mus nrhiav, packaging nws rau hauv ib cov lus XML thiab ces tus XML yog kawg transformed rau HTML ntawm XSLT.  Muaj coob heev jQuery muab kev koom tes, ib ntsis uas implements tej cov tabbing functionality.  Thaum twg koj nyem rau ntawm ib tug tab (tiag tiag, ib tug <div>), jQuery invokes .hide() thiab .show() nyob rau ntau yam divs (cov nplooj pib load downloads cov ntsiab lus txhua yam thiaj li muaj muaj tsis muaj postbacks qhov no).

Ib Rev teev dhau los, tus tab switching logic pib coj erratically thiab nws tsis qhia ib qho kuv tabs.  Kuv kawg tracked nws mus txog ntawd qhov internet explorer (tsawg) xav hais tias tus <div> cim npe nested deb deb, deb ntxaum dua intended.Tus tsim tawm toolbar yuav qhia:

-<div daim id = "Tab1Content">
  -<div>
    -<div>
      -<div daim id = "Tab2Content">
        -<div>
           …………………………
                   </div>  <— kaw thaum kawg uas qhia nws tag kev cia rau no!

Li ntawd, Yog hais tias kuv ua ib $("#Tab1Content").nkaum(), Kuv kuj xav nraim Tab2 thiab kuv yuav tsis pom Tab2 yog hais tias kuv tsis tau qhia Tab1.  Tau theej thiab Document lub chaws rau studio siv qhov muag saib thiab nws yuav tsom hauv ob sab qhov div phlu tuaj tag nrho nicely, li lawv thiab yuav tau ua, saib zoo li no:

-<div daim id = "Tab1Content">
  +<div>
  +<div>
-<div daim id = "Tab2Content">
  +<div>
  +<div>

Tuav kuv lub taub hau tiv thaiv phab ntsa ib pliag thiab pom tau tias nyob hauv lub txoos HTML code tau generating empty heev <div> cim npe, zoo li:

<lub cev>

  <div daim id = "Tab1Content">

    <div daim id = "row1" />
    <div daim id = "row2" />

  </div>

  <div daim id = "Tab2Content">

    <div daim id = "row1" />
    <div daim id = "row2" />

  </div>

</lub cev>

(Cov saum no yog waaaaaaaaaaaay oversimplified.  Qhov khoob div cim ua npe yog siv tau lig. Qee yam ntawm kuv <div> cim npe tau tag nrho cov ntsiab lus, tab sis coob tshaj ntawd twb tsis tau.  Kuv tuaj hauv realization uas kuv <xsl:rau-ib> kev tswj tau emitting lub luv-daim ntawv div tags thaum twg tus xsl:rau-ib tsis ' nrhiav tej ntaub ntawv no.  Kuv yuam ua qhov HTML saib mus rau hauv lub qhov zis, li:

image

 

Tom qab kuv puas tau tias, tag nrho cov div lub lined nicely thiab kuv tab switching pib ua hauj lwm.

Li ib txwm, Kuv vam tias qhov no yuav pab lwm tus neeg nyob hauv lub pinch.

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

Tsis tau ntxiv jQuery–Resize ib qho piv txwv ua tus duab

Kuv pub ib cov qhov Web site ntawm ib tug neeg laus vendor thiab yuav ua tau ib qho teeb meem loj, me duab.  Cov dluab yuav tsum muaj 60×50 tab sis vim khib, tus thawj vendor yuam lawv ua 42×42, li ntawd, lawv nrhiav squashed:

 

Cov duab zoo

Teeb duab

Ntawm no yog cov markup (dog dig yooj yim zog):

<table hoob = 'ncua-outlook'>
  <thead>
    <tr>
      <th  dav ='100′>3 Tuesday</th>
    </tr>
  </thead>

  <tbody>
    <cov chav kawm tr = 'huab cua'>
      <Td dav ='100′>
        <ul>
          <lis hoob = 'high'>Siab: 72&deg;F</lis>
          <lis hoob = 'low'>Qes: 44&deg;F</lis>
          <lis hoob = 'mob'>Tshav ntuj
            <img src =’
http://deskwx.weatherbug.com/images/Forecast/icons/localized/60×50/en/Trans/cond007.png’ dav ='42’ qhov siab ='42’ xwm =” />
          </lis>
        </ul>
      </Td>
    </tr>

  </tbody>

</cov lus>

Koj mam li nco tias txawm ho lub kev ua kom cov duab xwb qhia qhov kom zoo dimension (60×50) tus thawj vendor yuam nws hauv 42×42.  Ua li cas?  Vwm.

Xijpeem, Kuv xav tau txoj kev sai thiab yooj yim tov rau no qhov teeb meem thiab kuv muab rau jQuery.  Qhov ua kom yuam kev los nrhiav tau txhua yam txog qhov tsim nyog tau <img> cim npe.  Kuv tsis xav muck cov cim kev lwm img npe (cov uas muaj ntau ntau).  JQuery no me ntsis puas tau qhov ua kom yuam kev:

<Script yam = "ntawv nyeem/javascript" src ="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></tsab ntawv>

<Script yam = "ntawv nyeem/javascript">
     $(daim ntawv).npaj txhij(muaj nuj nqi () {

         $(' li.condition > img').txhua(muaj nuj nqi (Performance Index, yam khoom)
           
{
             $(yam khoom).CSS("dav", "60"); 
             $(yam khoom).CSS(qhov "siab", "50");
            });
     }); // nyob rau daim ntawv load
</tsab ntawv>

Chaws ntawd me ntsis pom qhov sau los ua <lis> cim npe cov hoob kawm uas nws yog "mob" thiab <img> cov me nyuam.  Nws mam li iterates los ntawm tag nrho cov neeg ntawd.  Ua haujlwm zoo li ib lub nplhaib.

Kuv yuav zaum khiav nws, tab sis kuv yeej tsis muaj ib hom txiv leej tub unix tias solved π mus 18 xaus-npawb tsab precision sed thiab cov awk thiab kuv tsis ntawd seb yog jQuery guy tog twg los Luag nyav.

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

Yuav tau tswj koj lawv xav tshuaj thiab rho nyees khawm

Kuv thiaj sau cov tshooj no ib while rov qab, tab sis looks li kuv tsis txuas rau nws los ntawm kuv cov blog lub sij hawm, yog li nov mus:

image

Cov tshooj no piav li cas sib zog newform.aspx mus rau ib sab redirect thaum cov neeg siv cov clicks lawv xav tshuaj thiab ib nplooj ntawv txawv thaum nws clicks cancel.

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

Nreeb taub: Ntxiv jQuery kom NTXHUAB Publishing phab

Thaum twg mus pab tau txoj NTXHUAB publising nplooj ntawv siv jQuery, Kuv ntaus lub pob loj hauv qab ceev tsawv:

Neeg rau zaub mov yuam kev hauv ' /’ Daim ntawv.


Parser kev ua yuam kev

Hauj lwm lawm: Ib qho kev ua yuam kev tshwm sim thaum lub caij cov parsing hauv ib qho chaw uas yuav tsum tau muab cov kev pab no thov. Thov nyeem qhov nram qab no parse kev yuam kev txhawb thiab hloov koj cov ntaub ntawv twg paab.

Lus sam yuam kev parser: Tsuas kawm ntawd tus ntawm lwm yam uas tau ntawm ib phab cov uas muaj cov ua ntawm lwm yam uas ncaj qha.

Qhov yuam kev:

 
Line 10: 
Line 11: 
Line 12: <script 
Line 13:     type="text/javascript" 
Line 14:     src="/jQuery/jquery-1.4.min.js"> 

Tau qhov twg los thov: /_catalogs/masterpage/KCC_FacultyMember.aspx    Kab: 12


Cov ntaub ntawv Version: Microsoft .NET moj khaum Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927

Nws twb yooj yim txaus los txhim kho (h/t rau kuv colleague, Uday Ethirajulu).  Nco ntsoov tias cov jQuery chaws nyob sab hauv lub "PlaceHolderAdditionalPageHead" li:

<asp:Chav ContentPlaceholderID = "PlaceHolderAdditionalPageHead" runat = "neeg rau zaub mov">

<tsab ntawv

    yam = "ntawv nyeem/javascript"

    src="/jQuery/jquery-1.4.min.js">

</tsab ntawv>

<Script yam = "ntawv nyeem/javascript">

  $(daim ntawv).npaj txhij(muaj nuj nqi() {

   // Ci ntsa iab jQuery khoom nov mus.

   });

</tsab ntawv>

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin