PageSourceSearch

https://tuyendung.bidv.com.vn/assets/js/jquery.stringtoslug.js

js bidv.com.vn collected 2026-09-24 09:46:45 UTC 2,850 bytes, 91 lines download raw bytes

1/*
2 * jQuery stringToSlug plug-in 2.1.0
3 *
4 * Documentation http://leocaseiro.github.io/jQuery-Plugin-stringToSlug/
5 *
6 * Copyright (c) 2009-2018 Leo Caseiro
7 *
8 * v1 Based on [Edson Hilios](http://www.edsonhilios.com.br/) Algorithm
9 * v2 Uses [SpeakingURL](https://github.com/pid/speakingurl)
10 *
11 *
12 * Released under the MIT license
13 * http://www.opensource.org/licenses/mit-license.php
14 */
15var _stringToSlug_API = function( text, options ) {
16    'use strict';
17
18    var defaults = {
19            setEvents: 'keyup keydown blur', //set Events to bind
20            getPut: '#permalink', //set output field
21            space: '-', //Sets the space(separator) character
22            prefix: '', //Concatenated before the slug
23            suffix: '', //Concatenated after the slug
24            replace: '', //RegExp replacement: /\s?\([^\)]*\)/gi
25            AND: 'and',
26            options: {},
27            callback: false
28        },
29        stringToSlug;
30
31    jQuery.extend( defaults, options );
32
33    /**
34     * from stringToSlug.space to getSlug.separator
35     */
36    if ( ! defaults.options.hasOwnProperty( 'separator' ) ) {
37        defaults.options.separator = defaults.space;
38    }
39
40    /**
41     * from stringToSlug.AND to getSlug.custom
42     */
43    if ( ! defaults.options.hasOwnProperty( 'custom' ) ) {
44        defaults.options.custom = { '&': defaults.AND };
45    }
46
47    text = text.replace( defaults.replace, '' ); //replace
48
49    try {
50        text = getSlug( text, defaults.options );
51    } catch ( err ) {
52        console.warn( 'Make sure you insert speakingurl.min.js before jquery.stringtoslug.min.js' );
53    }
54
55    stringToSlug = defaults.prefix + text + defaults.suffix; //Concatenate with prefix and suffix
56
57    return stringToSlug;
58};
59
60jQuery.fn.stringToSlug = function( options ) {
61    'use strict';
62
63    var defaults = {
64        setEvents: 'keyup keydown blur', //set Events that your script will work
65        getPut: '#permalink', //set output field
66        space: '-', //Sets the space character. If the hyphen,
67        prefix: '',
68        suffix: '',
69        replace: '', //Sample: /\s?\([^\)]*\)/gi
70        AND: 'and',
71        callback: false
72    };
73
74    jQuery.extend( defaults, options );
75
76    jQuery( this ).bind( defaults.setEvents, function() {
77        var text = jQuery( this ).val(),
78            stringToSlug = _stringToSlug_API( text, options );
79
80        jQuery( defaults.getPut ).val( stringToSlug ); //Write in value to input fields (input text, textarea, input hidden, ...)
81        jQuery( defaults.getPut ).html( stringToSlug ); //Write in HTML tags (span, p, strong, h1, ...)
82
83        if ( false !== defaults.callback ) {
84            defaults.callback( stringToSlug );
85        }
86
87        return this;
88    } );
89
90    return this;
91};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.