PageSourceSearch

https://razdolie.net/assets/23321213/js/helpers/Helpers.js?v=1644181982

js razdolie.net collected 2026-10-06 12:53:22 UTC 6,569 bytes, 236 lines download raw bytes

1/*!
2 *
3 * Helpers containing various functions
4 * Содержит как независимые вспомогательные, полезные функции.
5 *
6 * @date 06.11.2014
7 * @copyright skeeks.com
8 * @author Semenov Alexander <[email protected]>
9 */
10
11
12(function(global, sx, $, _)
13{
14    sx.createNamespace('helpers', sx);
15    /**
16     * @type {{getParams: Function}}
17     */
18    sx.helpers.Request =
19    {
20        getParams: function()
21        {
22            var $_GET = {};
23            var __GET = window.location.search.substring(1).split("&");
24
25            for(var i=0; i<__GET.length; i++)
26            {
27              var getVar = __GET[i].split("=");
28              $_GET[getVar[0]] = typeof(getVar[1]) == "undefined" ? "" : getVar[1];
29            }
30
31            return $_GET;
32        }
33    };
34    /**
35     * Для работы с url
36     * @type {{redirect: Function}}
37     */
38
39    sx.helpers.Url = {
40
41        redirect : function(url)
42        {
43            location.href = url;
44        }
45    };
46
47    /**
48     * Просто вспомогательные функции для работы со строками
49     * @type {{strpos: Function, str_replace: Function}}
50     */
51    sx.helpers.String = {
52
53        /**
54         * Аналог php
55         * @param haystack
56         * @param needle
57         * @param offset | с какого символа начинать поиск
58         * @returns {*}
59         */
60        strpos: function(haystack, needle, offset)
61        {
62            var i = haystack.toString().indexOf( needle, offset ); // returns -1
63            return i >= 0 ? i : false;
64        },
65
66        /**
67         * Аналог php функции
68         *
69         * @param search
70         * @param replace
71         * @param subject
72         * @returns {*}
73         */
74        str_replace: function( search, replace, subject )
75        {
76            if(!(replace instanceof Array)){
77                replace=new Array(replace);
78                if(search instanceof Array){//If search	is an array and replace	is a string, then this replacement string is used for every value of search
79                    while(search.length>replace.length){
80                        replace[replace.length]=replace[0];
81                    }
82                }
83            }
84
85            if(!(search instanceof Array))search=new Array(search);
86            while(search.length>replace.length){//If replace	has fewer values than search , then an empty string is used for the rest of replacement values
87                replace[replace.length]='';
88            }
89
90            if(subject instanceof Array){//If subject is an array, then the search and replace is performed with every entry of subject , and the return value is an array as well.
91                for(k in subject){
92                    subject[k]=str_replace(search,replace,subject[k]);
93                }
94                return subject;
95            }
96
97            for(var k=0; k<search.length; k++){
98                var i = subject.indexOf(search[k]);
99                while(i>-1){
100                    subject = subject.replace(search[k], replace[k]);
101                    i = subject.indexOf(search[k],i);
102                }
103            }
104
105            return subject;
106        },
107
108        /**
109         *
110         * analog php function substr
111         *
112         * @param f_string
113         * @param f_start
114         * @param f_length
115         * @return {String}
116         */
117        substr : function(f_string, f_start, f_length)
118        {
119
120            if(f_start < 0) {
121                f_start += f_string.length;
122            }
123
124            if(f_length == undefined) {
125                f_length = f_string.length;
126            } else if(f_length < 0){
127                f_length += f_string.length;
128            } else {
129                f_length += f_start;
130            }
131
132            if(f_length < f_start) {
133                f_length = f_start;
134            }
135
136            return f_string.substring(f_start, f_length);
137        },
138
139        /**
140         * Генерация случайной строки.
141         *
142         * @param length
143         * @returns {string}
144         */
145        randStr: function(length)
146        {
147            length = length || 6;
148            var result       = '';
149            var words        = '0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
150            var max_position = words.length - 1;
151
152            for( i = 0; i < length; ++i )
153            {
154                position = Math.floor ( Math.random() * max_position );
155                result = result + words.substring(position, position + 1);
156            }
157
158            return result;
159        }
160    };
161
162    /**
163     * Помощь для работы с массивами
164     * @type {{in_array: Function, explode: Function, implode: Function}}
165     */
166    sx.helpers.Array = {
167
168        /**
169         * analog php function in_array
170         *
171         * @param value
172         * @param array
173         * @return {Boolean}
174         */
175        in_array : function(value, array)
176        {
177            for(var i = 0; i < array.length; i++)
178            {
179                if(array[i] == value) return true;
180            }
181            return false;
182        },
183
184        /**
185         * Аналог php
186         *
187         * @param delimiter
188         * @param string
189         * @return {*}
190         */
191        explode: function(delimiter, string)
192        {
193            var emptyArray = { 0: '' };
194
195            if ( arguments.length != 2
196                || typeof arguments[0] == 'undefined'
197                || typeof arguments[1] == 'undefined' )
198            {
199                return null;
200            }
201
202            if ( delimiter === ''
203                || delimiter === false
204                || delimiter === null )
205            {
206                return false;
207            }
208
209            if ( typeof delimiter == 'function'
210                || typeof delimiter == 'object'
211                || typeof string == 'function'
212                || typeof string == 'object' )
213            {
214                return emptyArray;
215            }
216
217            if ( delimiter === true ) {
218                delimiter = '1';
219            }
220
221            return string.toString().split ( delimiter.toString() );
222        },
223
224        /**
225         * Аналог php
226         * @param glue
227         * @param pieces
228         * @returns {*}
229         */
230        implode: function( glue, pieces ) {
231            return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );
232        }
233
234    };
235
236})(window, Skeeks, Skeeks.$, Skeeks._);

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.