Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>window.jQuery || document.write('<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">\x3C/script>')</script>
- <script type="text/javascript">
- // make sure jquery doesn't break dojo
- jQuery.noConflict();
- jQuery(document).ready(function($) {
- sourceInputName = "#title";
- destInput = $("#urlTitle");
- // function to convert text to a proper url slug
- function cleanUrl(url){
- url = url.toLowerCase();
- url = url.replace(/@.*$/g,""); /* Get rid of @oc.edu */
- url= url.replace(/^\s+|\s+$/g,"");
- url = url.replace(/[^a-zA-Z 0-9]+/g,' ');
- url = url.replace(/\s/g, "-");
- while(url.indexOf("--") > -1){
- url = url.replace("--",'-');
- }
- url = url.replace(/^-/,"");
- url = url.replace(/-$/g,"");
- return url;
- }
- function updateUrlTitle(){
- var myUrl = cleanUrl($(sourceInputName).val());
- destInput.val(myUrl);
- }
- updateUrlTitle(); // Run initially
- // when title is changed, update fields
- $(document.body).on('change',sourceInputName,function(){
- updateUrlTitle();
- console.log("sourceInput has changed");
- });
- // Make it visible by taking it out of the page and putting it back in
- destInput.detach().attr("type","text").appendTo("#urlTitle_field");
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment