[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/includes/vendor/ozh/bookmarkletgen/src/Ozh/Bookmarkletgen/ -> Bookmarkletgen.php (summary)

(no description)

File Size: 197 lines (6 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Bookmarkletgen:: (7 methods):
  crunch()
  encodeURIComponent()
  kill_comments()
  compress_white_space()
  combine_strings()
  replace_strings()
  restore_strings()


Class: Bookmarkletgen  - X-Ref

BookmarkletGen : converts readable Javascript code into a bookmarklet link

Features :
- removes comments
- compresses code, not literal strings
Example:
function someName( param ) { alert( "this is a string" ) }
will return:
function%20someName(param){alert("this is a string")}
- wraps code into a self invoking function

This is basically a slightly enhanced PHP port of the excellent Bookmarklet Crunchinator
http://ted.mielczarek.org/code/mozilla/bookmarklet.html

crunch( $code )   X-Ref
Main function, calls all others

return: string        Bookmarklet link
param: string $code  Javascript code to bookmarkletify

encodeURIComponent( $str )   X-Ref
PHP port of Javascript function encodeURIComponent

From http://stackoverflow.com/a/1734255/36850

return: string       Encoded string
param: string $str  String to encode
since:

kill_comments( $code )   X-Ref
Kill comment lines and blocks

return: string        Commentless code
param: string $code  Commented Javascript code

compress_white_space( $code )   X-Ref
Compress white space

Remove some extraneous spaces and make the whole script a one liner

return: string        Compressed code
param: string $code  Javascript code

combine_strings( $code )   X-Ref
Combine any consecutive strings

In the case we have two consecutive quoted strings (eg: "hello" + "world"), save a couple more
length and combine them

return: string        Javascript code
param: string $code  Javascript code

replace_strings( $code )   X-Ref
Replace all literal strings (eg: "hello world") with a placeholder and collect them in an array

The idea is that strings cannot be trimmed or white-space optimized: take them out first before uglifying
the code, then we'll reinject them back in later

return: string        Javascript code with placeholders (eg "__1__") instead of literal strings
param: string $code  Javascript code

restore_strings( $code )   X-Ref
Restore literal strings by replacing their placeholders with actual strings

return: string        Javascript code with actual strings
param: string $code  Javascript code with placeholders



Generated: Thu Sep 19 05:10:04 2024 Cross-referenced by PHPXref 0.7.1