Strontium-90 /
StrontiumPjaxBundle
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | (function ($, cookie, exports, domInitializer) { |
||
| 2 | 'use strict'; |
||
| 3 | |||
| 4 | var PJAX_PUSH = 'pjax-push'; |
||
| 5 | |||
| 6 | var app = exports.application = { |
||
| 7 | PJAX_REDIRECT_TARGET_PARAMETER: 'pjax-redirect-target', |
||
| 8 | ROOT_CONTAINER_NAME: 'main', |
||
| 9 | |||
| 10 | linkSelector: 'a[data-pjax],' + |
||
| 11 | 'a:not([data-toggle]):not([data-behavior]):not([data-skip-pjax]):not([href^="http://"]):not([href^="/_profiler/"]):not([href^="/app_dev.php/_profiler/"])', |
||
| 12 | |||
| 13 | formSelector: 'form:not([w]):not([data-skip-pjax])', |
||
| 14 | |||
| 15 | params: {}, |
||
| 16 | |||
| 17 | getPage: function (route, params, target) { |
||
| 18 | var req_params = this.params; |
||
| 19 | for (var i in params) { |
||
|
0 ignored issues
–
show
|
|||
| 20 | req_params[i] = params[i]; |
||
| 21 | } |
||
| 22 | |||
| 23 | return this.getUrl(Routing.generate(route, req_params), target); |
||
|
0 ignored issues
–
show
The variable
Routing seems to be never declared. If this is a global, consider adding a /** global: Routing */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 24 | }, |
||
| 25 | |||
| 26 | getPjaxContainer: function (target) { |
||
| 27 | return findTargetContainer(target || app.ROOT_CONTAINER_NAME); |
||
| 28 | }, |
||
| 29 | |||
| 30 | getUrl: function (url, target) { |
||
| 31 | var container = this.getPjaxContainer(target); |
||
| 32 | url = url || ''; |
||
| 33 | |||
| 34 | return $.pjax({ |
||
| 35 | url: url, |
||
| 36 | container: container, |
||
| 37 | method: 'get', |
||
| 38 | push: toPush(target, 'GET'), |
||
| 39 | replace: false |
||
| 40 | }); |
||
| 41 | }, |
||
| 42 | |||
| 43 | reload: function (target, url) { |
||
| 44 | return this.getUrl(url, target); |
||
| 45 | } |
||
| 46 | }; |
||
| 47 | |||
| 48 | $(function () { |
||
| 49 | if ($.support.pjax) { |
||
| 50 | $.pjax.defaults.timeout = 50000; |
||
| 51 | |||
| 52 | $(document) |
||
| 53 | .on('click', app.linkSelector, onPjaxLinkClick) |
||
| 54 | .on('submit', app.formSelector, onPjaxFormSubmit) |
||
| 55 | .on('pjax:complete', onPjaxComplete) |
||
| 56 | .on('pjax:beforeSend', onPjaxBeforeSend) |
||
| 57 | .on('pjax:beforeReplace', onPjaxBeforeReplace); |
||
| 58 | } |
||
| 59 | }); |
||
| 60 | |||
| 61 | function onPjaxLinkClick(event) { |
||
| 62 | if (event.isDefaultPrevented()) { |
||
| 63 | return; |
||
| 64 | } |
||
| 65 | var target = findPjaxTargetFor(this); |
||
| 66 | var container = findTargetContainer(target); |
||
| 67 | var redirectTarget = $(this).data(app.PJAX_REDIRECT_TARGET_PARAMETER); |
||
| 68 | |||
| 69 | $.pjax.click(event, container, { |
||
| 70 | target: target, |
||
| 71 | redirectTarget: redirectTarget, |
||
| 72 | push: toPush(target, 'GET', $(this).data(PJAX_PUSH)), |
||
| 73 | replace: false |
||
| 74 | }); |
||
| 75 | } |
||
| 76 | |||
| 77 | function onPjaxFormSubmit(event) { |
||
| 78 | if (event.isDefaultPrevented()) { |
||
| 79 | return; |
||
| 80 | } |
||
| 81 | var $form = $(this); |
||
| 82 | var target = findPjaxTargetFor(this); |
||
| 83 | var targetContainer = findTargetContainer(target); |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Если пытаемся отправить форму с файлами, |
||
| 87 | * но браузером не поддерживается FormData, |
||
| 88 | * тогда просто штатно отправляем форму. |
||
| 89 | * Пока так. |
||
| 90 | */ |
||
| 91 | if ('multipart/form-data' === $form.attr('enctype') && window.FormData === undefined) { |
||
| 92 | return true; |
||
| 93 | } |
||
| 94 | var params = { |
||
| 95 | target: target, |
||
| 96 | redirectTarget: targetContainer.data(app.PJAX_REDIRECT_TARGET_PARAMETER), |
||
| 97 | push: toPush(target, $form.attr('method'), $(this).data(PJAX_PUSH)), |
||
| 98 | replace: false |
||
| 99 | }; |
||
| 100 | |||
| 101 | if ($form.attr('enctype') === 'multipart/form-data') { |
||
| 102 | $.extend(params, { |
||
| 103 | contentType: false, |
||
| 104 | processData: false, |
||
| 105 | cache: false, |
||
| 106 | data: $form.serializeMultipart() |
||
| 107 | }) |
||
| 108 | } |
||
| 109 | |||
| 110 | $.pjax.submit(event, targetContainer, params); |
||
|
0 ignored issues
–
show
|
|||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Пушить стейт или нет |
||
| 115 | * |
||
| 116 | * @param target |
||
| 117 | * @param method |
||
| 118 | * @param option bool значение атрибута data-pjax-push |
||
| 119 | * @returns bool |
||
| 120 | */ |
||
| 121 | function toPush(target, method, option) { |
||
| 122 | if (option == undefined) { |
||
| 123 | if (method == undefined) { |
||
| 124 | method = 'GET'; |
||
| 125 | } |
||
| 126 | method = method.toUpperCase(); |
||
| 127 | |||
| 128 | return method == 'GET' && target == app.ROOT_CONTAINER_NAME; |
||
| 129 | } |
||
| 130 | |||
| 131 | return option; |
||
| 132 | } |
||
| 133 | |||
| 134 | |||
| 135 | function onPjaxComplete(event, content, status, options) { |
||
|
0 ignored issues
–
show
|
|||
| 136 | domInitializer.initialize(event.target); |
||
| 137 | } |
||
| 138 | |||
| 139 | function onPjaxBeforeReplace(event, contents, options) { |
||
| 140 | var redirectedTo, |
||
| 141 | redirectCookieTargetName, |
||
| 142 | redirectCookieName, |
||
| 143 | optionsTransformer, |
||
| 144 | generateStateParams, |
||
| 145 | redirectTarget = options.redirectTarget; |
||
| 146 | |||
| 147 | if (redirectTarget) { |
||
| 148 | redirectCookieTargetName = parsePjaxContainerSelector(options.context.selector); |
||
| 149 | optionsTransformer = function (options) { |
||
| 150 | return $.extend(options, { |
||
| 151 | context: findTargetContainer(redirectTarget) |
||
| 152 | }); |
||
| 153 | }; |
||
| 154 | generateStateParams = function (options) { |
||
| 155 | return { |
||
| 156 | container: options.context.selector |
||
| 157 | }; |
||
| 158 | }; |
||
| 159 | } else { |
||
| 160 | optionsTransformer = function (options) { |
||
| 161 | return options; |
||
| 162 | }; |
||
| 163 | generateStateParams = function (options) { |
||
|
0 ignored issues
–
show
|
|||
| 164 | return {}; |
||
| 165 | }; |
||
| 166 | redirectTarget = redirectCookieTargetName = findPjaxTargetFor(event.target); |
||
| 167 | } |
||
| 168 | |||
| 169 | redirectCookieName = 'pjax_redirect_' + redirectCookieTargetName; |
||
| 170 | |||
| 171 | if (undefined !== (redirectedTo = cookie.get(redirectCookieName))) { |
||
| 172 | cookie.expire(redirectCookieName); |
||
| 173 | |||
| 174 | options = optionsTransformer(options); |
||
| 175 | |||
| 176 | if (toPush(redirectTarget, 'GET')) { |
||
| 177 | $.extend(event.state, { |
||
| 178 | push: true, |
||
| 179 | url: redirectedTo |
||
| 180 | }, generateStateParams(options)); |
||
| 181 | window.history.pushState(event.state, event.state.title, event.state.url); |
||
| 182 | } |
||
| 183 | |||
| 184 | if (redirectTarget && redirectTarget != app.PJAX_MODAL_CONTAINER) { |
||
| 185 | $(app.PJAX_MODAL_SELECTOR).modal('hide'); |
||
| 186 | } |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | function onPjaxBeforeSend(event, xhr, settings) { |
||
| 191 | xhr.setRequestHeader('X-PJAX-Target', settings.target); |
||
| 192 | settings.redirectTarget && xhr.setRequestHeader('X-PJAX-Redirect-Target', settings.redirectTarget); |
||
| 193 | } |
||
| 194 | |||
| 195 | function findPjaxTargetFor(elem) { |
||
| 196 | var $elem = $(elem); |
||
| 197 | |||
| 198 | return $elem.data('pjax') |
||
| 199 | || $elem.closest('[data-pjax-container]').data('pjax-container') |
||
| 200 | || app.ROOT_CONTAINER_NAME; |
||
| 201 | } |
||
| 202 | |||
| 203 | function findTargetContainer(target) { |
||
| 204 | var container = $(generatePjaxContainerSelector(target)); |
||
| 205 | |||
| 206 | return container.length ? container : null; |
||
| 207 | } |
||
| 208 | |||
| 209 | function generatePjaxContainerSelector(name) { |
||
| 210 | return '[data-pjax-container="' + name + '"]'; |
||
| 211 | } |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @param {string} selector |
||
| 215 | * @returns {string} |
||
| 216 | */ |
||
| 217 | function parsePjaxContainerSelector(selector) { |
||
| 218 | return selector.match(/^\[data-pjax-container="(.+?)"\]$/)[1]; |
||
| 219 | } |
||
| 220 | |||
| 221 | $.fn.serializeMultipart = function () { |
||
| 222 | var obj = $(this); |
||
| 223 | /* ADD FILE TO PARAM AJAX */ |
||
| 224 | var formData = new FormData(); |
||
| 225 | $.each($(obj).find("input[type='file']"), function (i, tag) { |
||
| 226 | $.each($(tag)[0].files, function (i, file) { |
||
| 227 | formData.append(tag.name, file); |
||
| 228 | }); |
||
| 229 | }); |
||
| 230 | var params = $(obj).serializeArray(); |
||
| 231 | $.each(params, function (i, val) { |
||
| 232 | formData.append(val.name, val.value); |
||
| 233 | }); |
||
| 234 | return formData; |
||
| 235 | }; |
||
| 236 | |||
| 237 | })(jQuery, Cookies, window, domInitializer); |
||
|
0 ignored issues
–
show
The variable
Cookies seems to be never declared. If this is a global, consider adding a /** global: Cookies */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
The variable
domInitializer seems to be never declared. If this is a global, consider adding a /** global: domInitializer */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 238 |
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: