CourseSites jQuery plug-in
-
Upload
wayan-wira -
Category
Technology
-
view
400 -
download
0
Transcript of CourseSites jQuery plug-in
![Page 1: CourseSites jQuery plug-in](https://reader036.fdocuments.in/reader036/viewer/2022082513/557e7de2d8b42a48528b4888/html5/thumbnails/1.jpg)
CourseSites jQuery plug-in
![Page 2: CourseSites jQuery plug-in](https://reader036.fdocuments.in/reader036/viewer/2022082513/557e7de2d8b42a48528b4888/html5/thumbnails/2.jpg)
Context
• Replace specific string(s) on a page that is part of href with something else
![Page 3: CourseSites jQuery plug-in](https://reader036.fdocuments.in/reader036/viewer/2022082513/557e7de2d8b42a48528b4888/html5/thumbnails/3.jpg)
CourseSites
• Instructor homepage (ie. https://wayank12teacher2.coursesites.com)– List of courses• Course101 (https://
wayank12teacher2.coursesites.com/s/_course101)• Course102
(https://wayank12teacher2.coursesites.com/s/_course102)
• Goal replace wayank12teacher2 with www
![Page 4: CourseSites jQuery plug-in](https://reader036.fdocuments.in/reader036/viewer/2022082513/557e7de2d8b42a48528b4888/html5/thumbnails/4.jpg)
Firebug…locate the element
![Page 5: CourseSites jQuery plug-in](https://reader036.fdocuments.in/reader036/viewer/2022082513/557e7de2d8b42a48528b4888/html5/thumbnails/5.jpg)
Firebug…locate the element (2)
![Page 6: CourseSites jQuery plug-in](https://reader036.fdocuments.in/reader036/viewer/2022082513/557e7de2d8b42a48528b4888/html5/thumbnails/6.jpg)
Element of interest
• <li class="course-navigation-course"><a class="highlight" href="https://wayank12teacher2.coursesites-stage.com/s/_wayank12changestructure101">wayank12changestructure101»</a></li>
![Page 7: CourseSites jQuery plug-in](https://reader036.fdocuments.in/reader036/viewer/2022082513/557e7de2d8b42a48528b4888/html5/thumbnails/7.jpg)
Find those elements
• jQuery('li.course-navigation-course').find('a[href]')
• Results:• [<a class= "highlight" href= "https: / /
wayank12teacher2.coursesites-stage.com/ s/ _wayank12changestructure101"> wayank12changestructure101» </a>
• , <a class= "highlight" href= "https: / / wayank12teacher2.coursesites-stage.com/ s/ _wayank12nov04test101"> wayank12nov04test101» </a>
• ]
![Page 8: CourseSites jQuery plug-in](https://reader036.fdocuments.in/reader036/viewer/2022082513/557e7de2d8b42a48528b4888/html5/thumbnails/8.jpg)
Search and Replace ( Use Firebug if you have to)
• location.host• Result "wayank12teacher2.coursesites-
stage.com"
• var b='https://' + location.host.replace(location.host.split('.')[0],'www')
![Page 9: CourseSites jQuery plug-in](https://reader036.fdocuments.in/reader036/viewer/2022082513/557e7de2d8b42a48528b4888/html5/thumbnails/9.jpg)
The plug-in
• jQuery.fn.convertUsertoWWW = function() { return this.each( function() { – var c=$(this).attr('href'); – var b='https://' +
location.host.replace(location.host.split('.')[0],'www')+c;
– $(this).attr('href',b); – }
• );
![Page 10: CourseSites jQuery plug-in](https://reader036.fdocuments.in/reader036/viewer/2022082513/557e7de2d8b42a48528b4888/html5/thumbnails/10.jpg)
To execute
• jQuery('li.course-navigation-course').find('a[href]').convertUsertoWWW();
![Page 11: CourseSites jQuery plug-in](https://reader036.fdocuments.in/reader036/viewer/2022082513/557e7de2d8b42a48528b4888/html5/thumbnails/11.jpg)
Final script
• jQuery(document).ready(function() { jQuery.fn.convertUsertoWWW = function() { return this.each( function() { – var c=$(this).attr('href'); – var b='https://' + location.host.replace(location.host.split('.')
[0],'www')+c; – $(this).attr('href',b); } );
• };
• jQuery('li.course-navigation-course').find('a[href]').convertUsertoWWW();